# HG changeset patch # User sl # Date 1418724498 -3600 # Node ID 042c1fa136b9b3898aab81fd62c1b4b5823677fb # Parent 906d88eb53fb10f17dbb5cdd95ce2fa6a8958110# Parent 60d584bad780e4722a1525651cbf2cae0a25ada0 Merge field unification changes and client recovery feature. diff -r 906d88eb53fb -r 042c1fa136b9 Client/Client.cs --- a/Client/Client.cs Tue Dec 16 10:59:10 2014 +0100 +++ b/Client/Client.cs Tue Dec 16 11:08:18 2014 +0100 @@ -57,7 +57,6 @@ [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] public class Client : DuplexClientBase { - public string Name { get; set; } public string SessionId { get { return InnerChannel.SessionId; } } public Client(ICallback aCallback) @@ -66,11 +65,9 @@ public void SetName(string aClientName) { - Name = aClientName; Channel.SetName(aClientName); } - public void SetLayout(TableLayout aLayout) { Channel.SetLayout(aLayout); @@ -93,7 +90,122 @@ public bool IsReady() { - return State == CommunicationState.Opened; + return State == CommunicationState.Opened || State == CommunicationState.Created; } } + + + /// + /// + /// + public class DisplayClient + { + Client iClient; + Callback iCallback; + private MainForm MainForm { get; set; } + + public string SessionId { get { return iClient.SessionId; } } + public string Name { get; private set; } + private TableLayout Layout { get; set; } + private System.Collections.Generic.IList Fields { get; set; } + + + public DisplayClient(MainForm aMainForm) + { + MainForm = aMainForm; + Name = ""; + Fields = new DataField[]{}; + } + + public void Open() + { + iCallback = new Callback(MainForm); + iClient = new Client(iCallback); + } + + 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()) + { + //Try to reconnect + Open(); + + //On reconnect there is a bunch of properties we need to set + if (Name != "") + { + iClient.SetName(Name); + } + + SetLayout(Layout); + SetFields(Fields); + } + } + + public void SetName(string aClientName) + { + Name = aClientName; + CheckConnection(); + iClient.SetName(aClientName); + } + + + public void SetLayout(TableLayout aLayout) + { + Layout = aLayout; + CheckConnection(); + iClient.SetLayout(aLayout); + } + + + public void SetField(DataField aField) + { + //TODO: Create fields if not present + int i = 0; + foreach (DataField field in Fields) + { + if (field.Index == aField.Index) + { + //Update our field then + Fields[i] = aField; + break; + } + i++; + } + + CheckConnection(); + iClient.SetField(aField); + } + + public void SetFields(System.Collections.Generic.IList aFields) + { + Fields = aFields; + CheckConnection(); + iClient.SetFields(aFields); + } + + + public int ClientCount() + { + CheckConnection(); + return iClient.ClientCount(); + } + + + + } + + } diff -r 906d88eb53fb -r 042c1fa136b9 Client/MainForm.cs --- a/Client/MainForm.cs Tue Dec 16 10:59:10 2014 +0100 +++ b/Client/MainForm.cs Tue Dec 16 11:08:18 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"); @@ -69,13 +69,13 @@ //We are in the proper thread if (IsClientReady()) { - Trace.TraceInformation("Closing client: " + iClient.SessionId); + string sessionId = iClient.SessionId; + Trace.TraceInformation("Closing client: " + sessionId); iClient.Close(); - Trace.TraceInformation("Closed client: " + iClient.SessionId); + Trace.TraceInformation("Closed client: " + sessionId); } iClient = null; - iCallback = null; } } @@ -105,7 +105,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 +196,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); @@ -221,6 +221,7 @@ DataField field = new DataField(0, bitmap); //We want our bitmap field to span across two rows field.RowSpan = 2; + iClient.SetField(field); //Set texts iClient.SetFields(new DataField[] diff -r 906d88eb53fb -r 042c1fa136b9 Interface/Interface.cs --- a/Interface/Interface.cs Tue Dec 16 10:59:10 2014 +0100 +++ b/Interface/Interface.cs Tue Dec 16 11:08:18 2014 +0100 @@ -113,7 +113,7 @@ [DataMember] public int RowSpan { get; set; } - + //Text properties [DataMember] public string Text { get; set; }