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