# HG changeset patch # User sl # Date 1418665962 -3600 # Node ID 926cdf23b485fe0b9db9d63dfaed7999cb41d71a # Parent fd0bb39a7818195f4209e1ed57ec75648843e9e3 Client now recovers from faulty states and timeout. diff -r fd0bb39a7818 -r 926cdf23b485 Client/Client.cs --- a/Client/Client.cs Sat Oct 25 13:35:11 2014 +0200 +++ b/Client/Client.cs Mon Dec 15 18:52:42 2014 +0100 @@ -101,4 +101,98 @@ return State == CommunicationState.Opened; } } + + + /// + /// + /// + public class DisplayClient + { + Client iClient; + Callback iCallback; + private MainForm MainForm { get; set; } + + public string Name { get; set; } + public string SessionId { get { return iClient.SessionId; } } + + public DisplayClient(MainForm aMainForm) + { + MainForm = aMainForm; + Name = ""; + } + + public void Open() + { + iCallback = new Callback(MainForm); + iClient = new Client(iCallback); + if (Name != "") + { + iClient.SetName(Name); + } + } + + public void Close() + { + iClient.Close(); + iClient = null; + iCallback.Dispose(); + iCallback = null; + } + + public bool IsReady() + { + return (iClient != null && iCallback != null && iClient.IsReady()); + } + + public void CheckConnection() + { + if (!IsReady()) + { + Open(); + } + } + + public void SetName(string aClientName) + { + Name = aClientName; + CheckConnection(); + iClient.SetName(aClientName); + } + + + public void SetLayout(TableLayout aLayout) + { + CheckConnection(); + iClient.SetLayout(aLayout); + } + + public void SetText(DataField aField) + { + CheckConnection(); + iClient.SetText(aField); + } + + public void SetTexts(System.Collections.Generic.IList aFields) + { + CheckConnection(); + iClient.SetTexts(aFields); + } + + public void SetBitmap(DataField aField) + { + CheckConnection(); + iClient.SetBitmap(aField); + } + + public int ClientCount() + { + CheckConnection(); + return iClient.ClientCount(); + } + + + + } + + } diff -r fd0bb39a7818 -r 926cdf23b485 Client/MainForm.cs --- a/Client/MainForm.cs Sat Oct 25 13:35:11 2014 +0200 +++ b/Client/MainForm.cs Mon Dec 15 18:52:42 2014 +0100 @@ -17,8 +17,8 @@ { public partial class MainForm : Form { - Client iClient; - Callback iCallback; + DisplayClient iClient; + ContentAlignment Alignment; DataField iTextFieldTop; @@ -32,8 +32,8 @@ private void MainForm_Load(object sender, EventArgs e) { - iCallback = new Callback(this); - iClient = new Client(iCallback); + iClient = new DisplayClient(this); + iClient.Open(); //Connect using unique name //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); @@ -75,7 +75,6 @@ } iClient = null; - iCallback = null; } } @@ -105,7 +104,7 @@ public bool IsClientReady() { - return (iClient != null && iClient.State == CommunicationState.Opened); + return (iClient != null && iClient.IsReady()); } private void buttonAlignLeft_Click(object sender, EventArgs e) @@ -196,7 +195,7 @@ TableLayout layout = new TableLayout(2, 2); //First column only takes 25% layout.Columns[0].Width = 25F; - //Second column takes up 75% + //Second column takes up 75% layout.Columns[1].Width = 75F; //Send layout to server iClient.SetLayout(layout);