# HG changeset patch # User sl # Date 1418669081 -3600 # Node ID 60d584bad780e4722a1525651cbf2cae0a25ada0 # Parent 926cdf23b485fe0b9db9d63dfaed7999cb41d71a Removing some Text and Bitmap specific stuff and using generic Field instead. diff -r 926cdf23b485 -r 60d584bad780 Client/Client.cs --- a/Client/Client.cs Mon Dec 15 18:52:42 2014 +0100 +++ b/Client/Client.cs Mon Dec 15 19:44:41 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,29 +65,22 @@ public void SetName(string aClientName) { - Name = aClientName; Channel.SetName(aClientName); } - public void SetLayout(TableLayout aLayout) { Channel.SetLayout(aLayout); } - public void SetText(DataField aField) + public void SetField(DataField aField) { - Channel.SetText(aField); + Channel.SetField(aField); } - public void SetTexts(System.Collections.Generic.IList aFields) + public void SetFields(System.Collections.Generic.IList aFields) { - Channel.SetTexts(aFields); - } - - public void SetBitmap(DataField aField) - { - Channel.SetBitmap(aField); + Channel.SetFields(aFields); } public int ClientCount() @@ -98,7 +90,7 @@ public bool IsReady() { - return State == CommunicationState.Opened; + return State == CommunicationState.Opened || State == CommunicationState.Created; } } @@ -112,23 +104,23 @@ Callback iCallback; private MainForm MainForm { get; set; } - public string Name { 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); - if (Name != "") - { - iClient.SetName(Name); - } } public void Close() @@ -148,7 +140,17 @@ { 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); } } @@ -162,27 +164,38 @@ public void SetLayout(TableLayout aLayout) { + Layout = aLayout; CheckConnection(); iClient.SetLayout(aLayout); } - public void SetText(DataField aField) + + 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.SetText(aField); + iClient.SetField(aField); } - public void SetTexts(System.Collections.Generic.IList aFields) + public void SetFields(System.Collections.Generic.IList aFields) { + Fields = aFields; CheckConnection(); - iClient.SetTexts(aFields); + iClient.SetFields(aFields); } - public void SetBitmap(DataField aField) - { - CheckConnection(); - iClient.SetBitmap(aField); - } public int ClientCount() { diff -r 926cdf23b485 -r 60d584bad780 Client/MainForm.cs --- a/Client/MainForm.cs Mon Dec 15 18:52:42 2014 +0100 +++ b/Client/MainForm.cs Mon Dec 15 19:44:41 2014 +0100 @@ -69,9 +69,10 @@ //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; @@ -133,7 +134,7 @@ //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); iTextFieldTop.Text = textBoxTop.Text; iTextFieldTop.Alignment = Alignment; - iClient.SetText(iTextFieldTop); + iClient.SetField(iTextFieldTop); } private void buttonSetText_Click(object sender, EventArgs e) @@ -142,7 +143,7 @@ //iClient.SetText(1, "Bottom"); //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); - iClient.SetTexts(new DataField[] + iClient.SetFields(new DataField[] { new DataField(0, textBoxTop.Text, Alignment), new DataField(1, textBoxBottom.Text, Alignment) @@ -178,7 +179,7 @@ DataField field = new DataField(0, bitmap); field.ColumnSpan = 2; - iClient.SetBitmap(field); + iClient.SetField(field); } private void buttonBitmapLayout_Click(object sender, EventArgs e) @@ -221,10 +222,11 @@ //We want our bitmap field to span across two rows field.RowSpan = 2; //Send it to our server - iClient.SetBitmap(field); + //TODO: Check why first run not working when sending with the rest of our fields? + iClient.SetField(field); //Set texts - iClient.SetTexts(new DataField[] + iClient.SetFields(new DataField[] { new DataField(1, textBoxTop.Text, Alignment), new DataField(2, textBoxBottom.Text, Alignment) diff -r 926cdf23b485 -r 60d584bad780 Interface/Interface.cs --- a/Interface/Interface.cs Mon Dec 15 18:52:42 2014 +0100 +++ b/Interface/Interface.cs Mon Dec 15 19:44:41 2014 +0100 @@ -113,7 +113,7 @@ [DataMember] public int RowSpan { get; set; } - + //Text properties [DataMember] public string Text { get; set; } @@ -161,22 +161,14 @@ /// /// [OperationContract(IsOneWay = true)] - void SetText(DataField aField); + void SetField(DataField aField); /// /// Allows a client to set multiple text fields at once. /// /// [OperationContract(IsOneWay = true)] - void SetTexts(System.Collections.Generic.IList aFields); - - /// - /// Put the given bitmap in the given field on your display. - /// Fields are often just lines of text. - /// - /// - [OperationContract(IsOneWay = true)] - void SetBitmap(DataField aBitmapField); + void SetFields(System.Collections.Generic.IList aFields); /// /// Provides the number of clients currently connected diff -r 926cdf23b485 -r 60d584bad780 Server/Session.cs --- a/Server/Session.cs Mon Dec 15 18:52:42 2014 +0100 +++ b/Server/Session.cs Mon Dec 15 19:44:41 2014 +0100 @@ -60,22 +60,25 @@ } //From IDisplayService - public void SetTexts(System.Collections.Generic.IList aFields) + public void SetFields(System.Collections.Generic.IList aFields) { SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aFields); } // - public void SetText(DataField aField) + public void SetField(DataField aField) { - SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField); + if (aField.HasBitmap) + { + SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField); + } + else + { + SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField); + } + } - // - public void SetBitmap(DataField aField) - { - SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField); - } /// public int ClientCount()