Client now recovers from faulty states and timeout.
authorsl
Mon, 15 Dec 2014 18:52:42 +0100
changeset 73926cdf23b485
parent 72 fd0bb39a7818
child 74 60d584bad780
Client now recovers from faulty states and timeout.
Client/Client.cs
Client/MainForm.cs
     1.1 --- a/Client/Client.cs	Sat Oct 25 13:35:11 2014 +0200
     1.2 +++ b/Client/Client.cs	Mon Dec 15 18:52:42 2014 +0100
     1.3 @@ -101,4 +101,98 @@
     1.4              return State == CommunicationState.Opened;
     1.5          }
     1.6      }
     1.7 +
     1.8 +
     1.9 +    /// <summary>
    1.10 +    ///
    1.11 +    /// </summary>
    1.12 +    public class DisplayClient
    1.13 +    {
    1.14 +        Client iClient;
    1.15 +        Callback iCallback;
    1.16 +        private MainForm MainForm { get; set; }
    1.17 +
    1.18 +        public string Name { get; set; }
    1.19 +        public string SessionId { get { return iClient.SessionId; } }
    1.20 +
    1.21 +        public DisplayClient(MainForm aMainForm)
    1.22 +        {
    1.23 +            MainForm = aMainForm;
    1.24 +            Name = "";
    1.25 +        }
    1.26 +
    1.27 +        public void Open()
    1.28 +        {
    1.29 +            iCallback = new Callback(MainForm);
    1.30 +            iClient = new Client(iCallback);
    1.31 +            if (Name != "")
    1.32 +            {
    1.33 +                iClient.SetName(Name);
    1.34 +            }
    1.35 +        }
    1.36 +
    1.37 +        public void Close()
    1.38 +        {
    1.39 +            iClient.Close();
    1.40 +            iClient = null;
    1.41 +            iCallback.Dispose();
    1.42 +            iCallback = null;
    1.43 +        }
    1.44 +
    1.45 +        public bool IsReady()
    1.46 +        {
    1.47 +            return (iClient != null && iCallback != null && iClient.IsReady());
    1.48 +        }
    1.49 +
    1.50 +        public void CheckConnection()
    1.51 +        {
    1.52 +            if (!IsReady())
    1.53 +            {
    1.54 +                Open();
    1.55 +            }
    1.56 +        }
    1.57 +
    1.58 +        public void SetName(string aClientName)
    1.59 +        {
    1.60 +            Name = aClientName;
    1.61 +            CheckConnection();
    1.62 +            iClient.SetName(aClientName);
    1.63 +        }
    1.64 +
    1.65 +
    1.66 +        public void SetLayout(TableLayout aLayout)
    1.67 +        {
    1.68 +            CheckConnection();
    1.69 +            iClient.SetLayout(aLayout);
    1.70 +        }
    1.71 +
    1.72 +        public void SetText(DataField aField)
    1.73 +        {
    1.74 +            CheckConnection();
    1.75 +            iClient.SetText(aField);
    1.76 +        }
    1.77 +
    1.78 +        public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
    1.79 +        {
    1.80 +            CheckConnection();
    1.81 +            iClient.SetTexts(aFields);
    1.82 +        }
    1.83 +
    1.84 +        public void SetBitmap(DataField aField)
    1.85 +        {
    1.86 +            CheckConnection();
    1.87 +            iClient.SetBitmap(aField);
    1.88 +        }
    1.89 +
    1.90 +        public int ClientCount()
    1.91 +        {
    1.92 +            CheckConnection();
    1.93 +            return iClient.ClientCount();
    1.94 +        }
    1.95 +
    1.96 +
    1.97 +
    1.98 +    }
    1.99 +
   1.100 +
   1.101  }
     2.1 --- a/Client/MainForm.cs	Sat Oct 25 13:35:11 2014 +0200
     2.2 +++ b/Client/MainForm.cs	Mon Dec 15 18:52:42 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 @@ -75,7 +75,6 @@
    2.26                  }
    2.27  
    2.28                  iClient = null;
    2.29 -                iCallback = null;
    2.30              }
    2.31          }
    2.32  
    2.33 @@ -105,7 +104,7 @@
    2.34  
    2.35          public bool IsClientReady()
    2.36          {
    2.37 -            return (iClient != null && iClient.State == CommunicationState.Opened);
    2.38 +            return (iClient != null && iClient.IsReady());
    2.39          }
    2.40  
    2.41          private void buttonAlignLeft_Click(object sender, EventArgs e)
    2.42 @@ -196,7 +195,7 @@
    2.43              TableLayout layout = new TableLayout(2, 2);
    2.44              //First column only takes 25%
    2.45              layout.Columns[0].Width = 25F;
    2.46 -            //Second column takes up 75% 
    2.47 +            //Second column takes up 75%
    2.48              layout.Columns[1].Width = 75F;
    2.49              //Send layout to server
    2.50              iClient.SetLayout(layout);