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@62
|
63 |
public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
|
sl@62
|
64 |
{
|
sl@65
|
65 |
SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aTextFields);
|
sl@62
|
66 |
}
|
sl@62
|
67 |
|
sl@62
|
68 |
//
|
sl@62
|
69 |
public void SetText(TextField aTextField)
|
sl@62
|
70 |
{
|
sl@65
|
71 |
SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aTextField);
|
sl@62
|
72 |
}
|
sl@62
|
73 |
|
sl@62
|
74 |
|
sl@26
|
75 |
///
|
sl@32
|
76 |
public int ClientCount()
|
sl@26
|
77 |
{
|
sl@55
|
78 |
return SharpDisplayManager.Program.iMainForm.iClients.Count;
|
sl@26
|
79 |
}
|
sl@26
|
80 |
|
sl@62
|
81 |
|
sl@21
|
82 |
|
sl@17
|
83 |
}
|
sl@17
|
84 |
|
sl@17
|
85 |
}
|