Fixing our client issue with static MainForm overwritten when using multiple clients.
That was basically our issue with broadcast not working the way it should.
2 using System.Windows.Forms;
3 using System.Collections;
4 using System.ServiceModel;
5 using System.Collections.Generic;
7 using SharpDisplayInterface;
8 using System.Diagnostics;
10 namespace SharpDisplayManager
13 /// Implement our display service.
14 /// This class is instantiated anew whenever a client send a request.
17 ConcurrencyMode = ConcurrencyMode.Multiple,
18 InstanceContextMode = InstanceContextMode.PerSession
20 class DisplayServer : IDisplayService, IDisposable
22 public string SessionId { get; set; }
26 Trace.TraceInformation("Server session opening.");
27 //First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
28 SessionId = OperationContext.Current.SessionId;
29 IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
31 Program.iMainForm.AddClientThreadSafe(SessionId,callback);
37 Trace.TraceInformation("Server session closing.");
38 Program.iMainForm.RemoveClientThreadSafe(SessionId);
41 //From IDisplayService
42 public void SetTexts(System.Collections.Generic.IList<string> aTexts)
44 Program.iMainForm.SetTextsThreadSafe(aTexts);
48 public void SetText(int aLineIndex, string aText)
50 Program.iMainForm.SetTextThreadSafe(aLineIndex, aText);
54 public void Connect(string aClientName)
56 //Disconnect(aClientName);
58 //Register our client and its callback interface
59 //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel<IDisplayServiceCallback>();
60 //Program.iMainForm.iClients.Add(aClientName, callback);
61 //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
62 //For some reason MP still hangs on that one
63 //callback.OnConnected();
67 public void Disconnect(string aClientName)
69 //remove the old client if any
71 if (Program.iMainForm.iClients.Keys.Contains(aClientName))
73 Program.iMainForm.iClients.Remove(aClientName);
74 Program.iMainForm.treeViewClients.Nodes.Remove(Program.iMainForm.treeViewClients.Nodes.Find(aClientName,false)[0]);