Publishing v0.6.0.0 with hard coded CEC support.
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 /// Compare two TableLayout object.
56 /// <returns>Tells whether both layout are identical.</returns>
57 public bool IsSameAs(TableLayout aTableLayout)
59 //Check rows and columns counts
60 if (Columns.Count != aTableLayout.Columns.Count || Rows.Count != aTableLayout.Rows.Count)
65 //Compare each columns
66 for (int i=0;i<Columns.Count;i++)
68 if (Columns[i].SizeType != aTableLayout.Columns[i].SizeType)
73 if (Columns[i].Width != aTableLayout.Columns[i].Width)
79 //Compare each columns
80 for (int i = 0; i < Rows.Count; i++)
82 if (Rows[i].SizeType != aTableLayout.Rows[i].SizeType)
87 if (Rows[i].Height != aTableLayout.Rows[i].Height)
93 //Both rows and columns have the same content.
98 public List<ColumnStyle> Columns { get; set; }
101 public List<RowStyle> Rows { get; set; }
105 /// Define a data field on our display.
106 /// Data field can be either text or bitmap.
109 public class DataField
118 Alignment = ContentAlignment.MiddleLeft;
124 public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
130 Alignment = aAlignment;
136 public DataField(int aIndex, Bitmap aBitmap)
144 Alignment = ContentAlignment.MiddleLeft;
148 //Generic layout properties
150 public int Index { get; set; }
153 public int Column { get; set; }
156 public int Row { get; set; }
159 public int ColumnSpan { get; set; }
162 public int RowSpan { get; set; }
166 public string Text { get; set; }
169 public ContentAlignment Alignment { get; set; }
173 public Bitmap Bitmap { get; set; }
176 public bool IsBitmap { get{ return Bitmap!=null;} }
178 public bool IsText { get { return Bitmap == null; } }
180 public bool IsSameLayout(DataField aField)
182 return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan);
187 /// Define our SharpDisplay service.
188 /// Clients and servers must implement it to communicate with one another.
189 /// Through this service clients can send requests to a server.
190 /// Through this service a server session can receive requests from a client.
192 [ServiceContract( CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
193 public interface IService
196 /// Set the name of this client.
197 /// Name is a convenient way to recognize your client.
198 /// Naming you client is not mandatory.
199 /// In the absence of a name the session ID is often used instead.
201 /// <param name="aClientName"></param>
202 [OperationContract(IsOneWay = true)]
203 void SetName(string aClientName);
207 /// <param name="aLayout"></param>
208 [OperationContract(IsOneWay = true)]
209 void SetLayout(TableLayout aLayout);
212 /// Set the given field on your display.
213 /// Fields are often just lines of text or bitmaps.
215 /// <param name="aTextFieldIndex"></param>
216 [OperationContract(IsOneWay = true)]
217 void SetField(DataField aField);
220 /// Allows a client to set multiple fields at once.
222 /// <param name="aFields"></param>
223 [OperationContract(IsOneWay = true)]
224 void SetFields(System.Collections.Generic.IList<DataField> aFields);
227 /// Provides the number of clients currently connected
229 /// <returns></returns>
230 [OperationContract()]
236 /// SharDisplay callback provides a means for a server to notify its clients.
238 public interface ICallback
240 [OperationContract(IsOneWay = true)]
244 /// Tell our client to close its connection.
245 /// Notably sent when the server is shutting down.
247 [OperationContract(IsOneWay = true)]