Moving ClientData class to its own file.
2 // Define a public API for both SharpDisplay client and server to use.
6 using System.Collections.Generic;
9 using System.Threading.Tasks;
10 using System.ServiceModel;
11 using System.Collections;
13 using System.Runtime.Serialization;
14 using System.Windows.Forms;
17 namespace SharpDisplay
20 /// For client to specify a specific layout.
21 /// A table layout is sent from client to server and defines data fields layout on our display.
24 public class TableLayout
28 Columns = new List<ColumnStyle>();
29 Rows = new List<RowStyle>();
33 /// Construct our table layout.
35 /// <param name="aColumnCount">Number of column in our table.</param>
36 /// <param name="aRowCount">Number of rows in our table.</param>
37 public TableLayout(int aColumnCount, int aRowCount)
39 Columns = new List<ColumnStyle>();
40 Rows = new List<RowStyle>();
42 for (int i = 0; i < aColumnCount; i++)
44 Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount));
47 for (int i = 0; i < aRowCount; i++)
49 Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount));
54 public List<ColumnStyle> Columns { get; set; }
57 public List<RowStyle> Rows { get; set; }
61 /// Define a data field on our display.
62 /// Data field can be either text or bitmap.
65 public class DataField
74 Alignment = ContentAlignment.MiddleLeft;
80 public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
86 Alignment = aAlignment;
92 public DataField(int aIndex, Bitmap aBitmap)
100 Alignment = ContentAlignment.MiddleLeft;
104 //Generic layout properties
106 public int Index { get; set; }
109 public int Column { get; set; }
112 public int Row { get; set; }
115 public int ColumnSpan { get; set; }
118 public int RowSpan { get; set; }
122 public string Text { get; set; }
125 public ContentAlignment Alignment { get; set; }
129 public Bitmap Bitmap { get; set; }
132 public bool IsBitmap { get{ return Bitmap!=null;} }
134 public bool IsText { get { return Bitmap == null; } }
136 public bool IsSameLayout(DataField aField)
138 return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan);
143 /// Define our SharpDisplay service.
144 /// Clients and servers must implement it to communicate with one another.
145 /// Through this service clients can send requests to a server.
146 /// Through this service a server session can receive requests from a client.
148 [ServiceContract( CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
149 public interface IService
152 /// Set the name of this client.
153 /// Name is a convenient way to recognize your client.
154 /// Naming you client is not mandatory.
155 /// In the absence of a name the session ID is often used instead.
157 /// <param name="aClientName"></param>
158 [OperationContract(IsOneWay = true)]
159 void SetName(string aClientName);
163 /// <param name="aLayout"></param>
164 [OperationContract(IsOneWay = true)]
165 void SetLayout(TableLayout aLayout);
168 /// Set the given field on your display.
169 /// Fields are often just lines of text or bitmaps.
171 /// <param name="aTextFieldIndex"></param>
172 [OperationContract(IsOneWay = true)]
173 void SetField(DataField aField);
176 /// Allows a client to set multiple fields at once.
178 /// <param name="aFields"></param>
179 [OperationContract(IsOneWay = true)]
180 void SetFields(System.Collections.Generic.IList<DataField> aFields);
183 /// Provides the number of clients currently connected
185 /// <returns></returns>
186 [OperationContract()]
192 /// SharDisplay callback provides a means for a server to notify its clients.
194 public interface ICallback
196 [OperationContract(IsOneWay = true)]
200 /// Tell our client to close its connection.
201 /// Notably sent when the server is shutting down.
203 [OperationContract(IsOneWay = true)]