Server/Session.cs
author StephaneLenclud
Tue, 16 Aug 2016 12:59:32 +0200
changeset 235 ba14a29944c4
parent 184 7b6aa551eb6c
child 261 e2729a990e8b
permissions -rw-r--r--
Removing JSON type converter from ear manager.
Using bindings for some application settings.
     1 //
     2 // Copyright (C) 2014-2015 Stéphane Lenclud.
     3 //
     4 // This file is part of SharpDisplayManager.
     5 //
     6 // SharpDisplayManager is free software: you can redistribute it and/or modify
     7 // it under the terms of the GNU General Public License as published by
     8 // the Free Software Foundation, either version 3 of the License, or
     9 // (at your option) any later version.
    10 //
    11 // SharpDisplayManager is distributed in the hope that it will be useful,
    12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 // GNU General Public License for more details.
    15 //
    16 // You should have received a copy of the GNU General Public License
    17 // along with SharpDisplayManager.  If not, see <http://www.gnu.org/licenses/>.
    18 //
    19 
    20 using System;
    21 using System.Windows.Forms;
    22 using System.Collections;
    23 using System.ServiceModel;
    24 using System.Collections.Generic;
    25 using System.Linq;
    26 using System.Diagnostics;
    27 using SharpLib.Display;
    28 
    29 namespace SharpDisplay
    30 {
    31     /// <summary>
    32     /// Implement our display services.
    33     /// Each client connection has such a session object server side.
    34     /// </summary>
    35     [ServiceBehavior(
    36                         ConcurrencyMode = ConcurrencyMode.Multiple,
    37                         InstanceContextMode = InstanceContextMode.PerSession
    38                     )]
    39     class Session : IService, IDisposable
    40     {
    41         public string SessionId { get; set; }
    42         public string Name { get; set; }
    43         public uint Priority { get; set; }
    44 
    45         Session()
    46         {
    47             Trace.TraceInformation("Server session opening.");
    48             //First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
    49             SessionId = OperationContext.Current.SessionId;
    50             ICallback callback = OperationContext.Current.GetCallbackChannel<ICallback>();
    51             //
    52             SharpDisplayManager.Program.iFormMain.AddClientThreadSafe(SessionId,callback);
    53 
    54         }
    55 
    56         public void Dispose()
    57         {
    58             Trace.TraceInformation("Server session closing.");
    59             SharpDisplayManager.Program.iFormMain.RemoveClientThreadSafe(SessionId);
    60         }
    61 
    62         //
    63         public void SetName(string aClientName)
    64         {
    65             Name = aClientName;
    66             SharpDisplayManager.Program.iFormMain.SetClientNameThreadSafe(SessionId, Name);
    67             //Disconnect(aClientName);
    68 
    69             //Register our client and its callback interface
    70             //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
    71             //Program.iFormMain.iClients.Add(aClientName, callback);
    72             //Program.iFormMain.treeViewClients.Nodes.Add(aClientName, aClientName);
    73             //For some reason MP still hangs on that one
    74             //callback.OnConnected();
    75         }
    76 
    77         /// <summary>
    78         /// 
    79         /// </summary>
    80         /// <param name="aPriority"></param>
    81         public void SetPriority(uint aPriority)
    82         {
    83             Priority = aPriority;
    84             SharpDisplayManager.Program.iFormMain.SetClientPriorityThreadSafe(SessionId, Priority);
    85         }
    86 
    87         public void SetLayout(TableLayout aLayout)
    88         {
    89             SharpDisplayManager.Program.iFormMain.SetClientLayoutThreadSafe(SessionId, aLayout);
    90         }
    91 
    92         //
    93         public void SetField(DataField aField)
    94         {
    95             SharpDisplayManager.Program.iFormMain.SetClientFieldThreadSafe(SessionId, aField);
    96         }
    97 
    98         //From IDisplayService
    99         public void SetFields(System.Collections.Generic.IList<DataField> aFields)
   100         {
   101             SharpDisplayManager.Program.iFormMain.SetClientFieldsThreadSafe(SessionId, aFields);
   102         }
   103 
   104         ///
   105         public int ClientCount()
   106         {
   107             return SharpDisplayManager.Program.iFormMain.iClients.Count;
   108         }
   109 
   110 
   111 
   112     }
   113 
   114 }