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