Click here to Skip to main content
15,895,799 members
Articles / Programming Languages / C#

Silver Draw - A Silverlight Based Collaboration White Board with Drawing and Chat

Rate me:
Please Sign up or sign in to vote.
4.98/5 (37 votes)
2 Nov 2009CPOL9 min read 140.3K   3.1K   137  
Silver Draw shows how to use Silverlight and WCF Polling Duplex services to create realtime collaboration apps.
  • silverdraw.zip
    • Client
      • .svn
        • all-wcprops
        • entries
        • format
        • prop-base
        • props
        • text-base
          • App.xaml.cs.svn-base
          • App.xaml.svn-base
          • Page.xaml.cs.svn-base
          • Page.xaml.svn-base
          • ScreenObject.cs.svn-base
          • ServiceReferences.ClientConfig.svn-base
          • Silverdraw.Client.csproj.svn-base
          • Silverdraw.Client.csproj.user.svn-base
        • tmp
          • prop-base
          • props
          • text-base
      • App.xaml
      • App.xaml.cs
      • Bin
        • .svn
          • all-wcprops
          • entries
          • format
          • prop-base
          • props
          • text-base
          • tmp
            • prop-base
            • props
            • text-base
        • Debug
          • .svn
            • all-wcprops
            • entries
            • format
            • prop-base
              • SilverPaintGadget.dll.svn-base
              • SilverPaintGadget.pdb.svn-base
              • SilverPaintGadget.xap.svn-base
              • System.Json.dll.svn-base
              • System.Runtime.Serialization.Json.dll.svn-base
              • System.ServiceModel.PollingDuplex.dll.svn-base
            • props
            • text-base
              • AppManifest.xaml.svn-base
              • SilverPaintGadget.dll.svn-base
              • SilverPaintGadget.pdb.svn-base
              • SilverPaintGadget.xap.svn-base
              • System.Json.dll.svn-base
              • System.Json.xml.svn-base
              • System.Runtime.Serialization.Json.dll.svn-base
              • System.Runtime.Serialization.Json.xml.svn-base
              • System.ServiceModel.PollingDuplex.dll.svn-base
              • System.ServiceModel.PollingDuplex.xml.svn-base
              • TestPage.html.svn-base
            • tmp
              • prop-base
              • props
              • text-base
          • AppManifest.xaml
          • de
            • .svn
              • all-wcprops
              • entries
              • format
              • prop-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • props
              • text-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • tmp
                • prop-base
                • props
                • text-base
            • System.Json.resources.dll
            • System.Runtime.Serialization.Json.resources.dll
            • System.ServiceModel.PollingDuplex.resources.dll
            • System.Windows.Controls.resources.dll
          • es
            • .svn
              • all-wcprops
              • entries
              • format
              • prop-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • props
              • text-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • tmp
                • prop-base
                • props
                • text-base
            • System.Json.resources.dll
            • System.Runtime.Serialization.Json.resources.dll
            • System.ServiceModel.PollingDuplex.resources.dll
            • System.Windows.Controls.resources.dll
          • fr
            • .svn
              • all-wcprops
              • entries
              • format
              • prop-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • props
              • text-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • tmp
                • prop-base
                • props
                • text-base
            • System.Json.resources.dll
            • System.Runtime.Serialization.Json.resources.dll
            • System.ServiceModel.PollingDuplex.resources.dll
            • System.Windows.Controls.resources.dll
          • it
            • .svn
              • all-wcprops
              • entries
              • format
              • prop-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • props
              • text-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • tmp
                • prop-base
                • props
                • text-base
            • System.Json.resources.dll
            • System.Runtime.Serialization.Json.resources.dll
            • System.ServiceModel.PollingDuplex.resources.dll
            • System.Windows.Controls.resources.dll
          • ja
            • .svn
              • all-wcprops
              • entries
              • format
              • prop-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • props
              • text-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • tmp
                • prop-base
                • props
                • text-base
            • System.Json.resources.dll
            • System.Runtime.Serialization.Json.resources.dll
            • System.ServiceModel.PollingDuplex.resources.dll
            • System.Windows.Controls.resources.dll
          • ko
            • .svn
              • all-wcprops
              • entries
              • format
              • prop-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • props
              • text-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • tmp
                • prop-base
                • props
                • text-base
            • System.Json.resources.dll
            • System.Runtime.Serialization.Json.resources.dll
            • System.ServiceModel.PollingDuplex.resources.dll
            • System.Windows.Controls.resources.dll
          • Silverdraw.Client.dll
          • SilverPaintGadget.dll
          • SilverPaintGadget.xap
          • System.Json.dll
          • System.Json.xml
          • System.Runtime.Serialization.Json.dll
          • System.Runtime.Serialization.Json.xml
          • System.ServiceModel.PollingDuplex.dll
          • System.ServiceModel.PollingDuplex.xml
          • System.Windows.Controls.dll
          • System.Windows.Controls.xml
          • TestPage.html
          • zh-Hans
            • .svn
              • all-wcprops
              • entries
              • format
              • prop-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • props
              • text-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • tmp
                • prop-base
                • props
                • text-base
            • System.Json.resources.dll
            • System.Runtime.Serialization.Json.resources.dll
            • System.ServiceModel.PollingDuplex.resources.dll
            • System.Windows.Controls.resources.dll
          • zh-Hant
            • .svn
              • all-wcprops
              • entries
              • format
              • prop-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • props
              • text-base
                • System.Json.resources.dll.svn-base
                • System.Runtime.Serialization.Json.resources.dll.svn-base
                • System.ServiceModel.PollingDuplex.resources.dll.svn-base
              • tmp
                • prop-base
                • props
                • text-base
            • System.Json.resources.dll
            • System.Runtime.Serialization.Json.resources.dll
            • System.ServiceModel.PollingDuplex.resources.dll
            • System.Windows.Controls.resources.dll
      • ColorPicker
        • .svn
          • all-wcprops
          • entries
          • format
          • prop-base
          • props
          • text-base
            • ColorPicker.xaml.cs.svn-base
            • ColorPicker.xaml.svn-base
          • tmp
            • prop-base
            • props
            • text-base
        • ColorPicker.xaml
        • ColorPicker.xaml.cs
      • Helpers
      • Page.xaml
      • Page.xaml.cs
      • Properties
        • .svn
          • all-wcprops
          • entries
          • format
          • prop-base
          • props
          • text-base
            • AppManifest.xml.svn-base
            • AssemblyInfo.cs.svn-base
          • tmp
            • prop-base
            • props
            • text-base
        • AppManifest.xml
        • AssemblyInfo.cs
      • Resources
        • .svn
          • all-wcprops
          • entries
          • format
          • prop-base
            • brush.jpg.svn-base
            • circle.PNG.svn-base
            • pen.jpg.svn-base
            • pencil.jpg.svn-base
            • rect.PNG.svn-base
            • sticky.jpg.svn-base
          • props
          • text-base
            • brush.jpg.svn-base
            • circle.PNG.svn-base
            • pen.jpg.svn-base
            • pencil.jpg.svn-base
            • rect.PNG.svn-base
            • sticky.jpg.svn-base
          • tmp
            • prop-base
            • props
            • text-base
        • brush.jpg
        • circle.PNG
        • pen.jpg
        • pencil.jpg
        • rect.PNG
        • sticky.jpg
      • ScreenObject.cs
      • Service References
        • .svn
          • all-wcprops
          • entries
          • format
          • prop-base
          • props
          • text-base
          • tmp
            • prop-base
            • props
            • text-base
        • Proxy
          • .svn
            • all-wcprops
            • entries
            • format
            • prop-base
            • props
            • text-base
              • configuration.svcinfo.svn-base
              • configuration91.svcinfo.svn-base
              • DuplexDrawService.disco.svn-base
              • DuplexDrawService.wsdl.svn-base
              • DuplexDrawService.xsd.svn-base
              • DuplexDrawService1.xsd.svn-base
              • DuplexDrawService2.xsd.svn-base
              • Reference.cs.svn-base
              • Reference.svcmap.svn-base
            • tmp
              • prop-base
              • props
              • text-base
          • configuration.svcinfo
          • configuration91.svcinfo
          • DuplexDrawService.disco
          • DuplexDrawService.wsdl
          • DuplexDrawService.xsd
          • DuplexDrawService1.xsd
          • DuplexDrawService2.xsd
          • Reference.cs
          • Reference.svcmap
      • ServiceReferences.ClientConfig
      • Silverdraw.Client.csproj
      • Silverdraw.Client.csproj.user
    • Server
      • .svn
        • all-wcprops
        • dir-prop-base
        • entries
        • format
        • prop-base
        • props
        • text-base
          • ClientAccessPolicy.xml.svn-base
          • DrawData.cs.svn-base
          • DuplexDrawService.svc.cs.svn-base
          • DuplexDrawService.svc.svn-base
          • IDuplexDrawCallback.cs.svn-base
          • IDuplexDrawService.cs.svn-base
          • Silverdraw.html.svn-base
          • Silverdraw.Publish.xml.svn-base
          • Silverdraw.Server.csproj.svn-base
          • Silverdraw.Server.csproj.user.svn-base
          • Silverlight.js.svn-base
          • Web.config.svn-base
          • Web.Debug.config.svn-base
          • Web.Release.config.svn-base
        • tmp
          • prop-base
          • props
          • text-base
      • App_Data
        • .svn
          • all-wcprops
          • entries
          • format
          • prop-base
          • props
          • text-base
          • tmp
            • prop-base
            • props
            • text-base
      • bin
        • Silverdraw.Server.dll
        • System.Data.DataSetExtensions.dll
        • System.ServiceModel.PollingDuplex.dll
        • System.Web.Extensions.dll
      • ClientAccessPolicy.xml
      • ClientBin
        • SilverPaintGadget.xap
      • default.htm
      • DrawData.cs
      • DuplexDrawService.svc
      • DuplexDrawService.svc.cs
      • IDuplexDrawCallback.cs
      • IDuplexDrawService.cs
      • Properties
        • .svn
          • all-wcprops
          • entries
          • format
          • prop-base
          • props
          • text-base
            • AssemblyInfo.cs.svn-base
          • tmp
            • prop-base
            • props
            • text-base
        • AssemblyInfo.cs
      • Service References
        • .svn
          • all-wcprops
          • entries
          • format
          • prop-base
          • props
          • text-base
          • tmp
            • prop-base
            • props
            • text-base
      • Silverdraw.Publish.xml
      • Silverdraw.Server.csproj
      • Silverdraw.Server.csproj.user
      • Silverdraw.Server.Publish.xml
      • Silverlight.js
      • Web.config
      • Web.Debug.config
      • Web.Release.config
    • Silverdraw.sln
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.Globalization;
using System.ComponentModel;
using Silverdraw.Server;

