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