Server/Session.cs
author sl
Sat, 27 Dec 2014 21:52:14 +0100
changeset 83 150c4a9d7e26
parent 75 2549a8055bd1
parent 74 60d584bad780
child 123 0df386e37e29
permissions -rw-r--r--
Merge
     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 System.Diagnostics;
     8 using SharpDisplay;
     9 
    10 namespace SharpDisplay
    11 {
    12     /// <summary>
    13     /// Implement our display services.
    14     /// Each client connection has such a session object server side.
    15     /// </summary>
    16     [ServiceBehavior(
    17                         ConcurrencyMode = ConcurrencyMode.Multiple,
    18                         InstanceContextMode = InstanceContextMode.PerSession
    19                     )]
    20     class Session : IService, IDisposable
    21     {
    22         public string SessionId { get; set; }
    23         public string Name { get; set; }
    24 
    25         Session()
    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             ICallback callback = OperationContext.Current.GetCallbackChannel<ICallback>();
    31             //
    32             SharpDisplayManager.Program.iMainForm.AddClientThreadSafe(SessionId,callback);
    33 
    34         }
    35 
    36         public void Dispose()
    37         {
    38             Trace.TraceInformation("Server session closing.");
    39             SharpDisplayManager.Program.iMainForm.RemoveClientThreadSafe(SessionId);
    40         }
    41 
    42         //
    43         public void SetName(string aClientName)
    44         {
    45             Name = aClientName;
    46             SharpDisplayManager.Program.iMainForm.SetClientNameThreadSafe(SessionId, Name);
    47             //Disconnect(aClientName);
    48 
    49             //Register our client and its callback interface
    50             //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
    51             //Program.iMainForm.iClients.Add(aClientName, callback);
    52             //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
    53             //For some reason MP still hangs on that one
    54             //callback.OnConnected();
    55         }
    56 
    57         public void SetLayout(TableLayout aLayout)
    58         {
    59             SharpDisplayManager.Program.iMainForm.SetClientLayoutThreadSafe(SessionId, aLayout);
    60         }
    61 
    62         //
    63         public void SetField(DataField aField)
    64         {
    65             SharpDisplayManager.Program.iMainForm.SetClientFieldThreadSafe(SessionId, aField);
    66         }
    67 
    68         //From IDisplayService
    69         public void SetFields(System.Collections.Generic.IList<DataField> aFields)
    70         {
    71             SharpDisplayManager.Program.iMainForm.SetClientFieldsThreadSafe(SessionId, aFields);
    72         }
    73 
    74         ///
    75         public int ClientCount()
    76         {
    77             return SharpDisplayManager.Program.iMainForm.iClients.Count;
    78         }
    79 
    80 
    81 
    82     }
    83 
    84 }