author | sl |
Fri, 15 Aug 2014 11:11:17 +0200 | |
changeset 31 | f19b04646b6a |
parent 29 | c4e03315035c |
child 32 | 4c416d2878dd |
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@30 | 23 |
|
sl@30 | 24 |
DisplayServer() |
sl@30 | 25 |
{ |
sl@30 | 26 |
Trace.TraceInformation("Server session opening."); |
sl@30 | 27 |
//First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then. |
sl@30 | 28 |
SessionId = OperationContext.Current.SessionId; |
sl@30 | 29 |
IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>(); |
sl@30 | 30 |
// |
sl@30 | 31 |
Program.iMainForm.AddClientThreadSafe(SessionId,callback); |
sl@30 | 32 |
|
sl@30 | 33 |
} |
sl@30 | 34 |
|
sl@30 | 35 |
public void Dispose() |
sl@30 | 36 |
{ |
sl@30 | 37 |
Trace.TraceInformation("Server session closing."); |
sl@30 | 38 |
Program.iMainForm.RemoveClientThreadSafe(SessionId); |
sl@30 | 39 |
} |
sl@30 | 40 |
|
sl@17 | 41 |
//From IDisplayService |
sl@19 | 42 |
public void SetTexts(System.Collections.Generic.IList<string> aTexts) |
sl@19 | 43 |
{ |
sl@30 | 44 |
Program.iMainForm.SetTextsThreadSafe(aTexts); |
sl@19 | 45 |
} |
sl@22 | 46 |
|
sl@19 | 47 |
// |
sl@17 | 48 |
public void SetText(int aLineIndex, string aText) |
sl@17 | 49 |
{ |
sl@30 | 50 |
Program.iMainForm.SetTextThreadSafe(aLineIndex, aText); |
sl@17 | 51 |
} |
sl@17 | 52 |
|
sl@20 | 53 |
// |
sl@20 | 54 |
public void Connect(string aClientName) |
sl@20 | 55 |
{ |
sl@30 | 56 |
//Disconnect(aClientName); |
sl@26 | 57 |
|
sl@26 | 58 |
//Register our client and its callback interface |
sl@30 | 59 |
//IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>(); |
sl@30 | 60 |
//Program.iMainForm.iClients.Add(aClientName, callback); |
sl@30 | 61 |
//Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName); |
sl@21 | 62 |
//For some reason MP still hangs on that one |
sl@21 | 63 |
//callback.OnConnected(); |
sl@20 | 64 |
} |
sl@20 | 65 |
|
sl@26 | 66 |
/// |
sl@26 | 67 |
public void Disconnect(string aClientName) |
sl@26 | 68 |
{ |
sl@26 | 69 |
//remove the old client if any |
sl@30 | 70 |
/* |
sl@26 | 71 |
if (Program.iMainForm.iClients.Keys.Contains(aClientName)) |
sl@26 | 72 |
{ |
sl@26 | 73 |
Program.iMainForm.iClients.Remove(aClientName); |
sl@30 | 74 |
Program.iMainForm.treeViewClients.Nodes.Remove(Program.iMainForm.treeViewClients.Nodes.Find(aClientName,false)[0]); |
sl@26 | 75 |
} |
sl@30 | 76 |
*/ |
sl@29 | 77 |
|
sl@26 | 78 |
} |
sl@26 | 79 |
|
sl@30 | 80 |
|
sl@21 | 81 |
|
sl@17 | 82 |
} |
sl@17 | 83 |
|
sl@17 | 84 |
} |