sl@17: using System;
sl@17: using System.Windows.Forms;
sl@19: using System.Collections;
sl@20: using System.ServiceModel;
sl@21: using System.Collections.Generic;
sl@21: using System.Linq;
sl@22: using SharpDisplayInterface;
sl@30: using System.Diagnostics;
sl@17:
sl@17: namespace SharpDisplayManager
sl@17: {
sl@17: ///
sl@17: /// Implement our display service.
sl@17: /// This class is instantiated anew whenever a client send a request.
sl@17: ///
sl@30: [ServiceBehavior(
sl@30: ConcurrencyMode = ConcurrencyMode.Multiple,
sl@30: InstanceContextMode = InstanceContextMode.PerSession
sl@30: )]
sl@30: class DisplayServer : IDisplayService, IDisposable
sl@17: {
sl@30: public string SessionId { get; set; }
sl@30:
sl@30: DisplayServer()
sl@30: {
sl@30: Trace.TraceInformation("Server session opening.");
sl@30: //First save our session ID. It will be needed in Dispose cause our OperationContxt won't be available then.
sl@30: SessionId = OperationContext.Current.SessionId;
sl@30: IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel();
sl@30: //
sl@30: Program.iMainForm.AddClientThreadSafe(SessionId,callback);
sl@30:
sl@30: }
sl@30:
sl@30: public void Dispose()
sl@30: {
sl@30: Trace.TraceInformation("Server session closing.");
sl@30: Program.iMainForm.RemoveClientThreadSafe(SessionId);
sl@30: }
sl@30:
sl@17: //From IDisplayService
sl@19: public void SetTexts(System.Collections.Generic.IList aTexts)
sl@19: {
sl@30: Program.iMainForm.SetTextsThreadSafe(aTexts);
sl@19: }
sl@22:
sl@19: //
sl@17: public void SetText(int aLineIndex, string aText)
sl@17: {
sl@30: Program.iMainForm.SetTextThreadSafe(aLineIndex, aText);
sl@17: }
sl@17:
sl@20: //
sl@20: public void Connect(string aClientName)
sl@20: {
sl@30: //Disconnect(aClientName);
sl@26:
sl@26: //Register our client and its callback interface
sl@30: //IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel();
sl@30: //Program.iMainForm.iClients.Add(aClientName, callback);
sl@30: //Program.iMainForm.treeViewClients.Nodes.Add(aClientName, aClientName);
sl@21: //For some reason MP still hangs on that one
sl@21: //callback.OnConnected();
sl@20: }
sl@20:
sl@26: ///
sl@26: public void Disconnect(string aClientName)
sl@26: {
sl@26: //remove the old client if any
sl@30: /*
sl@26: if (Program.iMainForm.iClients.Keys.Contains(aClientName))
sl@26: {
sl@26: Program.iMainForm.iClients.Remove(aClientName);
sl@30: Program.iMainForm.treeViewClients.Nodes.Remove(Program.iMainForm.treeViewClients.Nodes.Find(aClientName,false)[0]);
sl@26: }
sl@30: */
sl@29:
sl@26: }
sl@26:
sl@30:
sl@21:
sl@17: }
sl@17:
sl@17: }