PageRenderTime 65ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Visual Studio 2008/CSSL3LocalMessage/ReadMe.txt

#
Plain Text | 86 lines | 66 code | 20 blank | 0 comment | 0 complexity | 0137caeb783e2d6a225ee1fd35036689 MD5 | raw file
  1. ========================================================================
  2. SILVERLIGHT APPLICATION : CSSL3LocalMessage Project Overview
  3. ========================================================================
  4. /////////////////////////////////////////////////////////////////////////////
  5. Use:
  6. This project create a whiteboard application demonstrating how to use local message
  7. in silverlight 3. To test this local messaging sample, open TestPage.html in two
  8. browsers, draw on one of the application, another one would keep synchronous.
  9. /////////////////////////////////////////////////////////////////////////////
  10. Prerequisites:
  11. Silverlight 3 Tools for Visual Studio 2008 SP1
  12. http://www.microsoft.com/downloads/details.aspx?familyid=9442b0f2-7465-417a-88f3-5e7b5409e9dd&displaylang=en
  13. Silverilght 3 runtime:
  14. http://silverlight.net/getstarted/
  15. /////////////////////////////////////////////////////////////////////////////
  16. Code Logic:
  17. 1. How does this sample working?
  18. 1. When starting application, use localmessagereceiver and localmessagesender
  19. to create a duplex communication channel.
  20. 2. When drawing a stroke, serialize stroke object to a string, use localmessagesender
  21. send string to another applciation.
  22. 3. When localmessagereceiver received stroke string, deserialize to stroke object,
  23. add to InkPresenter.
  24. 2. How to establish duplex communication channel between two application?
  25. 1. Preassign two names as LocalMessageReceiver name.
  26. 2. Use one of its name to create LocalMessageReeciver, register messagereceived event,
  27. start listening by calling LocalMessageRecevier.Listen(). if got exception, it means
  28. another application with same name in domain has started listening already, try use
  29. another preset name to create receiver.
  30. 3. When initializing LocalMessageReceiver successful, create LocalMessageSender targeting
  31. to another application's recever. Register messagesended event, handling the message send
  32. state and response message there.
  33. 3. How to serialize/deserialize object for transfering by local message?
  34. Local message only accept text format message, to transfer object, we could use Xml or JSON
  35. Serializer. This sample use DataContractJsonSerializer to serialize/deserialize object.
  36. To serialize Stroke object to json string:
  37. // Serialize stroke object to string.
  38. var stream = new MemoryStream();
  39. _jsonserializer.WriteObject(stream, _newStroke);
  40. stream.Flush();
  41. stream.Position = 0;
  42. var obstring = new StreamReader(stream).ReadToEnd();
  43. stream.Close();
  44. To deserialize string to Stroke object:
  45. // Deserialize json string to stroke object.
  46. var stream = new MemoryStream();
  47. var streamwriter = new StreamWriter(stream);
  48. streamwriter.Write(e.Message);
  49. streamwriter.Flush();
  50. var receivedstroke = _jsonserializer.ReadObject(stream) as Stroke;
  51. stream.Close();
  52. For details about DataContractJsonSerializer, please check msdn article
  53. http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer(VS.95).aspx
  54. 4. How to use implement drawing function?
  55. The drawing function is implemented by using InkPresenter.
  56. 1. When mouseleftbuttondown, create new Stroke as currentstroke, add to InkPresenter.
  57. 2. While mousemoving, if currentstroke is not null, add current position as new StylusPoints
  58. to currentstroke.
  59. 3. When mouseleftbuttondown, set currentstroke to null.
  60. For creating more complex drawing function with inkprsenter, you could check
  61. http://msdn.microsoft.com/en-us/magazine/cc721604.aspx
  62. /////////////////////////////////////////////////////////////////////////////
  63. References:
  64. Communication Between Local Silverlight-Based Applications
  65. http://msdn.microsoft.com/en-us/library/dd833063(VS.95).aspx
  66. /////////////////////////////////////////////////////////////////////////////