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