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