author | sl |
Sun, 26 Oct 2014 16:16:57 +0100 | |
changeset 75 | 2549a8055bd1 |
parent 72 | fd0bb39a7818 |
child 76 | 906d88eb53fb |
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. |
sl@56 | 21 |
/// </summary> |
sl@43 | 22 |
[DataContract] |
sl@62 | 23 |
public class TableLayout |
sl@62 | 24 |
{ |
sl@62 | 25 |
public TableLayout() |
sl@62 | 26 |
{ |
sl@63 | 27 |
Columns = new List<ColumnStyle>(); |
sl@63 | 28 |
Rows = new List<RowStyle>(); |
sl@63 | 29 |
Cells = new List<DataField>(); |
sl@62 | 30 |
} |
sl@62 | 31 |
|
sl@62 | 32 |
public TableLayout(int aColumnCount, int aRowCount) |
sl@62 | 33 |
{ |
sl@63 | 34 |
Columns = new List<ColumnStyle>(); |
sl@63 | 35 |
Rows = new List<RowStyle>(); |
sl@63 | 36 |
|
sl@63 | 37 |
for (int i = 0; i < aColumnCount; i++) |
sl@63 | 38 |
{ |
sl@63 | 39 |
Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount)); |
sl@63 | 40 |
} |
sl@63 | 41 |
|
sl@63 | 42 |
for (int i = 0; i < aRowCount; i++) |
sl@63 | 43 |
{ |
sl@63 | 44 |
Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount)); |
sl@63 | 45 |
} |
sl@62 | 46 |
} |
sl@62 | 47 |
|
sl@62 | 48 |
[DataMember] |
sl@63 | 49 |
public List<DataField> Cells { get; set; } |
sl@62 | 50 |
|
sl@62 | 51 |
[DataMember] |
sl@63 | 52 |
public List<ColumnStyle> Columns { get; set; } |
sl@62 | 53 |
|
sl@62 | 54 |
[DataMember] |
sl@63 | 55 |
public List<RowStyle> Rows { get; set; } |
sl@62 | 56 |
} |
sl@62 | 57 |
|
sl@62 | 58 |
/// <summary> |
sl@62 | 59 |
/// |
sl@62 | 60 |
/// </summary> |
sl@62 | 61 |
[DataContract] |
sl@62 | 62 |
public class DataField |
sl@62 | 63 |
{ |
sl@66 | 64 |
public DataField() |
sl@66 | 65 |
{ |
sl@66 | 66 |
Index = 0; |
sl@66 | 67 |
ColumnSpan = 1; |
sl@66 | 68 |
RowSpan = 1; |
sl@72 | 69 |
//Text |
sl@72 | 70 |
Text = ""; |
sl@72 | 71 |
Alignment = ContentAlignment.MiddleLeft; |
sl@72 | 72 |
//Bitmap |
sl@72 | 73 |
Bitmap = null; |
sl@66 | 74 |
} |
sl@66 | 75 |
|
sl@72 | 76 |
//Text constructor |
sl@72 | 77 |
public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) |
sl@72 | 78 |
{ |
sl@72 | 79 |
ColumnSpan = 1; |
sl@72 | 80 |
RowSpan = 1; |
sl@72 | 81 |
Index = aIndex; |
sl@72 | 82 |
Text = aText; |
sl@72 | 83 |
Alignment = aAlignment; |
sl@72 | 84 |
// |
sl@72 | 85 |
Bitmap = null; |
sl@72 | 86 |
} |
sl@72 | 87 |
|
sl@72 | 88 |
//Bitmap constructor |
sl@72 | 89 |
public DataField(int aIndex, Bitmap aBitmap) |
sl@72 | 90 |
{ |
sl@72 | 91 |
ColumnSpan = 1; |
sl@72 | 92 |
RowSpan = 1; |
sl@72 | 93 |
Index = aIndex; |
sl@72 | 94 |
Bitmap = aBitmap; |
sl@72 | 95 |
//Text |
sl@72 | 96 |
Text = ""; |
sl@72 | 97 |
Alignment = ContentAlignment.MiddleLeft; |
sl@72 | 98 |
} |
sl@72 | 99 |
|
sl@72 | 100 |
|
sl@72 | 101 |
//Generic layout properties |
sl@66 | 102 |
[DataMember] |
sl@66 | 103 |
public int Index { get; set; } |
sl@66 | 104 |
|
sl@62 | 105 |
[DataMember] |
sl@62 | 106 |
public int Column { get; set; } |
sl@62 | 107 |
|
sl@62 | 108 |
[DataMember] |
sl@62 | 109 |
public int Row { get; set; } |
sl@62 | 110 |
|
sl@62 | 111 |
[DataMember] |
sl@62 | 112 |
public int ColumnSpan { get; set; } |
sl@62 | 113 |
|
sl@62 | 114 |
[DataMember] |
sl@62 | 115 |
public int RowSpan { get; set; } |
sl@72 | 116 |
|
sl@72 | 117 |
//Text properties |
sl@43 | 118 |
[DataMember] |
sl@43 | 119 |
public string Text { get; set; } |
sl@43 | 120 |
|
sl@43 | 121 |
[DataMember] |
sl@43 | 122 |
public ContentAlignment Alignment { get; set; } |
sl@43 | 123 |
|
sl@72 | 124 |
//Bitmap properties |
sl@66 | 125 |
[DataMember] |
sl@66 | 126 |
public Bitmap Bitmap { get; set; } |
sl@72 | 127 |
|
sl@72 | 128 |
// |
sl@75 | 129 |
public bool IsBitmap { get{ return Bitmap!=null;} } |
sl@75 | 130 |
// |
sl@75 | 131 |
public bool IsText { get { return Bitmap == null; } } |
sl@75 | 132 |
// |
sl@75 | 133 |
public bool IsSameLayout(DataField aField) |
sl@75 | 134 |
{ |
sl@75 | 135 |
return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan); |
sl@75 | 136 |
} |
sl@66 | 137 |
} |
sl@66 | 138 |
|
sl@66 | 139 |
/// <summary> |
sl@56 | 140 |
/// Define our SharpDisplay service. |
sl@56 | 141 |
/// Clients and servers must implement it to communicate with one another. |
sl@56 | 142 |
/// Through this service clients can send requests to a server. |
sl@56 | 143 |
/// Through this service a server session can receive requests from a client. |
sl@56 | 144 |
/// </summary> |
sl@55 | 145 |
[ServiceContract( CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)] |
sl@55 | 146 |
public interface IService |
sl@24 | 147 |
{ |
sl@32 | 148 |
/// <summary> |
sl@32 | 149 |
/// Set the name of this client. |
sl@32 | 150 |
/// Name is a convenient way to recognize your client. |
sl@32 | 151 |
/// Naming you client is not mandatory. |
sl@32 | 152 |
/// In the absence of a name the session ID is often used instead. |
sl@32 | 153 |
/// </summary> |
sl@32 | 154 |
/// <param name="aClientName"></param> |
sl@24 | 155 |
[OperationContract(IsOneWay = true)] |
sl@32 | 156 |
void SetName(string aClientName); |
sl@24 | 157 |
|
sl@62 | 158 |
/// <summary> |
sl@62 | 159 |
/// </summary> |
sl@62 | 160 |
/// <param name="aLayout"></param> |
sl@62 | 161 |
[OperationContract(IsOneWay = true)] |
sl@62 | 162 |
void SetLayout(TableLayout aLayout); |
sl@62 | 163 |
|
sl@32 | 164 |
/// <summary> |
sl@75 | 165 |
/// Set the given field on your display. |
sl@75 | 166 |
/// Fields are often just lines of text or bitmaps. |
sl@32 | 167 |
/// </summary> |
sl@43 | 168 |
/// <param name="aTextFieldIndex"></param> |
sl@24 | 169 |
[OperationContract(IsOneWay = true)] |
sl@75 | 170 |
void SetField(DataField aField); |
sl@26 | 171 |
|
sl@32 | 172 |
/// <summary> |
sl@75 | 173 |
/// Allows a client to set multiple fields at once. |
sl@32 | 174 |
/// </summary> |
sl@75 | 175 |
/// <param name="aFields"></param> |
sl@24 | 176 |
[OperationContract(IsOneWay = true)] |
sl@75 | 177 |
void SetFields(System.Collections.Generic.IList<DataField> aFields); |
sl@67 | 178 |
|
sl@67 | 179 |
/// <summary> |
sl@32 | 180 |
/// Provides the number of clients currently connected |
sl@32 | 181 |
/// </summary> |
sl@32 | 182 |
/// <returns></returns> |
sl@32 | 183 |
[OperationContract()] |
sl@32 | 184 |
int ClientCount(); |
sl@32 | 185 |
|
sl@24 | 186 |
} |
sl@24 | 187 |
|
sl@56 | 188 |
/// <summary> |
sl@56 | 189 |
/// SharDisplay callback provides a means for a server to notify its clients. |
sl@56 | 190 |
/// </summary> |
sl@55 | 191 |
public interface ICallback |
sl@24 | 192 |
{ |
sl@24 | 193 |
[OperationContract(IsOneWay = true)] |
sl@24 | 194 |
void OnConnected(); |
sl@24 | 195 |
|
sl@32 | 196 |
/// <summary> |
sl@32 | 197 |
/// Tell our client to close its connection. |
sl@32 | 198 |
/// Notably sent when the server is shutting down. |
sl@32 | 199 |
/// </summary> |
sl@24 | 200 |
[OperationContract(IsOneWay = true)] |
sl@32 | 201 |
void OnCloseOrder(); |
sl@24 | 202 |
} |
sl@24 | 203 |
|
sl@24 | 204 |
|
sl@24 | 205 |
|
sl@24 | 206 |
} |