Server/Session.cs
author StephaneLenclud
Sat, 26 Dec 2015 17:43:41 +0100
changeset 175 391bce3c8368
parent 123 0df386e37e29
child 184 7b6aa551eb6c
permissions -rw-r--r--
Improving layout change workflow efficiency.
     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 
    44         Session()
    45         {
    46             Trace.TraceInformation("Server session opening.");
    47             //First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
    48             SessionId = OperationContext.Current.SessionId;
    49             ICallback callback = OperationContext.Current.GetCallbackChannel<ICallback>();
    50             //
    51             SharpDisplayManager.Program.iMainForm.AddClientThreadSafe(SessionId,callback);
    52 
    53         }
    54 
    55         public void Dispose()
    56         {
    57             Trace.TraceInformation("Server session closing.");
    58             SharpDisplayManager.Program.iMainForm.RemoveClientThreadSafe(SessionId);
    59         }
    60 
    61         //
    62         public void SetName(string aClientName)
    63         {
    64             Name = aClientName;
    65             SharpDisplayManager.Program.iMainForm.SetClientNameThreadSafe(SessionId, Name);
    66             //Disconnect(aClientName);
    67 
    68             //Register our client and its callback interface
    69             //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
    70             //Program.iMainForm.iClients.Add(aClientName, callback);
    71             //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
    72             //For some reason MP still hangs on that one
    73             //callback.OnConnected();
    74         }
    75 
    76         public void SetLayout(TableLayout aLayout)
    77         {
    78             SharpDisplayManager.Program.iMainForm.SetClientLayoutThreadSafe(SessionId, aLayout);
    79         }
    80 
    81         //
    82         public void SetField(DataField aField)
    83         {
    84             SharpDisplayManager.Program.iMainForm.SetClientFieldThreadSafe(SessionId, aField);
    85         }
    86 
    87         //From IDisplayService
    88         public void SetFields(System.Collections.Generic.IList<DataField> aFields)
    89         {
    90             SharpDisplayManager.Program.iMainForm.SetClientFieldsThreadSafe(SessionId, aFields);
    91         }
    92 
    93         ///
    94         public int ClientCount()
    95         {
    96             return SharpDisplayManager.Program.iMainForm.iClients.Count;
    97         }
    98 
    99 
   100 
   101     }
   102 
   103 }