Server/Servers.cs
author sl
Thu, 14 Aug 2014 00:23:18 +0200
changeset 21 274a6b27c3f9
parent 20 e3d394dd0388
child 22 cac466b1b6e6
permissions -rw-r--r--
Adding server closing notification to clients.
     1 using System;
     2 using System.Windows.Forms;
     3 using System.Collections;
     4 using System.ServiceModel;
     5 using System.Collections.Generic;
     6 using System.Linq;
     7 
     8 namespace SharpDisplayManager
     9 {
    10     /// <summary>
    11     /// Implement our display service.
    12     /// This class is instantiated anew whenever a client send a request.
    13     /// </summary>
    14     [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    15     class DisplayServer : IDisplayService
    16     {
    17         //From IDisplayService
    18         public void SetTexts(System.Collections.Generic.IList<string> aTexts)
    19         {
    20             //Only support two lines for now
    21             for (int i=0; i<aTexts.Count; i++)
    22             {
    23                 if (i == 0)
    24                 {
    25                     Program.iMainForm.marqueeLabelTop.Text = aTexts[i];
    26                 }
    27                 else if (i == 1)
    28                 {
    29                     Program.iMainForm.marqueeLabelBottom.Text = aTexts[i];
    30                 }
    31             }
    32         }
    33         
    34         //
    35         public void SetText(int aLineIndex, string aText)
    36         {
    37             //Only support two lines for now
    38                 if (aLineIndex == 0)
    39                 {
    40                     Program.iMainForm.marqueeLabelTop.Text = aText;
    41                 }
    42                 else if (aLineIndex == 1)
    43                 {
    44                     Program.iMainForm.marqueeLabelBottom.Text = aText;
    45                 }
    46         }
    47 
    48         //
    49         public void Connect(string aClientName)
    50         {
    51             IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
    52             //remove the old client if any
    53             if (Program.iMainForm.iClients.Keys.Contains(aClientName))
    54             {
    55                 Program.iMainForm.iClients.Remove(aClientName);
    56             }
    57             //Register our client
    58             Program.iMainForm.iClients.Add(aClientName, callback);
    59   
    60             //For some reason MP still hangs on that one
    61             //callback.OnConnected();
    62         }
    63 
    64 
    65     }
    66 
    67 }