sl@56: // sl@56: // Define a public API for both SharpDisplay client and server to use. sl@56: // sl@56: sl@56: using System; sl@24: using System.Collections.Generic; sl@24: using System.Linq; sl@24: using System.Text; sl@24: using System.Threading.Tasks; sl@24: using System.ServiceModel; sl@24: using System.Collections; sl@43: using System.Drawing; sl@43: using System.Runtime.Serialization; sl@63: using System.Windows.Forms; sl@24: sl@24: sl@55: namespace SharpDisplay sl@24: { sl@63: sl@63: sl@63: sl@56: /// StephaneLenclud@64: /// For client to specify a specific layout. sl@56: /// sl@43: [DataContract] sl@62: public class TableLayout sl@62: { sl@62: public TableLayout() sl@62: { sl@63: Columns = new List(); sl@63: Rows = new List(); sl@63: Cells = new List(); sl@62: } sl@62: sl@62: public TableLayout(int aColumnCount, int aRowCount) sl@62: { sl@63: Columns = new List(); sl@63: Rows = new List(); sl@63: sl@63: for (int i = 0; i < aColumnCount; i++) sl@63: { sl@63: Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount)); sl@63: } sl@63: sl@63: for (int i = 0; i < aRowCount; i++) sl@63: { sl@63: Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount)); sl@63: } sl@62: } sl@62: sl@62: [DataMember] sl@63: public List Cells { get; set; } sl@62: sl@62: [DataMember] sl@63: public List Columns { get; set; } sl@62: sl@62: [DataMember] sl@63: public List Rows { get; set; } sl@62: } sl@62: sl@62: /// sl@62: /// sl@62: /// sl@62: [DataContract] sl@62: public class DataField sl@62: { sl@62: [DataMember] sl@62: public int Column { get; set; } sl@62: sl@62: [DataMember] sl@62: public int Row { get; set; } sl@62: sl@62: [DataMember] sl@62: public int ColumnSpan { get; set; } sl@62: sl@62: [DataMember] sl@62: public int RowSpan { get; set; } sl@62: sl@62: } sl@62: sl@62: sl@62: /// sl@62: /// TextField can be send to our server to be displayed on the screen. sl@62: /// sl@62: [DataContract] sl@62: public class TextField : DataField sl@43: { sl@43: public TextField() sl@43: { sl@43: Index = 0; sl@43: Text = ""; sl@43: Alignment = ContentAlignment.MiddleLeft; sl@43: } sl@43: sl@43: public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) sl@43: { sl@43: Index = aIndex; sl@43: Text = aText; sl@43: Alignment = aAlignment; sl@43: } sl@43: sl@43: [DataMember] sl@43: public int Index { get; set; } sl@43: sl@43: [DataMember] sl@43: public string Text { get; set; } sl@43: sl@43: [DataMember] sl@43: public ContentAlignment Alignment { get; set; } sl@43: } sl@43: sl@56: /// sl@56: /// Define our SharpDisplay service. sl@56: /// Clients and servers must implement it to communicate with one another. sl@56: /// Through this service clients can send requests to a server. sl@56: /// Through this service a server session can receive requests from a client. sl@56: /// sl@55: [ServiceContract( CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)] sl@55: public interface IService sl@24: { sl@32: /// sl@32: /// Set the name of this client. sl@32: /// Name is a convenient way to recognize your client. sl@32: /// Naming you client is not mandatory. sl@32: /// In the absence of a name the session ID is often used instead. sl@32: /// sl@32: /// sl@24: [OperationContract(IsOneWay = true)] sl@32: void SetName(string aClientName); sl@24: sl@62: /// sl@62: /// sl@62: /// sl@62: [OperationContract(IsOneWay = true)] sl@62: void SetLayout(TableLayout aLayout); sl@62: sl@32: /// sl@32: /// Put the given text in the given field on your display. sl@32: /// Fields are often just lines of text. sl@32: /// sl@43: /// sl@24: [OperationContract(IsOneWay = true)] sl@43: void SetText(TextField aTextField); sl@26: sl@32: /// sl@32: /// Allows a client to set multiple text fields at once. sl@32: /// sl@32: /// sl@24: [OperationContract(IsOneWay = true)] sl@43: void SetTexts(System.Collections.Generic.IList aTextFields); sl@32: sl@32: /// sl@32: /// Provides the number of clients currently connected sl@32: /// sl@32: /// sl@32: [OperationContract()] sl@32: int ClientCount(); sl@32: sl@24: } sl@24: sl@56: /// sl@56: /// SharDisplay callback provides a means for a server to notify its clients. sl@56: /// sl@55: public interface ICallback sl@24: { sl@24: [OperationContract(IsOneWay = true)] sl@24: void OnConnected(); sl@24: sl@32: /// sl@32: /// Tell our client to close its connection. sl@32: /// Notably sent when the server is shutting down. sl@32: /// sl@24: [OperationContract(IsOneWay = true)] sl@32: void OnCloseOrder(); sl@24: } sl@24: sl@24: sl@24: sl@24: }