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