Server/Servers.cs
author sl
Fri, 22 Aug 2014 22:48:30 +0200
changeset 43 86aad774b532
parent 34 59bfa4ebcbbb
child 55 b5ed2e29be23
permissions -rw-r--r--
Client now supports text alignment through our new TextField.
     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         public string Name { get; set; }
    24 
    25         DisplayServer()
    26         {
    27             Trace.TraceInformation("Server session opening.");
    28             //First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
    29             SessionId = OperationContext.Current.SessionId;
    30             IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
    31             //
    32             Program.iMainForm.AddClientThreadSafe(SessionId,callback);
    33 
    34         }
    35 
    36         public void Dispose()
    37         {
    38             Trace.TraceInformation("Server session closing.");
    39             Program.iMainForm.RemoveClientThreadSafe(SessionId);
    40         }
    41         
    42         //From IDisplayService
    43         public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
    44         {
    45             Program.iMainForm.SetTextsThreadSafe(SessionId, aTextFields);
    46         }
    47 
    48         //
    49         public void SetText(TextField aTextField)
    50         {
    51             Program.iMainForm.SetTextThreadSafe(SessionId, aTextField);
    52         }
    53 
    54         //
    55         public void SetName(string aClientName)
    56         {
    57             Name = aClientName;
    58             Program.iMainForm.SetClientNameThreadSafe(SessionId, Name);
    59             //Disconnect(aClientName);
    60 
    61             //Register our client and its callback interface
    62             //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
    63             //Program.iMainForm.iClients.Add(aClientName, callback);
    64             //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
    65             //For some reason MP still hangs on that one
    66             //callback.OnConnected();
    67         }
    68 
    69         ///
    70         public int ClientCount()
    71         {
    72             return Program.iMainForm.iClients.Count;
    73         }
    74 
    75         
    76 
    77     }
    78 
    79 }