diff -r 042c1fa136b9 -r f0dda362f77e Client/Client.cs
--- a/Client/Client.cs Tue Dec 16 11:08:18 2014 +0100
+++ b/Client/Client.cs Tue Dec 16 13:24:12 2014 +0100
@@ -96,14 +96,16 @@
///
- ///
+ /// Handle connection with our Sharp Display Server.
+ /// If the connection is faulted it will attempt to restart it.
///
public class DisplayClient
{
- Client iClient;
- Callback iCallback;
+ private Client iClient;
+ private Callback iCallback;
+ private bool resetingConnection = false;
+
private MainForm MainForm { get; set; }
-
public string SessionId { get { return iClient.SessionId; } }
public string Name { get; private set; }
private TableLayout Layout { get; set; }
@@ -117,12 +119,18 @@
Fields = new DataField[]{};
}
+ ///
+ /// Initialize our server connection.
+ ///
public void Open()
{
iCallback = new Callback(MainForm);
iClient = new Client(iCallback);
}
+ ///
+ /// Terminate our server connection.
+ ///
public void Close()
{
iClient.Close();
@@ -131,26 +139,45 @@
iCallback = null;
}
+ ///
+ /// Tells whether a server connection is available.
+ ///
+ /// True if a server connection is available. False otherwise.
public bool IsReady()
{
return (iClient != null && iCallback != null && iClient.IsReady());
}
+ ///
+ /// Check if our server connection is available and attempt reset it if it isn't.
+ /// This is notably dealing with timed out connections.
+ ///
public void CheckConnection()
{
- if (!IsReady())
+ if (!IsReady() && !resetingConnection)
{
//Try to reconnect
Open();
- //On reconnect there is a bunch of properties we need to set
- if (Name != "")
+ //Avoid stack overflow in case of persisting failure
+ resetingConnection = true;
+
+ try
{
- iClient.SetName(Name);
+ //On reconnect there is a bunch of properties we need to reset
+ if (Name != "")
+ {
+ iClient.SetName(Name);
+ }
+
+ SetLayout(Layout);
+ SetFields(Fields);
}
-
- SetLayout(Layout);
- SetFields(Fields);
+ finally
+ {
+ //Make sure our this state does not get out of sync
+ resetingConnection = true;
+ }
}
}