Merge field unification changes and client recovery feature.
authorsl
Tue, 16 Dec 2014 11:08:18 +0100
changeset 77042c1fa136b9
parent 76 906d88eb53fb
parent 74 60d584bad780
child 78 f0dda362f77e
child 82 42d62953c937
Merge field unification changes and client recovery feature.
Client/Client.cs
Client/MainForm.cs
Interface/Interface.cs
Server/Session.cs
     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  }
     2.1 --- a/Client/MainForm.cs	Tue Dec 16 10:59:10 2014 +0100
     2.2 +++ b/Client/MainForm.cs	Tue Dec 16 11:08:18 2014 +0100
     2.3 @@ -17,8 +17,8 @@
     2.4  {
     2.5      public partial class MainForm : Form
     2.6      {
     2.7 -        Client iClient;
     2.8 -        Callback iCallback;
     2.9 +        DisplayClient iClient;
    2.10 +
    2.11          ContentAlignment Alignment;
    2.12          DataField iTextFieldTop;
    2.13  
    2.14 @@ -32,8 +32,8 @@
    2.15  
    2.16          private void MainForm_Load(object sender, EventArgs e)
    2.17          {
    2.18 -            iCallback = new Callback(this);
    2.19 -            iClient = new Client(iCallback);
    2.20 +            iClient = new DisplayClient(this);
    2.21 +            iClient.Open();
    2.22  
    2.23              //Connect using unique name
    2.24              //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
    2.25 @@ -69,13 +69,13 @@
    2.26                  //We are in the proper thread
    2.27                  if (IsClientReady())
    2.28                  {
    2.29 -                    Trace.TraceInformation("Closing client: " + iClient.SessionId);
    2.30 +                    string sessionId = iClient.SessionId;
    2.31 +                    Trace.TraceInformation("Closing client: " + sessionId);
    2.32                      iClient.Close();
    2.33 -                    Trace.TraceInformation("Closed client: " + iClient.SessionId);
    2.34 +                    Trace.TraceInformation("Closed client: " + sessionId);
    2.35                  }
    2.36  
    2.37                  iClient = null;
    2.38 -                iCallback = null;
    2.39              }
    2.40          }
    2.41  
    2.42 @@ -105,7 +105,7 @@
    2.43  
    2.44          public bool IsClientReady()
    2.45          {
    2.46 -            return (iClient != null && iClient.State == CommunicationState.Opened);
    2.47 +            return (iClient != null && iClient.IsReady());
    2.48          }
    2.49  
    2.50          private void buttonAlignLeft_Click(object sender, EventArgs e)
    2.51 @@ -196,7 +196,7 @@
    2.52              TableLayout layout = new TableLayout(2, 2);
    2.53              //First column only takes 25%
    2.54              layout.Columns[0].Width = 25F;
    2.55 -            //Second column takes up 75% 
    2.56 +            //Second column takes up 75%
    2.57              layout.Columns[1].Width = 75F;
    2.58              //Send layout to server
    2.59              iClient.SetLayout(layout);
    2.60 @@ -221,6 +221,7 @@
    2.61              DataField field = new DataField(0, bitmap);
    2.62              //We want our bitmap field to span across two rows
    2.63              field.RowSpan = 2;
    2.64 +            iClient.SetField(field);
    2.65  
    2.66              //Set texts
    2.67              iClient.SetFields(new DataField[]
     3.1 --- a/Interface/Interface.cs	Tue Dec 16 10:59:10 2014 +0100
     3.2 +++ b/Interface/Interface.cs	Tue Dec 16 11:08:18 2014 +0100
     3.3 @@ -113,7 +113,7 @@
     3.4  
     3.5          [DataMember]
     3.6          public int RowSpan { get; set; }
     3.7 -        
     3.8 +
     3.9          //Text properties
    3.10          [DataMember]
    3.11          public string Text { get; set; }