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@56: /// StephaneLenclud@64: /// For client to specify a specific layout. StephaneLenclud@138: /// A table layout is sent from client to server and defines data fields layout on our display. 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@62: } sl@62: StephaneLenclud@138: /// StephaneLenclud@138: /// Construct our table layout. StephaneLenclud@138: /// StephaneLenclud@138: /// Number of column in our table. StephaneLenclud@138: /// Number of rows in our table. 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 Columns { get; set; } sl@62: sl@62: [DataMember] sl@63: public List Rows { get; set; } sl@62: } sl@62: sl@62: /// StephaneLenclud@138: /// Define a data field on our display. StephaneLenclud@138: /// Data field can be either text or bitmap. sl@62: /// sl@62: [DataContract] sl@62: public class DataField sl@62: { sl@66: public DataField() sl@66: { sl@66: Index = 0; sl@66: ColumnSpan = 1; sl@66: RowSpan = 1; sl@72: //Text sl@72: Text = ""; sl@72: Alignment = ContentAlignment.MiddleLeft; sl@72: //Bitmap sl@72: Bitmap = null; sl@66: } sl@66: sl@72: //Text constructor sl@72: public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) sl@72: { sl@72: ColumnSpan = 1; sl@72: RowSpan = 1; sl@72: Index = aIndex; sl@72: Text = aText; sl@72: Alignment = aAlignment; sl@72: // sl@72: Bitmap = null; sl@72: } sl@72: sl@72: //Bitmap constructor sl@72: public DataField(int aIndex, Bitmap aBitmap) sl@72: { sl@72: ColumnSpan = 1; sl@72: RowSpan = 1; sl@72: Index = aIndex; sl@72: Bitmap = aBitmap; sl@72: //Text sl@72: Text = ""; sl@72: Alignment = ContentAlignment.MiddleLeft; sl@72: } sl@72: sl@72: sl@72: //Generic layout properties sl@66: [DataMember] sl@66: public int Index { get; set; } sl@66: 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@74: sl@72: //Text properties 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@72: //Bitmap properties sl@66: [DataMember] sl@66: public Bitmap Bitmap { get; set; } sl@72: sl@72: // sl@75: public bool IsBitmap { get{ return Bitmap!=null;} } sl@75: // sl@75: public bool IsText { get { return Bitmap == null; } } sl@75: // sl@75: public bool IsSameLayout(DataField aField) sl@75: { sl@75: return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan); sl@75: } sl@66: } sl@66: sl@66: /// 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@75: /// Set the given field on your display. sl@75: /// Fields are often just lines of text or bitmaps. sl@32: /// sl@43: /// sl@24: [OperationContract(IsOneWay = true)] sl@74: void SetField(DataField aField); sl@26: sl@32: /// sl@75: /// Allows a client to set multiple fields at once. sl@32: /// sl@75: /// sl@24: [OperationContract(IsOneWay = true)] sl@74: void SetFields(System.Collections.Generic.IList aFields); sl@67: sl@67: /// 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: }