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