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; }
|
sl@30
|
44 |
|
sl@55
|
45 |
Session()
|
sl@30
|
46 |
{
|
sl@30
|
47 |
Trace.TraceInformation("Server session opening.");
|
sl@30
|
48 |
//First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
|
sl@30
|
49 |
SessionId = OperationContext.Current.SessionId;
|
sl@55
|
50 |
ICallback callback = OperationContext.Current.GetCallbackChannel<ICallback>();
|
sl@30
|
51 |
//
|
sl@55
|
52 |
SharpDisplayManager.Program.iMainForm.AddClientThreadSafe(SessionId,callback);
|
sl@30
|
53 |
|
sl@30
|
54 |
}
|
sl@30
|
55 |
|
sl@30
|
56 |
public void Dispose()
|
sl@30
|
57 |
{
|
sl@30
|
58 |
Trace.TraceInformation("Server session closing.");
|
sl@55
|
59 |
SharpDisplayManager.Program.iMainForm.RemoveClientThreadSafe(SessionId);
|
sl@30
|
60 |
}
|
sl@17
|
61 |
|
sl@20
|
62 |
//
|
sl@32
|
63 |
public void SetName(string aClientName)
|
sl@20
|
64 |
{
|
sl@32
|
65 |
Name = aClientName;
|
sl@55
|
66 |
SharpDisplayManager.Program.iMainForm.SetClientNameThreadSafe(SessionId, Name);
|
sl@30
|
67 |
//Disconnect(aClientName);
|
sl@26
|
68 |
|
sl@26
|
69 |
//Register our client and its callback interface
|
sl@30
|
70 |
//IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
|
sl@30
|
71 |
//Program.iMainForm.iClients.Add(aClientName, callback);
|
sl@30
|
72 |
//Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
|
sl@21
|
73 |
//For some reason MP still hangs on that one
|
sl@21
|
74 |
//callback.OnConnected();
|
sl@20
|
75 |
}
|
sl@20
|
76 |
|
StephaneLenclud@184
|
77 |
/// <summary>
|
StephaneLenclud@184
|
78 |
///
|
StephaneLenclud@184
|
79 |
/// </summary>
|
StephaneLenclud@184
|
80 |
/// <param name="aPriority"></param>
|
StephaneLenclud@184
|
81 |
public void SetPriority(uint aPriority)
|
StephaneLenclud@184
|
82 |
{
|
StephaneLenclud@184
|
83 |
Priority = aPriority;
|
StephaneLenclud@184
|
84 |
SharpDisplayManager.Program.iMainForm.SetClientPriorityThreadSafe(SessionId, Priority);
|
StephaneLenclud@184
|
85 |
}
|
StephaneLenclud@184
|
86 |
|
sl@62
|
87 |
public void SetLayout(TableLayout aLayout)
|
sl@62
|
88 |
{
|
sl@62
|
89 |
SharpDisplayManager.Program.iMainForm.SetClientLayoutThreadSafe(SessionId, aLayout);
|
sl@62
|
90 |
}
|
sl@62
|
91 |
|
sl@75
|
92 |
//
|
sl@75
|
93 |
public void SetField(DataField aField)
|
sl@72
|
94 |
{
|
sl@75
|
95 |
SharpDisplayManager.Program.iMainForm.SetClientFieldThreadSafe(SessionId, aField);
|
sl@72
|
96 |
}
|
sl@72
|
97 |
|
sl@62
|
98 |
//From IDisplayService
|
sl@74
|
99 |
public void SetFields(System.Collections.Generic.IList<DataField> aFields)
|
sl@62
|
100 |
{
|
sl@75
|
101 |
SharpDisplayManager.Program.iMainForm.SetClientFieldsThreadSafe(SessionId, aFields);
|
sl@62
|
102 |
}
|
sl@62
|
103 |
|
sl@26
|
104 |
///
|
sl@32
|
105 |
public int ClientCount()
|
sl@26
|
106 |
{
|
sl@55
|
107 |
return SharpDisplayManager.Program.iMainForm.iClients.Count;
|
sl@26
|
108 |
}
|
sl@26
|
109 |
|
sl@62
|
110 |
|
sl@21
|
111 |
|
sl@17
|
112 |
}
|
sl@17
|
113 |
|
sl@17
|
114 |
}
|