Server/Session.cs
author sl
Mon, 22 Sep 2014 13:00:27 +0200
changeset 60 4f2a73683adc
parent 55 b5ed2e29be23
child 62 ac698f4e1b36
permissions -rw-r--r--
Adding and removing row is now working.
Can now have any number of text field.
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@30
    16
    [ServiceBehavior(   
sl@30
    17
                        ConcurrencyMode = ConcurrencyMode.Multiple,
sl@30
    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@30
    41
        
sl@17
    42
        //From IDisplayService
sl@43
    43
        public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
sl@19
    44
        {
sl@55
    45
            SharpDisplayManager.Program.iMainForm.SetTextsThreadSafe(SessionId, aTextFields);
sl@19
    46
        }
sl@22
    47
sl@19
    48
        //
sl@43
    49
        public void SetText(TextField aTextField)
sl@17
    50
        {
sl@55
    51
            SharpDisplayManager.Program.iMainForm.SetTextThreadSafe(SessionId, aTextField);
sl@17
    52
        }
sl@17
    53
sl@20
    54
        //
sl@32
    55
        public void SetName(string aClientName)
sl@20
    56
        {
sl@32
    57
            Name = aClientName;
sl@55
    58
            SharpDisplayManager.Program.iMainForm.SetClientNameThreadSafe(SessionId, Name);
sl@30
    59
            //Disconnect(aClientName);
sl@26
    60
sl@26
    61
            //Register our client and its callback interface
sl@30
    62
            //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
sl@30
    63
            //Program.iMainForm.iClients.Add(aClientName, callback);
sl@30
    64
            //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
sl@21
    65
            //For some reason MP still hangs on that one
sl@21
    66
            //callback.OnConnected();
sl@20
    67
        }
sl@20
    68
sl@26
    69
        ///
sl@32
    70
        public int ClientCount()
sl@26
    71
        {
sl@55
    72
            return SharpDisplayManager.Program.iMainForm.iClients.Count;
sl@26
    73
        }
sl@26
    74
sl@30
    75
        
sl@21
    76
sl@17
    77
    }
sl@17
    78
sl@17
    79
}