1.1 --- a/Server/Servers.cs Thu Aug 14 18:37:23 2014 +0200
1.2 +++ b/Server/Servers.cs Fri Aug 15 10:20:01 2014 +0200
1.3 @@ -5,6 +5,7 @@
1.4 using System.Collections.Generic;
1.5 using System.Linq;
1.6 using SharpDisplayInterface;
1.7 +using System.Diagnostics;
1.8
1.9 namespace SharpDisplayManager
1.10 {
1.11 @@ -12,49 +13,52 @@
1.12 /// Implement our display service.
1.13 /// This class is instantiated anew whenever a client send a request.
1.14 /// </summary>
1.15 - [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
1.16 - class DisplayServer : IDisplayService
1.17 + [ServiceBehavior(
1.18 + ConcurrencyMode = ConcurrencyMode.Multiple,
1.19 + InstanceContextMode = InstanceContextMode.PerSession
1.20 + )]
1.21 + class DisplayServer : IDisplayService, IDisposable
1.22 {
1.23 + public string SessionId { get; set; }
1.24 +
1.25 + DisplayServer()
1.26 + {
1.27 + Trace.TraceInformation("Server session opening.");
1.28 + //First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
1.29 + SessionId = OperationContext.Current.SessionId;
1.30 + IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
1.31 + //
1.32 + Program.iMainForm.AddClientThreadSafe(SessionId,callback);
1.33 +
1.34 + }
1.35 +
1.36 + public void Dispose()
1.37 + {
1.38 + Trace.TraceInformation("Server session closing.");
1.39 + Program.iMainForm.RemoveClientThreadSafe(SessionId);
1.40 + }
1.41 +
1.42 //From IDisplayService
1.43 public void SetTexts(System.Collections.Generic.IList<string> aTexts)
1.44 {
1.45 - //Only support two lines for now
1.46 - for (int i=0; i<aTexts.Count; i++)
1.47 - {
1.48 - if (i == 0)
1.49 - {
1.50 - Program.iMainForm.marqueeLabelTop.Text = aTexts[i];
1.51 - }
1.52 - else if (i == 1)
1.53 - {
1.54 - Program.iMainForm.marqueeLabelBottom.Text = aTexts[i];
1.55 - }
1.56 - }
1.57 + Program.iMainForm.SetTextsThreadSafe(aTexts);
1.58 }
1.59
1.60 //
1.61 public void SetText(int aLineIndex, string aText)
1.62 {
1.63 - //Only support two lines for now
1.64 - if (aLineIndex == 0)
1.65 - {
1.66 - Program.iMainForm.marqueeLabelTop.Text = aText;
1.67 - }
1.68 - else if (aLineIndex == 1)
1.69 - {
1.70 - Program.iMainForm.marqueeLabelBottom.Text = aText;
1.71 - }
1.72 + Program.iMainForm.SetTextThreadSafe(aLineIndex, aText);
1.73 }
1.74
1.75 //
1.76 public void Connect(string aClientName)
1.77 {
1.78 - Disconnect(aClientName);
1.79 + //Disconnect(aClientName);
1.80
1.81 //Register our client and its callback interface
1.82 - IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
1.83 - Program.iMainForm.iClients.Add(aClientName, callback);
1.84 -
1.85 + //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
1.86 + //Program.iMainForm.iClients.Add(aClientName, callback);
1.87 + //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
1.88 //For some reason MP still hangs on that one
1.89 //callback.OnConnected();
1.90 }
1.91 @@ -63,13 +67,17 @@
1.92 public void Disconnect(string aClientName)
1.93 {
1.94 //remove the old client if any
1.95 + /*
1.96 if (Program.iMainForm.iClients.Keys.Contains(aClientName))
1.97 {
1.98 Program.iMainForm.iClients.Remove(aClientName);
1.99 + Program.iMainForm.treeViewClients.Nodes.Remove(Program.iMainForm.treeViewClients.Nodes.Find(aClientName,false)[0]);
1.100 }
1.101 + */
1.102
1.103 }
1.104
1.105 +
1.106
1.107 }
1.108