StephaneLenclud@123: //
StephaneLenclud@123: // Copyright (C) 2014-2015 Stéphane Lenclud.
StephaneLenclud@123: //
StephaneLenclud@123: // This file is part of SharpDisplayManager.
StephaneLenclud@123: //
StephaneLenclud@123: // SharpDisplayManager is free software: you can redistribute it and/or modify
StephaneLenclud@123: // it under the terms of the GNU General Public License as published by
StephaneLenclud@123: // the Free Software Foundation, either version 3 of the License, or
StephaneLenclud@123: // (at your option) any later version.
StephaneLenclud@123: //
StephaneLenclud@123: // SharpDisplayManager is distributed in the hope that it will be useful,
StephaneLenclud@123: // but WITHOUT ANY WARRANTY; without even the implied warranty of
StephaneLenclud@123: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
StephaneLenclud@123: // GNU General Public License for more details.
StephaneLenclud@123: //
StephaneLenclud@123: // You should have received a copy of the GNU General Public License
StephaneLenclud@123: // along with SharpDisplayManager. If not, see .
StephaneLenclud@123: //
StephaneLenclud@123:
StephaneLenclud@123: 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@30: using System.Diagnostics;
StephaneLenclud@171: using SharpLib.Display;
sl@17:
sl@55: namespace SharpDisplay
sl@17: {
sl@17: ///
sl@55: /// Implement our display services.
sl@55: /// Each client connection has such a session object server side.
sl@17: ///
sl@62: [ServiceBehavior(
sl@30: ConcurrencyMode = ConcurrencyMode.Multiple,
sl@62: InstanceContextMode = InstanceContextMode.PerSession
sl@30: )]
sl@55: class Session : IService, IDisposable
sl@17: {
sl@30: public string SessionId { get; set; }
sl@32: public string Name { get; set; }
StephaneLenclud@184: public uint Priority { get; set; }
sl@30:
sl@55: Session()
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@55: ICallback callback = OperationContext.Current.GetCallbackChannel();
sl@30: //
sl@55: SharpDisplayManager.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@55: SharpDisplayManager.Program.iMainForm.RemoveClientThreadSafe(SessionId);
sl@30: }
sl@17:
sl@20: //
sl@32: public void SetName(string aClientName)
sl@20: {
sl@32: Name = aClientName;
sl@55: SharpDisplayManager.Program.iMainForm.SetClientNameThreadSafe(SessionId, Name);
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:
StephaneLenclud@184: ///
StephaneLenclud@184: ///
StephaneLenclud@184: ///
StephaneLenclud@184: ///
StephaneLenclud@184: public void SetPriority(uint aPriority)
StephaneLenclud@184: {
StephaneLenclud@184: Priority = aPriority;
StephaneLenclud@184: SharpDisplayManager.Program.iMainForm.SetClientPriorityThreadSafe(SessionId, Priority);
StephaneLenclud@184: }
StephaneLenclud@184:
sl@62: public void SetLayout(TableLayout aLayout)
sl@62: {
sl@62: SharpDisplayManager.Program.iMainForm.SetClientLayoutThreadSafe(SessionId, aLayout);
sl@62: }
sl@62:
sl@75: //
sl@75: public void SetField(DataField aField)
sl@72: {
sl@75: SharpDisplayManager.Program.iMainForm.SetClientFieldThreadSafe(SessionId, aField);
sl@72: }
sl@72:
sl@62: //From IDisplayService
sl@74: public void SetFields(System.Collections.Generic.IList aFields)
sl@62: {
sl@75: SharpDisplayManager.Program.iMainForm.SetClientFieldsThreadSafe(SessionId, aFields);
sl@62: }
sl@62:
sl@26: ///
sl@32: public int ClientCount()
sl@26: {
sl@55: return SharpDisplayManager.Program.iMainForm.iClients.Count;
sl@26: }
sl@26:
sl@62:
sl@21:
sl@17: }
sl@17:
sl@17: }