author | sl |
Mon, 22 Sep 2014 13:00:27 +0200 | |
changeset 60 | 4f2a73683adc |
parent 55 | b5ed2e29be23 |
child 62 | ac698f4e1b36 |
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@24 | 14 |
|
sl@24 | 15 |
|
sl@55 | 16 |
namespace SharpDisplay |
sl@24 | 17 |
{ |
sl@56 | 18 |
/// <summary> |
sl@56 | 19 |
/// TextField can be send to our server to be displayed on the screen. |
sl@56 | 20 |
/// </summary> |
sl@43 | 21 |
[DataContract] |
sl@43 | 22 |
public class TextField |
sl@43 | 23 |
{ |
sl@43 | 24 |
public TextField() |
sl@43 | 25 |
{ |
sl@43 | 26 |
Index = 0; |
sl@43 | 27 |
Text = ""; |
sl@43 | 28 |
Alignment = ContentAlignment.MiddleLeft; |
sl@43 | 29 |
} |
sl@43 | 30 |
|
sl@43 | 31 |
public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) |
sl@43 | 32 |
{ |
sl@43 | 33 |
Index = aIndex; |
sl@43 | 34 |
Text = aText; |
sl@43 | 35 |
Alignment = aAlignment; |
sl@43 | 36 |
} |
sl@43 | 37 |
|
sl@43 | 38 |
[DataMember] |
sl@43 | 39 |
public int Index { get; set; } |
sl@43 | 40 |
|
sl@43 | 41 |
[DataMember] |
sl@43 | 42 |
public string Text { get; set; } |
sl@43 | 43 |
|
sl@43 | 44 |
[DataMember] |
sl@43 | 45 |
public ContentAlignment Alignment { get; set; } |
sl@43 | 46 |
} |
sl@43 | 47 |
|
sl@56 | 48 |
/// <summary> |
sl@56 | 49 |
/// Define our SharpDisplay service. |
sl@56 | 50 |
/// Clients and servers must implement it to communicate with one another. |
sl@56 | 51 |
/// Through this service clients can send requests to a server. |
sl@56 | 52 |
/// Through this service a server session can receive requests from a client. |
sl@56 | 53 |
/// </summary> |
sl@55 | 54 |
[ServiceContract( CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)] |
sl@55 | 55 |
public interface IService |
sl@24 | 56 |
{ |
sl@32 | 57 |
/// <summary> |
sl@32 | 58 |
/// Set the name of this client. |
sl@32 | 59 |
/// Name is a convenient way to recognize your client. |
sl@32 | 60 |
/// Naming you client is not mandatory. |
sl@32 | 61 |
/// In the absence of a name the session ID is often used instead. |
sl@32 | 62 |
/// </summary> |
sl@32 | 63 |
/// <param name="aClientName"></param> |
sl@24 | 64 |
[OperationContract(IsOneWay = true)] |
sl@32 | 65 |
void SetName(string aClientName); |
sl@24 | 66 |
|
sl@32 | 67 |
/// <summary> |
sl@32 | 68 |
/// Put the given text in the given field on your display. |
sl@32 | 69 |
/// Fields are often just lines of text. |
sl@32 | 70 |
/// </summary> |
sl@43 | 71 |
/// <param name="aTextFieldIndex"></param> |
sl@24 | 72 |
[OperationContract(IsOneWay = true)] |
sl@43 | 73 |
void SetText(TextField aTextField); |
sl@26 | 74 |
|
sl@32 | 75 |
/// <summary> |
sl@32 | 76 |
/// Allows a client to set multiple text fields at once. |
sl@32 | 77 |
/// </summary> |
sl@32 | 78 |
/// <param name="aTexts"></param> |
sl@24 | 79 |
[OperationContract(IsOneWay = true)] |
sl@43 | 80 |
void SetTexts(System.Collections.Generic.IList<TextField> aTextFields); |
sl@32 | 81 |
|
sl@32 | 82 |
/// <summary> |
sl@32 | 83 |
/// Provides the number of clients currently connected |
sl@32 | 84 |
/// </summary> |
sl@32 | 85 |
/// <returns></returns> |
sl@32 | 86 |
[OperationContract()] |
sl@32 | 87 |
int ClientCount(); |
sl@32 | 88 |
|
sl@24 | 89 |
} |
sl@24 | 90 |
|
sl@56 | 91 |
/// <summary> |
sl@56 | 92 |
/// SharDisplay callback provides a means for a server to notify its clients. |
sl@56 | 93 |
/// </summary> |
sl@55 | 94 |
public interface ICallback |
sl@24 | 95 |
{ |
sl@24 | 96 |
[OperationContract(IsOneWay = true)] |
sl@24 | 97 |
void OnConnected(); |
sl@24 | 98 |
|
sl@32 | 99 |
/// <summary> |
sl@32 | 100 |
/// Tell our client to close its connection. |
sl@32 | 101 |
/// Notably sent when the server is shutting down. |
sl@32 | 102 |
/// </summary> |
sl@24 | 103 |
[OperationContract(IsOneWay = true)] |
sl@32 | 104 |
void OnCloseOrder(); |
sl@24 | 105 |
} |
sl@24 | 106 |
|
sl@24 | 107 |
|
sl@24 | 108 |
|
sl@24 | 109 |
} |