namespace Silverdraw.Client
{

    public enum CallBackEvents
    {
        NotifyReceived,
        RegisterCompleted,
        DrawCompleted
    }

    /// <summary>
    /// A helper class to initialize the proxy and receive call backs
    /// </summary>
    public class DuplexClientHelper<TDataType>
    {
        #region Variables
        object syncRoot = new object();
        Proxy.DuplexDrawServiceClient client = null;
        #endregion


        #region Events
        public event Action<string,Exception> GotError;
        public event Action<CallBackEvents, TDataType> GotNotification;
        #endregion


        #region Methods
        public void Initialize(string endPointAddress)
        {
            this.client = new Proxy.DuplexDrawServiceClient(
            new PollingDuplexHttpBinding(),
            new EndpointAddress(endPointAddress));

            this.client.NotifyReceived += new EventHandler<Proxy.NotifyReceivedEventArgs>(client_NotifyReceived);
            this.client.RegisterCompleted += new EventHandler<AsyncCompletedEventArgs>(client_RegisterCompleted);
        }


        /// <summary>
        /// Current client instance
        /// </summary>
        public Proxy.DuplexDrawServiceClient Client
        {
            get
            {
                return client;
            }
        }



        /// <summary>
        /// Callback to get the notification
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void client_NotifyReceived(object sender, Proxy.NotifyReceivedEventArgs e)
        {
            if (!this.IsError(e))
            {
                try
                {
                    if (GotNotification != null)
                    {
                        var data = e.request.GetBody<TDataType>();
                        GotNotification(CallBackEvents.NotifyReceived, data);
                    }
                }
                catch (Exception ex)
                {
                    if (GotError != null)
                        GotError(ex.Message,ex);

                }
            }
        }

        /// <summary>
        /// Callback to get the register completed event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void client_RegisterCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (!this.IsError(e))
            {
                if (GotNotification != null)
                    GotNotification(CallBackEvents.RegisterCompleted, default(TDataType));
            }
        }

        /// <summary>
        /// Check if we have an error
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        bool IsError(AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                lock (this.syncRoot)
                {
                    this.client.CloseAsync();
                    this.client = null;
                }
                if (GotError!=null)
                    GotError(e.Error.Message,e.Error);
            }


            return e.Error != null;
        }

        #endregion

    }
}

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 Code Project Open License (CPOL)


Written By
Architect
India India
Architect, Developer, Speaker | Wannabe GUT inventor & Data Scientist | Microsoft MVP in C#

Comments and Discussions