author | StephaneLenclud |
Wed, 02 Sep 2015 22:35:47 +0200 | |
changeset 155 | 703daa997f59 |
parent 138 | 426cc984fd18 |
permissions | -rw-r--r-- |
sl@56 | 1 |
// |
sl@56 | 2 |
// Define a public API for both SharpDisplay client and server to use. |
sl@56 | 3 |
// |
sl@56 | 4 |
|
sl@56 | 5 |
using System; |
sl@24 | 6 |
using System.Collections.Generic; |
sl@24 | 7 |
using System.Linq; |
sl@24 | 8 |
using System.Text; |
sl@24 | 9 |
using System.Threading.Tasks; |
sl@24 | 10 |
using System.ServiceModel; |
sl@24 | 11 |
using System.Collections; |
sl@43 | 12 |
using System.Drawing; |
sl@43 | 13 |
using System.Runtime.Serialization; |
sl@63 | 14 |
using System.Windows.Forms; |
sl@24 | 15 |
|
sl@24 | 16 |
|
sl@55 | 17 |
namespace SharpDisplay |
sl@24 | 18 |
{ |
sl@56 | 19 |
/// <summary> |
StephaneLenclud@64 | 20 |
/// For client to specify a specific layout. |
StephaneLenclud@138 | 21 |
/// A table layout is sent from client to server and defines data fields layout on our display. |
sl@56 | 22 |
/// </summary> |
sl@43 | 23 |
[DataContract] |
sl@62 | 24 |
public class TableLayout |
sl@62 | 25 |
{ |
sl@62 | 26 |
public TableLayout() |
sl@62 | 27 |
{ |
sl@63 | 28 |
Columns = new List<ColumnStyle>(); |
sl@63 | 29 |
Rows = new List<RowStyle>(); |
sl@62 | 30 |
} |
sl@62 | 31 |
|
StephaneLenclud@138 | 32 |
/// <summary> |
StephaneLenclud@138 | 33 |
/// Construct our table layout. |
StephaneLenclud@138 | 34 |
/// </summary> |
StephaneLenclud@138 | 35 |
/// <param name="aColumnCount">Number of column in our table.</param> |
StephaneLenclud@138 | 36 |
/// <param name="aRowCount">Number of rows in our table.</param> |
sl@62 | 37 |
public TableLayout(int aColumnCount, int aRowCount) |
sl@62 | 38 |
{ |
sl@63 | 39 |
Columns = new List<ColumnStyle>(); |
sl@63 | 40 |
Rows = new List<RowStyle>(); |
sl@63 | 41 |
|
sl@63 | 42 |
for (int i = 0; i < aColumnCount; i++) |
sl@63 | 43 |
{ |
sl@63 | 44 |
Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount)); |
sl@63 | 45 |
} |
sl@63 | 46 |
|
sl@63 | 47 |
for (int i = 0; i < aRowCount; i++) |
sl@63 | 48 |
{ |
sl@63 | 49 |
Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount)); |
sl@63 | 50 |
} |
sl@62 | 51 |
} |
sl@62 | 52 |
|
StephaneLenclud@148 | 53 |
/// <summary> |
StephaneLenclud@148 | 54 |
/// Compare two TableLayout object. |
StephaneLenclud@148 | 55 |
/// </summary> |
StephaneLenclud@148 | 56 |
/// <returns>Tells whether both layout are identical.</returns> |
StephaneLenclud@148 | 57 |
public bool IsSameAs(TableLayout aTableLayout) |
StephaneLenclud@148 | 58 |
{ |
StephaneLenclud@148 | 59 |
//Check rows and columns counts |
StephaneLenclud@148 | 60 |
if (Columns.Count != aTableLayout.Columns.Count || Rows.Count != aTableLayout.Rows.Count) |
StephaneLenclud@148 | 61 |
{ |
StephaneLenclud@148 | 62 |
return false; |
StephaneLenclud@148 | 63 |
} |
StephaneLenclud@148 | 64 |
|
StephaneLenclud@148 | 65 |
//Compare each columns |
StephaneLenclud@148 | 66 |
for (int i=0;i<Columns.Count;i++) |
StephaneLenclud@148 | 67 |
{ |
StephaneLenclud@148 | 68 |
if (Columns[i].SizeType != aTableLayout.Columns[i].SizeType) |
StephaneLenclud@148 | 69 |
{ |
StephaneLenclud@148 | 70 |
return false; |
StephaneLenclud@148 | 71 |
} |
StephaneLenclud@148 | 72 |
|
StephaneLenclud@148 | 73 |
if (Columns[i].Width != aTableLayout.Columns[i].Width) |
StephaneLenclud@148 | 74 |
{ |
StephaneLenclud@148 | 75 |
return false; |
StephaneLenclud@148 | 76 |
} |
StephaneLenclud@148 | 77 |
} |
StephaneLenclud@148 | 78 |
|
StephaneLenclud@148 | 79 |
//Compare each columns |
StephaneLenclud@148 | 80 |
for (int i = 0; i < Rows.Count; i++) |
StephaneLenclud@148 | 81 |
{ |
StephaneLenclud@148 | 82 |
if (Rows[i].SizeType != aTableLayout.Rows[i].SizeType) |
StephaneLenclud@148 | 83 |
{ |
StephaneLenclud@148 | 84 |
return false; |
StephaneLenclud@148 | 85 |
} |
StephaneLenclud@148 | 86 |
|
StephaneLenclud@148 | 87 |
if (Rows[i].Height != aTableLayout.Rows[i].Height) |
StephaneLenclud@148 | 88 |
{ |
StephaneLenclud@148 | 89 |
return false; |
StephaneLenclud@148 | 90 |
} |
StephaneLenclud@148 | 91 |
} |
StephaneLenclud@148 | 92 |
|
StephaneLenclud@148 | 93 |
//Both rows and columns have the same content. |
StephaneLenclud@148 | 94 |
return true; |
StephaneLenclud@148 | 95 |
} |
StephaneLenclud@148 | 96 |
|
sl@62 | 97 |
[DataMember] |
sl@63 | 98 |
public List<ColumnStyle> Columns { get; set; } |
sl@62 | 99 |
|
sl@62 | 100 |
[DataMember] |
sl@63 | 101 |
public List<RowStyle> Rows { get; set; } |
sl@62 | 102 |
} |
sl@62 | 103 |
|
sl@62 | 104 |
/// <summary> |
StephaneLenclud@138 | 105 |
/// Define a data field on our display. |
StephaneLenclud@138 | 106 |
/// Data field can be either text or bitmap. |
sl@62 | 107 |
/// </summary> |
sl@62 | 108 |
[DataContract] |
sl@62 | 109 |
public class DataField |
sl@62 | 110 |
{ |
sl@66 | 111 |
public DataField() |
sl@66 | 112 |
{ |
sl@66 | 113 |
Index = 0; |
sl@66 | 114 |
ColumnSpan = 1; |
sl@66 | 115 |
RowSpan = 1; |
sl@72 | 116 |
//Text |
sl@72 | 117 |
Text = ""; |
sl@72 | 118 |
Alignment = ContentAlignment.MiddleLeft; |
sl@72 | 119 |
//Bitmap |
sl@72 | 120 |
Bitmap = null; |
sl@66 | 121 |
} |
sl@66 | 122 |
|
sl@72 | 123 |
//Text constructor |
sl@72 | 124 |
public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) |
sl@72 | 125 |
{ |
sl@72 | 126 |
ColumnSpan = 1; |
sl@72 | 127 |
RowSpan = 1; |
sl@72 | 128 |
Index = aIndex; |
sl@72 | 129 |
Text = aText; |
sl@72 | 130 |
Alignment = aAlignment; |
sl@72 | 131 |
// |
sl@72 | 132 |
Bitmap = null; |
sl@72 | 133 |
} |
sl@72 | 134 |
|
sl@72 | 135 |
//Bitmap constructor |
sl@72 | 136 |
public DataField(int aIndex, Bitmap aBitmap) |
sl@72 | 137 |
{ |
sl@72 | 138 |
ColumnSpan = 1; |
sl@72 | 139 |
RowSpan = 1; |
sl@72 | 140 |
Index = aIndex; |
sl@72 | 141 |
Bitmap = aBitmap; |
sl@72 | 142 |
//Text |
sl@72 | 143 |
Text = ""; |
sl@72 | 144 |
Alignment = ContentAlignment.MiddleLeft; |
sl@72 | 145 |
} |
sl@72 | 146 |
|
sl@72 | 147 |
|
sl@72 | 148 |
//Generic layout properties |
sl@66 | 149 |
[DataMember] |
sl@66 | 150 |
public int Index { get; set; } |
sl@66 | 151 |
|
sl@62 | 152 |
[DataMember] |
sl@62 | 153 |
public int Column { get; set; } |
sl@62 | 154 |
|
sl@62 | 155 |
[DataMember] |
sl@62 | 156 |
public int Row { get; set; } |
sl@62 | 157 |
|
sl@62 | 158 |
[DataMember] |
sl@62 | 159 |
public int ColumnSpan { get; set; } |
sl@62 | 160 |
|
sl@62 | 161 |
[DataMember] |
sl@62 | 162 |
public int RowSpan { get; set; } |
sl@74 | 163 |
|
sl@72 | 164 |
//Text properties |
sl@43 | 165 |
[DataMember] |
sl@43 | 166 |
public string Text { get; set; } |
sl@43 | 167 |
|
sl@43 | 168 |
[DataMember] |
sl@43 | 169 |
public ContentAlignment Alignment { get; set; } |
sl@43 | 170 |
|
sl@72 | 171 |
//Bitmap properties |
sl@66 | 172 |
[DataMember] |
sl@66 | 173 |
public Bitmap Bitmap { get; set; } |
sl@72 | 174 |
|
sl@72 | 175 |
// |
sl@75 | 176 |
public bool IsBitmap { get{ return Bitmap!=null;} } |
sl@75 | 177 |
// |
sl@75 | 178 |
public bool IsText { get { return Bitmap == null; } } |
sl@75 | 179 |
// |
sl@75 | 180 |
public bool IsSameLayout(DataField aField) |
sl@75 | 181 |
{ |
sl@75 | 182 |
return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan); |
sl@75 | 183 |
} |
sl@66 | 184 |
} |
sl@66 | 185 |
|
sl@66 | 186 |
/// <summary> |
sl@56 | 187 |
/// Define our SharpDisplay service. |
sl@56 | 188 |
/// Clients and servers must implement it to communicate with one another. |
sl@56 | 189 |
/// Through this service clients can send requests to a server. |
sl@56 | 190 |
/// Through this service a server session can receive requests from a client. |
sl@56 | 191 |
/// </summary> |
sl@55 | 192 |
[ServiceContract( CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)] |
sl@55 | 193 |
public interface IService |
sl@24 | 194 |
{ |
sl@32 | 195 |
/// <summary> |
sl@32 | 196 |
/// Set the name of this client. |
sl@32 | 197 |
/// Name is a convenient way to recognize your client. |
sl@32 | 198 |
/// Naming you client is not mandatory. |
sl@32 | 199 |
/// In the absence of a name the session ID is often used instead. |
sl@32 | 200 |
/// </summary> |
sl@32 | 201 |
/// <param name="aClientName"></param> |
sl@24 | 202 |
[OperationContract(IsOneWay = true)] |
sl@32 | 203 |
void SetName(string aClientName); |
sl@24 | 204 |
|
sl@62 | 205 |
/// <summary> |
sl@62 | 206 |
/// </summary> |
sl@62 | 207 |
/// <param name="aLayout"></param> |
sl@62 | 208 |
[OperationContract(IsOneWay = true)] |
sl@62 | 209 |
void SetLayout(TableLayout aLayout); |
sl@62 | 210 |
|
sl@32 | 211 |
/// <summary> |
sl@75 | 212 |
/// Set the given field on your display. |
sl@75 | 213 |
/// Fields are often just lines of text or bitmaps. |
sl@32 | 214 |
/// </summary> |
sl@43 | 215 |
/// <param name="aTextFieldIndex"></param> |
sl@24 | 216 |
[OperationContract(IsOneWay = true)] |
sl@74 | 217 |
void SetField(DataField aField); |
sl@26 | 218 |
|
sl@32 | 219 |
/// <summary> |
sl@75 | 220 |
/// Allows a client to set multiple fields at once. |
sl@32 | 221 |
/// </summary> |
sl@75 | 222 |
/// <param name="aFields"></param> |
sl@24 | 223 |
[OperationContract(IsOneWay = true)] |
sl@74 | 224 |
void SetFields(System.Collections.Generic.IList<DataField> aFields); |
sl@67 | 225 |
|
sl@67 | 226 |
/// <summary> |
sl@32 | 227 |
/// Provides the number of clients currently connected |
sl@32 | 228 |
/// </summary> |
sl@32 | 229 |
/// <returns></returns> |
sl@32 | 230 |
[OperationContract()] |
sl@32 | 231 |
int ClientCount(); |
sl@32 | 232 |
|
sl@24 | 233 |
} |
sl@24 | 234 |
|
sl@56 | 235 |
/// <summary> |
sl@56 | 236 |
/// SharDisplay callback provides a means for a server to notify its clients. |
sl@56 | 237 |
/// </summary> |
sl@55 | 238 |
public interface ICallback |
sl@24 | 239 |
{ |
sl@24 | 240 |
[OperationContract(IsOneWay = true)] |
sl@24 | 241 |
void OnConnected(); |
sl@24 | 242 |
|
sl@32 | 243 |
/// <summary> |
sl@32 | 244 |
/// Tell our client to close its connection. |
sl@32 | 245 |
/// Notably sent when the server is shutting down. |
sl@32 | 246 |
/// </summary> |
sl@24 | 247 |
[OperationContract(IsOneWay = true)] |
sl@32 | 248 |
void OnCloseOrder(); |
sl@24 | 249 |
} |
sl@24 | 250 |
|
sl@24 | 251 |
} |