Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

An Introduction to the Silverlight samples in the All-In-One Framework

, 12 Dec 2009
This article introduces several Silverlight samples in the All-In-One Framework.
SilverlightIntroduction_src.zip
CSSL3LocalMessage
Properties
CSSL3MediaElement
CSSL3MediaElement
Properties
CSSL3MediaElement.Web
App_Data
ClientBin
CSSL3MediaElement.xap
Properties
ReadMe.mht
CSSL3PixelShader
cyclewatery.ps
Humpback Whale.jpg
Properties
CSSL3WriteableBitmap
Heart Empty.png
Properties
VBSL3Animation
My Project
VBSL3DeepZoom
VBSL3DeepZoom
images
home_hover.png
home_pressed.png
home_rest.png
My Project
Service References
DeepZoomServiceReference
configuration.svcinfo
configuration91.svcinfo
GenerateDeepZoomService.disco
GenerateDeepZoomService.wsdl
Reference.svcmap
ServiceReferences.ClientConfig
VBSL3DeepZoom.Web
App_Code
App_Data
Bin
DeepZoomTools.DLL
DeepZoomTools.DLL.refresh
ClientBin
GeneratedImages
GenerateDeepZoomService.svc
SourceImages
atom.png
background.jpg
cell.png
dna.png
Molecular.png
neutron.png
seed.png
wrap in bamboo.png
VBSL3HTMLBridge
VBSL3HTMLBridge
My Project
VBSL3HTMLBridge.Web
App_Data
ClientBin
VBSL3HTMLBridge.xap
My Project
Application.myapp
MyExtensions
Settings.settings
VBSL3Input
My Project
VBSL3LocalMessage
My Project
VBSL3MediaElement
ReadMe.mht
VBSL3MediaElement
My Project
VBSL3MediaElement.Web
App_Data
ClientBin
VBSL3MediaElement.xap
My Project
Application.myapp
MyExtensions
Settings.settings
VBSL3PixelShader
cyclewatery.ps
Humpback Whale.jpg
My Project
CSSL3Animation
Properties
CSSL3DeepZoom
CSSL3DeepZoom
images
home_hover.png
home_pressed.png
home_rest.png
Properties
Service References
DeepZoomServiceReference
configuration.svcinfo
configuration91.svcinfo
GenerateDeepZoomService.disco
GenerateDeepZoomService.wsdl
GenerateDeepZoomService1.wsdl
Reference.svcmap
ServiceReferences.ClientConfig
CSSL3DeepZoom.Web
App_Code
Bin
DeepZoomTools.DLL
DeepZoomTools.DLL.refresh
ClientBin
GeneratedImages
GenerateDeepZoomService.svc
SourceImages
atom.png
background.jpg
cell.png
dna.png
Molecular.png
neutron.png
seed.png
wrap in bamboo.png
ReadMe.mht
CSSL3HTMLBridge
CSSL3HTMLBridge
Properties
CSSL3HTMLBridge.Web
App_Data
ClientBin
CSSL3HTMLBridge.xap
Properties
CSSL3Input
Properties
========================================================================
    SILVERLIGHT APPLICATION : CSSL3LocalMessage Project Overview
========================================================================

/////////////////////////////////////////////////////////////////////////////
Use:

This project create a whiteboard application demonstrating how to use local message
in silverlight 3. To test this local messaging sample, open TestPage.html in two
browsers, draw on one of the application, another one would keep synchronous.

/////////////////////////////////////////////////////////////////////////////
Prerequisites:

Silverlight 3 Tools for Visual Studio 2008 SP1
http://www.microsoft.com/downloads/details.aspx?familyid=9442b0f2-7465-417a-88f3-5e7b5409e9dd&displaylang=en

Silverilght 3 runtime:
http://silverlight.net/getstarted/


/////////////////////////////////////////////////////////////////////////////
Code Logic:

1. How does this sample working?
    1. When starting application, use localmessagereceiver and localmessagesender
       to create a duplex communication channel.
    2. When drawing a stroke, serialize stroke object to a string, use localmessagesender
       send string to another applciation.
    3. When localmessagereceiver received stroke string, deserialize to stroke object,
       add to InkPresenter.

2. How to establish duplex communication channel between two application?
    1. Preassign two names as LocalMessageReceiver name.
    2. Use one of its name to create LocalMessageReeciver, register messagereceived event,
       start listening by calling LocalMessageRecevier.Listen(). if got exception, it means 
       another application with same name in domain has started listening already, try use 
       another preset name to create receiver.
    3. When initializing LocalMessageReceiver successful, create LocalMessageSender targeting
       to another application's recever. Register messagesended event, handling the message send
       state and response message there. 

3. How to serialize/deserialize object for transfering by local message?
    Local message only accept text format message, to transfer object, we could use Xml or JSON
    Serializer. This sample use DataContractJsonSerializer to serialize/deserialize object.
    To serialize Stroke object to json string:
    
        // Serialize stroke object to string.
        var stream = new MemoryStream();
        _jsonserializer.WriteObject(stream, _newStroke);
        stream.Flush();
        stream.Position = 0;
        var obstring = new StreamReader(stream).ReadToEnd();
        stream.Close();
        
    To deserialize string to Stroke object:
    
        // Deserialize json string to stroke object.
        var stream = new MemoryStream();
        var streamwriter = new StreamWriter(stream);
        streamwriter.Write(e.Message);
        streamwriter.Flush();
        var receivedstroke = _jsonserializer.ReadObject(stream) as Stroke;
        stream.Close();
    
    For details about DataContractJsonSerializer, please check msdn article
    http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer(VS.95).aspx
    
4. How to use implement drawing function?
    The drawing function is implemented by using InkPresenter.
    1. When mouseleftbuttondown, create new Stroke as currentstroke, add to InkPresenter.
    2. While mousemoving, if currentstroke is not null, add current position as new StylusPoints
       to currentstroke.
    3. When mouseleftbuttondown, set currentstroke to null.
    
    For creating more complex drawing function with inkprsenter, you could check  
    http://msdn.microsoft.com/en-us/magazine/cc721604.aspx

/////////////////////////////////////////////////////////////////////////////
References:

Communication Between Local Silverlight-Based Applications
http://msdn.microsoft.com/en-us/library/dd833063(VS.95).aspx


/////////////////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Microsoft All-In-One Code Framework delineates the framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on our support experience in MSDN newsgroups and forums. If you are a software developer, you can fill the skeleton with blood, muscle and soul. If you are a software tester or a support engineer like us, you may extend the sample codes a little to fit your specific test scenario or refer your customer to this project if the customer's question coincides with what we collected.
http://cfx.codeplex.com/

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 12 Dec 2009
Article Copyright 2009 by All-In-One Code Framework
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid