Removing some Text and Bitmap specific stuff and using generic Field instead.
authorsl
Mon, 15 Dec 2014 19:44:41 +0100
changeset 7460d584bad780
parent 73 926cdf23b485
child 77 042c1fa136b9
Removing some Text and Bitmap specific stuff and using generic Field instead.
Client/Client.cs
Client/MainForm.cs
Interface/Interface.cs
Server/Session.cs
     1.1 --- a/Client/Client.cs	Mon Dec 15 18:52:42 2014 +0100
     1.2 +++ b/Client/Client.cs	Mon Dec 15 19:44:41 2014 +0100
     1.3 @@ -57,7 +57,6 @@
     1.4      [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
     1.5      public class Client : DuplexClientBase<IService>
     1.6      {
     1.7 -        public string Name { get; set; }
     1.8          public string SessionId { get { return InnerChannel.SessionId; } }
     1.9  
    1.10          public Client(ICallback aCallback)
    1.11 @@ -66,29 +65,22 @@
    1.12  
    1.13          public void SetName(string aClientName)
    1.14          {
    1.15 -            Name = aClientName;
    1.16              Channel.SetName(aClientName);
    1.17          }
    1.18  
    1.19 -
    1.20          public void SetLayout(TableLayout aLayout)
    1.21          {
    1.22              Channel.SetLayout(aLayout);
    1.23          }
    1.24  
    1.25 -        public void SetText(DataField aField)
    1.26 +        public void SetField(DataField aField)
    1.27          {
    1.28 -            Channel.SetText(aField);
    1.29 +            Channel.SetField(aField);
    1.30          }
    1.31  
    1.32 -        public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
    1.33 +        public void SetFields(System.Collections.Generic.IList<DataField> aFields)
    1.34          {
    1.35 -            Channel.SetTexts(aFields);
    1.36 -        }
    1.37 -
    1.38 -        public void SetBitmap(DataField aField)
    1.39 -        {
    1.40 -            Channel.SetBitmap(aField);
    1.41 +            Channel.SetFields(aFields);
    1.42          }
    1.43  
    1.44          public int ClientCount()
    1.45 @@ -98,7 +90,7 @@
    1.46  
    1.47          public bool IsReady()
    1.48          {
    1.49 -            return State == CommunicationState.Opened;
    1.50 +            return State == CommunicationState.Opened || State == CommunicationState.Created;
    1.51          }
    1.52      }
    1.53  
    1.54 @@ -112,23 +104,23 @@
    1.55          Callback iCallback;
    1.56          private MainForm MainForm { get; set; }
    1.57  
    1.58 -        public string Name { get; set; }
    1.59          public string SessionId { get { return iClient.SessionId; } }
    1.60 +        public string Name { get; private set; }
    1.61 +        private TableLayout Layout { get; set; }
    1.62 +        private System.Collections.Generic.IList<DataField> Fields { get; set; }
    1.63 +
    1.64  
    1.65          public DisplayClient(MainForm aMainForm)
    1.66          {
    1.67              MainForm = aMainForm;
    1.68              Name = "";
    1.69 +            Fields = new DataField[]{};
    1.70          }
    1.71  
    1.72          public void Open()
    1.73          {
    1.74              iCallback = new Callback(MainForm);
    1.75              iClient = new Client(iCallback);
    1.76 -            if (Name != "")
    1.77 -            {
    1.78 -                iClient.SetName(Name);
    1.79 -            }
    1.80          }
    1.81  
    1.82          public void Close()
    1.83 @@ -148,7 +140,17 @@
    1.84          {
    1.85              if (!IsReady())
    1.86              {
    1.87 +                //Try to reconnect
    1.88                  Open();
    1.89 +
    1.90 +                //On reconnect there is a bunch of properties we need to set
    1.91 +                if (Name != "")
    1.92 +                {
    1.93 +                    iClient.SetName(Name);
    1.94 +                }
    1.95 +
    1.96 +                SetLayout(Layout);
    1.97 +                SetFields(Fields);
    1.98              }
    1.99          }
   1.100  
   1.101 @@ -162,27 +164,38 @@
   1.102  
   1.103          public void SetLayout(TableLayout aLayout)
   1.104          {
   1.105 +            Layout = aLayout;
   1.106              CheckConnection();
   1.107              iClient.SetLayout(aLayout);
   1.108          }
   1.109  
   1.110 -        public void SetText(DataField aField)
   1.111 +
   1.112 +        public void SetField(DataField aField)
   1.113          {
   1.114 +            //TODO: Create fields if not present
   1.115 +            int i = 0;
   1.116 +            foreach (DataField field in Fields)
   1.117 +            {
   1.118 +                if (field.Index == aField.Index)
   1.119 +                {
   1.120 +                    //Update our field then
   1.121 +                    Fields[i] = aField;
   1.122 +                    break;
   1.123 +                }
   1.124 +                i++;
   1.125 +            }
   1.126 +
   1.127              CheckConnection();
   1.128 -            iClient.SetText(aField);
   1.129 +            iClient.SetField(aField);
   1.130          }
   1.131  
   1.132 -        public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
   1.133 +        public void SetFields(System.Collections.Generic.IList<DataField> aFields)
   1.134          {
   1.135 +            Fields = aFields;
   1.136              CheckConnection();
   1.137 -            iClient.SetTexts(aFields);
   1.138 +            iClient.SetFields(aFields);
   1.139          }
   1.140  
   1.141 -        public void SetBitmap(DataField aField)
   1.142 -        {
   1.143 -            CheckConnection();
   1.144 -            iClient.SetBitmap(aField);
   1.145 -        }
   1.146  
   1.147          public int ClientCount()
   1.148          {
     2.1 --- a/Client/MainForm.cs	Mon Dec 15 18:52:42 2014 +0100
     2.2 +++ b/Client/MainForm.cs	Mon Dec 15 19:44:41 2014 +0100
     2.3 @@ -69,9 +69,10 @@
     2.4                  //We are in the proper thread
     2.5                  if (IsClientReady())
     2.6                  {
     2.7 -                    Trace.TraceInformation("Closing client: " + iClient.SessionId);
     2.8 +                    string sessionId = iClient.SessionId;
     2.9 +                    Trace.TraceInformation("Closing client: " + sessionId);
    2.10                      iClient.Close();
    2.11 -                    Trace.TraceInformation("Closed client: " + iClient.SessionId);
    2.12 +                    Trace.TraceInformation("Closed client: " + sessionId);
    2.13                  }
    2.14  
    2.15                  iClient = null;
    2.16 @@ -133,7 +134,7 @@
    2.17              //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
    2.18              iTextFieldTop.Text = textBoxTop.Text;
    2.19              iTextFieldTop.Alignment = Alignment;
    2.20 -            iClient.SetText(iTextFieldTop);
    2.21 +            iClient.SetField(iTextFieldTop);
    2.22          }
    2.23  
    2.24          private void buttonSetText_Click(object sender, EventArgs e)
    2.25 @@ -142,7 +143,7 @@
    2.26              //iClient.SetText(1, "Bottom");
    2.27              //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
    2.28  
    2.29 -            iClient.SetTexts(new DataField[]
    2.30 +            iClient.SetFields(new DataField[]
    2.31              {
    2.32                  new DataField(0, textBoxTop.Text, Alignment),
    2.33                  new DataField(1, textBoxBottom.Text, Alignment)
    2.34 @@ -178,7 +179,7 @@
    2.35  
    2.36              DataField field = new DataField(0, bitmap);
    2.37              field.ColumnSpan = 2;
    2.38 -            iClient.SetBitmap(field);
    2.39 +            iClient.SetField(field);
    2.40          }
    2.41  
    2.42          private void buttonBitmapLayout_Click(object sender, EventArgs e)
    2.43 @@ -221,10 +222,11 @@
    2.44              //We want our bitmap field to span across two rows
    2.45              field.RowSpan = 2;
    2.46              //Send it to our server
    2.47 -            iClient.SetBitmap(field);
    2.48 +            //TODO: Check why first run not working when sending with the rest of our fields?
    2.49 +            iClient.SetField(field);
    2.50  
    2.51              //Set texts
    2.52 -            iClient.SetTexts(new DataField[]
    2.53 +            iClient.SetFields(new DataField[]
    2.54              {
    2.55                  new DataField(1, textBoxTop.Text, Alignment),
    2.56                  new DataField(2, textBoxBottom.Text, Alignment)
     3.1 --- a/Interface/Interface.cs	Mon Dec 15 18:52:42 2014 +0100
     3.2 +++ b/Interface/Interface.cs	Mon Dec 15 19:44:41 2014 +0100
     3.3 @@ -113,7 +113,7 @@
     3.4  
     3.5          [DataMember]
     3.6          public int RowSpan { get; set; }
     3.7 -        
     3.8 +
     3.9          //Text properties
    3.10          [DataMember]
    3.11          public string Text { get; set; }
    3.12 @@ -161,22 +161,14 @@
    3.13          /// </summary>
    3.14          /// <param name="aTextFieldIndex"></param>
    3.15          [OperationContract(IsOneWay = true)]
    3.16 -        void SetText(DataField aField);
    3.17 +        void SetField(DataField aField);
    3.18  
    3.19          /// <summary>
    3.20          /// Allows a client to set multiple text fields at once.
    3.21          /// </summary>
    3.22          /// <param name="aTexts"></param>
    3.23          [OperationContract(IsOneWay = true)]
    3.24 -        void SetTexts(System.Collections.Generic.IList<DataField> aFields);
    3.25 -
    3.26 -        /// <summary>
    3.27 -        /// Put the given bitmap in the given field on your display.
    3.28 -        /// Fields are often just lines of text.
    3.29 -        /// </summary>
    3.30 -        /// <param name="aBitmapField"></param>
    3.31 -        [OperationContract(IsOneWay = true)]
    3.32 -        void SetBitmap(DataField aBitmapField);
    3.33 +        void SetFields(System.Collections.Generic.IList<DataField> aFields);
    3.34  
    3.35          /// <summary>
    3.36          /// Provides the number of clients currently connected
     4.1 --- a/Server/Session.cs	Mon Dec 15 18:52:42 2014 +0100
     4.2 +++ b/Server/Session.cs	Mon Dec 15 19:44:41 2014 +0100
     4.3 @@ -60,22 +60,25 @@
     4.4          }
     4.5  
     4.6          //From IDisplayService
     4.7 -        public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
     4.8 +        public void SetFields(System.Collections.Generic.IList<DataField> aFields)
     4.9          {
    4.10              SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aFields);
    4.11          }
    4.12  
    4.13          //
    4.14 -        public void SetText(DataField aField)
    4.15 +        public void SetField(DataField aField)
    4.16          {
    4.17 -            SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField);
    4.18 +            if (aField.HasBitmap)
    4.19 +            {
    4.20 +                SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField);
    4.21 +            }
    4.22 +            else
    4.23 +            {
    4.24 +                SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField);
    4.25 +            }
    4.26 +
    4.27          }
    4.28  
    4.29 -        //
    4.30 -        public void SetBitmap(DataField aField)
    4.31 -        {
    4.32 -            SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField);
    4.33 -        }
    4.34  
    4.35          ///
    4.36          public int ClientCount()