author | sl |
Sun, 31 Aug 2014 18:33:05 +0200 | |
changeset 52 | b22b0127afa4 |
parent 34 | 59bfa4ebcbbb |
child 55 | b5ed2e29be23 |
permissions | -rw-r--r-- |
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@22 | 7 |
using SharpDisplayInterface; |
sl@30 | 8 |
using System.Diagnostics; |
sl@17 | 9 |
|
sl@17 | 10 |
namespace SharpDisplayManager |
sl@17 | 11 |
{ |
sl@17 | 12 |
/// <summary> |
sl@17 | 13 |
/// Implement our display service. |
sl@17 | 14 |
/// This class is instantiated anew whenever a client send a request. |
sl@17 | 15 |
/// </summary> |
sl@30 | 16 |
[ServiceBehavior( |
sl@30 | 17 |
ConcurrencyMode = ConcurrencyMode.Multiple, |
sl@30 | 18 |
InstanceContextMode = InstanceContextMode.PerSession |
sl@30 | 19 |
)] |
sl@30 | 20 |
class DisplayServer : IDisplayService, IDisposable |
sl@17 | 21 |
{ |
sl@30 | 22 |
public string SessionId { get; set; } |
sl@32 | 23 |
public string Name { get; set; } |
sl@30 | 24 |
|
sl@30 | 25 |
DisplayServer() |
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@30 | 30 |
IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>(); |
sl@30 | 31 |
// |
sl@30 | 32 |
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@30 | 39 |
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@43 | 45 |
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@43 | 51 |
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@32 | 58 |
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@32 | 72 |
return 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 |
} |