Server/Session.cs
author sl
Sat, 25 Oct 2014 13:35:11 +0200
changeset 72 fd0bb39a7818
parent 67 6e50baf5a811
child 74 60d584bad780
child 75 2549a8055bd1
permissions -rw-r--r--
Now having a single class for both text and bitmap field.
Thus we should soon be able to use common functions to pass in fields.
sl@17
     1
using System;
sl@17
     2
using System.Windows.Forms;
sl@19
     3
using System.Collections;
sl@20
     4
using System.ServiceModel;
sl@21
     5
using System.Collections.Generic;
sl@21
     6
using System.Linq;
sl@30
     7
using System.Diagnostics;
sl@55
     8
using SharpDisplay;
sl@17
     9
sl@55
    10
namespace SharpDisplay
sl@17
    11
{
sl@17
    12
    /// <summary>
sl@55
    13
    /// Implement our display services.
sl@55
    14
    /// Each client connection has such a session object server side.
sl@17
    15
    /// </summary>
sl@62
    16
    [ServiceBehavior(
sl@30
    17
                        ConcurrencyMode = ConcurrencyMode.Multiple,
sl@62
    18
                        InstanceContextMode = InstanceContextMode.PerSession
sl@30
    19
                    )]
sl@55
    20
    class Session : IService, IDisposable
sl@17
    21
    {
sl@30
    22
        public string SessionId { get; set; }
sl@32
    23
        public string Name { get; set; }
sl@30
    24
sl@55
    25
        Session()
sl@30
    26
        {
sl@30
    27
            Trace.TraceInformation("Server session opening.");
sl@30
    28
            //First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
sl@30
    29
            SessionId = OperationContext.Current.SessionId;
sl@55
    30
            ICallback callback = OperationContext.Current.GetCallbackChannel<ICallback>();
sl@30
    31
            //
sl@55
    32
            SharpDisplayManager.Program.iMainForm.AddClientThreadSafe(SessionId,callback);
sl@30
    33
sl@30
    34
        }
sl@30
    35
sl@30
    36
        public void Dispose()
sl@30
    37
        {
sl@30
    38
            Trace.TraceInformation("Server session closing.");
sl@55
    39
            SharpDisplayManager.Program.iMainForm.RemoveClientThreadSafe(SessionId);
sl@30
    40
        }
sl@17
    41
sl@20
    42
        //
sl@32
    43
        public void SetName(string aClientName)
sl@20
    44
        {
sl@32
    45
            Name = aClientName;
sl@55
    46
            SharpDisplayManager.Program.iMainForm.SetClientNameThreadSafe(SessionId, Name);
sl@30
    47
            //Disconnect(aClientName);
sl@26
    48
sl@26
    49
            //Register our client and its callback interface
sl@30
    50
            //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
sl@30
    51
            //Program.iMainForm.iClients.Add(aClientName, callback);
sl@30
    52
            //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
sl@21
    53
            //For some reason MP still hangs on that one
sl@21
    54
            //callback.OnConnected();
sl@20
    55
        }
sl@20
    56
sl@62
    57
        public void SetLayout(TableLayout aLayout)
sl@62
    58
        {
sl@62
    59
            SharpDisplayManager.Program.iMainForm.SetClientLayoutThreadSafe(SessionId, aLayout);
sl@62
    60
        }
sl@62
    61
sl@62
    62
        //From IDisplayService
sl@72
    63
        public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
sl@62
    64
        {
sl@72
    65
            SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aFields);
sl@62
    66
        }
sl@62
    67
sl@62
    68
        //
sl@72
    69
        public void SetText(DataField aField)
sl@62
    70
        {
sl@72
    71
            SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField);
sl@62
    72
        }
sl@62
    73
sl@67
    74
        //
sl@72
    75
        public void SetBitmap(DataField aField)
sl@67
    76
        {
sl@72
    77
            SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField);
sl@67
    78
        }
sl@62
    79
sl@26
    80
        ///
sl@32
    81
        public int ClientCount()
sl@26
    82
        {
sl@55
    83
            return SharpDisplayManager.Program.iMainForm.iClients.Count;
sl@26
    84
        }
sl@26
    85
sl@62
    86
sl@21
    87
sl@17
    88
    }
sl@17
    89
sl@17
    90
}