Client/Client.cs
changeset 77 042c1fa136b9
parent 75 2549a8055bd1
parent 74 60d584bad780
child 78 f0dda362f77e
     1.1 --- a/Client/Client.cs	Tue Dec 16 10:59:10 2014 +0100
     1.2 +++ b/Client/Client.cs	Tue Dec 16 11:08:18 2014 +0100
     1.3 @@ -57,7 +57,6 @@
     1.4      [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
     1.5      public class Client : DuplexClientBase<IService>
     1.6      {
     1.7 -        public string Name { get; set; }
     1.8          public string SessionId { get { return InnerChannel.SessionId; } }
     1.9  
    1.10          public Client(ICallback aCallback)
    1.11 @@ -66,11 +65,9 @@
    1.12  
    1.13          public void SetName(string aClientName)
    1.14          {
    1.15 -            Name = aClientName;
    1.16              Channel.SetName(aClientName);
    1.17          }
    1.18  
    1.19 -
    1.20          public void SetLayout(TableLayout aLayout)
    1.21          {
    1.22              Channel.SetLayout(aLayout);
    1.23 @@ -93,7 +90,122 @@
    1.24  
    1.25          public bool IsReady()
    1.26          {
    1.27 -            return State == CommunicationState.Opened;
    1.28 +            return State == CommunicationState.Opened || State == CommunicationState.Created;
    1.29          }
    1.30      }
    1.31 +
    1.32 +
    1.33 +    /// <summary>
    1.34 +    ///
    1.35 +    /// </summary>
    1.36 +    public class DisplayClient
    1.37 +    {
    1.38 +        Client iClient;
    1.39 +        Callback iCallback;
    1.40 +        private MainForm MainForm { get; set; }
    1.41 +
    1.42 +        public string SessionId { get { return iClient.SessionId; } }
    1.43 +        public string Name { get; private set; }
    1.44 +        private TableLayout Layout { get; set; }
    1.45 +        private System.Collections.Generic.IList<DataField> Fields { get; set; }
    1.46 +
    1.47 +
    1.48 +        public DisplayClient(MainForm aMainForm)
    1.49 +        {
    1.50 +            MainForm = aMainForm;
    1.51 +            Name = "";
    1.52 +            Fields = new DataField[]{};
    1.53 +        }
    1.54 +
    1.55 +        public void Open()
    1.56 +        {
    1.57 +            iCallback = new Callback(MainForm);
    1.58 +            iClient = new Client(iCallback);
    1.59 +        }
    1.60 +
    1.61 +        public void Close()
    1.62 +        {
    1.63 +            iClient.Close();
    1.64 +            iClient = null;
    1.65 +            iCallback.Dispose();
    1.66 +            iCallback = null;
    1.67 +        }
    1.68 +
    1.69 +        public bool IsReady()
    1.70 +        {
    1.71 +            return (iClient != null && iCallback != null && iClient.IsReady());
    1.72 +        }
    1.73 +
    1.74 +        public void CheckConnection()
    1.75 +        {
    1.76 +            if (!IsReady())
    1.77 +            {
    1.78 +                //Try to reconnect
    1.79 +                Open();
    1.80 +
    1.81 +                //On reconnect there is a bunch of properties we need to set
    1.82 +                if (Name != "")
    1.83 +                {
    1.84 +                    iClient.SetName(Name);
    1.85 +                }
    1.86 +
    1.87 +                SetLayout(Layout);
    1.88 +                SetFields(Fields);
    1.89 +            }
    1.90 +        }
    1.91 +
    1.92 +        public void SetName(string aClientName)
    1.93 +        {
    1.94 +            Name = aClientName;
    1.95 +            CheckConnection();
    1.96 +            iClient.SetName(aClientName);
    1.97 +        }
    1.98 +
    1.99 +
   1.100 +        public void SetLayout(TableLayout aLayout)
   1.101 +        {
   1.102 +            Layout = aLayout;
   1.103 +            CheckConnection();
   1.104 +            iClient.SetLayout(aLayout);
   1.105 +        }
   1.106 +
   1.107 +
   1.108 +        public void SetField(DataField aField)
   1.109 +        {
   1.110 +            //TODO: Create fields if not present
   1.111 +            int i = 0;
   1.112 +            foreach (DataField field in Fields)
   1.113 +            {
   1.114 +                if (field.Index == aField.Index)
   1.115 +                {
   1.116 +                    //Update our field then
   1.117 +                    Fields[i] = aField;
   1.118 +                    break;
   1.119 +                }
   1.120 +                i++;
   1.121 +            }
   1.122 +
   1.123 +            CheckConnection();
   1.124 +            iClient.SetField(aField);
   1.125 +        }
   1.126 +
   1.127 +        public void SetFields(System.Collections.Generic.IList<DataField> aFields)
   1.128 +        {
   1.129 +            Fields = aFields;
   1.130 +            CheckConnection();
   1.131 +            iClient.SetFields(aFields);
   1.132 +        }
   1.133 +
   1.134 +
   1.135 +        public int ClientCount()
   1.136 +        {
   1.137 +            CheckConnection();
   1.138 +            return iClient.ClientCount();
   1.139 +        }
   1.140 +
   1.141 +
   1.142 +
   1.143 +    }
   1.144 +
   1.145 +
   1.146  }