Server/Servers.cs
author sl
Fri, 15 Aug 2014 11:11:17 +0200
changeset 31 f19b04646b6a
parent 29 c4e03315035c
child 32 4c416d2878dd
permissions -rw-r--r--
Fixing our client issue with static MainForm overwritten when using multiple clients.
That was basically our issue with broadcast not working the way it should.
     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 }