Server/Servers.cs
author sl
Fri, 15 Aug 2014 10:20:01 +0200
changeset 30 c375286d1a1c
parent 29 c4e03315035c
child 32 4c416d2878dd
permissions -rw-r--r--
Still trying to setup WCF for us to work nicely.
Now using multi threading and reliable session.
Implementing thread safe functions where needed.
Enforcing session mode.
Fixing bug in marquee label as we forgot to reset current position when text is changed.
     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 using System.Diagnostics;
     9 
    10 namespace SharpDisplayManager
    11 {
    12     /// <summary>
    13     /// Implement our display service.
    14     /// This class is instantiated anew whenever a client send a request.
    15     /// </summary>
    16     [ServiceBehavior(   
    17                         ConcurrencyMode = ConcurrencyMode.Multiple,
    18                         InstanceContextMode = InstanceContextMode.PerSession                       
    19                     )]
    20     class DisplayServer : IDisplayService, IDisposable
    21     {
    22         public string SessionId { get; set; }
    23 
    24         DisplayServer()
    25         {
    26             Trace.TraceInformation("Server session opening.");
    27             //First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
    28             SessionId = OperationContext.Current.SessionId;
    29             IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
    30             //
    31             Program.iMainForm.AddClientThreadSafe(SessionId,callback);
    32 
    33         }
    34 
    35         public void Dispose()
    36         {
    37             Trace.TraceInformation("Server session closing.");
    38             Program.iMainForm.RemoveClientThreadSafe(SessionId);
    39         }
    40         
    41         //From IDisplayService
    42         public void SetTexts(System.Collections.Generic.IList<string> aTexts)
    43         {
    44             Program.iMainForm.SetTextsThreadSafe(aTexts);
    45         }
    46 
    47         //
    48         public void SetText(int aLineIndex, string aText)
    49         {
    50             Program.iMainForm.SetTextThreadSafe(aLineIndex, aText);
    51         }
    52 
    53         //
    54         public void Connect(string aClientName)
    55         {
    56             //Disconnect(aClientName);
    57 
    58             //Register our client and its callback interface
    59             //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
    60             //Program.iMainForm.iClients.Add(aClientName, callback);
    61             //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
    62             //For some reason MP still hangs on that one
    63             //callback.OnConnected();
    64         }
    65 
    66         ///
    67         public void Disconnect(string aClientName)
    68         {
    69             //remove the old client if any
    70             /*
    71             if (Program.iMainForm.iClients.Keys.Contains(aClientName))
    72             {
    73                 Program.iMainForm.iClients.Remove(aClientName);
    74                 Program.iMainForm.treeViewClients.Nodes.Remove(Program.iMainForm.treeViewClients.Nodes.Find(aClientName,false)[0]);
    75             }
    76              */
    77 
    78         }
    79 
    80         
    81 
    82     }
    83 
    84 }