Interface/Interface.cs
author sl
Mon, 13 Oct 2014 20:05:48 +0200
changeset 67 6e50baf5a811
parent 66 a02bd242f219
child 72 fd0bb39a7818
permissions -rw-r--r--
Ground work for supporting generic field and bitmap ones.
     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         }
    70 
    71         [DataMember]
    72         public int Index { get; set; }
    73 
    74         [DataMember]
    75         public int Column { get; set; }
    76 
    77         [DataMember]
    78         public int Row { get; set; }
    79 
    80         [DataMember]
    81         public int ColumnSpan { get; set; }
    82 
    83         [DataMember]
    84         public int RowSpan { get; set; }
    85 
    86     }
    87 
    88 
    89     /// <summary>
    90     /// TextField can be send to our server to be displayed on the screen.
    91     /// </summary>
    92     [DataContract]
    93     public class TextField : DataField
    94     {
    95         public TextField()
    96         {
    97             Index = 0;
    98             Text = "";
    99             Alignment = ContentAlignment.MiddleLeft;
   100         }
   101 
   102         public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
   103         {
   104             Index = aIndex;
   105             Text = aText;
   106             Alignment = aAlignment;
   107         }
   108 
   109         [DataMember]
   110         public string Text { get; set; }
   111 
   112         [DataMember]
   113         public ContentAlignment Alignment { get; set; }
   114     }
   115 
   116     /// <summary>
   117     /// TextField can be send to our server to be displayed on the screen.
   118     /// </summary>
   119     [DataContract]
   120     public class BitmapField : DataField
   121     {
   122         public BitmapField()
   123         {
   124         }
   125 
   126         public BitmapField(int aIndex, Bitmap aBitmap)
   127         {
   128             Index = aIndex;
   129             Bitmap = aBitmap;
   130         }
   131 
   132         [DataMember]
   133         public Bitmap Bitmap { get; set; }
   134     }
   135 
   136     /// <summary>
   137     /// Define our SharpDisplay service.
   138     /// Clients and servers must implement it to communicate with one another.
   139     /// Through this service clients can send requests to a server.
   140     /// Through this service a server session can receive requests from a client.
   141     /// </summary>
   142     [ServiceContract(   CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
   143     public interface IService
   144     {
   145         /// <summary>
   146         /// Set the name of this client.
   147         /// Name is a convenient way to recognize your client.
   148         /// Naming you client is not mandatory.
   149         /// In the absence of a name the session ID is often used instead.
   150         /// </summary>
   151         /// <param name="aClientName"></param>
   152         [OperationContract(IsOneWay = true)]
   153         void SetName(string aClientName);
   154 
   155         /// <summary>
   156         /// </summary>
   157         /// <param name="aLayout"></param>
   158         [OperationContract(IsOneWay = true)]
   159         void SetLayout(TableLayout aLayout);
   160 
   161         /// <summary>
   162         /// Put the given text in the given field on your display.
   163         /// Fields are often just lines of text.
   164         /// </summary>
   165         /// <param name="aTextFieldIndex"></param>
   166         [OperationContract(IsOneWay = true)]
   167         void SetText(TextField aTextField);
   168 
   169         /// <summary>
   170         /// Allows a client to set multiple text fields at once.
   171         /// </summary>
   172         /// <param name="aTexts"></param>
   173         [OperationContract(IsOneWay = true)]
   174         void SetTexts(System.Collections.Generic.IList<TextField> aTextFields);
   175 
   176         /// <summary>
   177         /// Put the given bitmap in the given field on your display.
   178         /// Fields are often just lines of text.
   179         /// </summary>
   180         /// <param name="aBitmapField"></param>
   181         [OperationContract(IsOneWay = true)]
   182         void SetBitmap(BitmapField aBitmapField);
   183 
   184         /// <summary>
   185         /// Provides the number of clients currently connected
   186         /// </summary>
   187         /// <returns></returns>
   188         [OperationContract()]
   189         int ClientCount();
   190 
   191     }
   192 
   193     /// <summary>
   194     /// SharDisplay callback provides a means for a server to notify its clients.
   195     /// </summary>
   196     public interface ICallback
   197     {
   198         [OperationContract(IsOneWay = true)]
   199         void OnConnected();
   200 
   201         /// <summary>
   202         /// Tell our client to close its connection.
   203         /// Notably sent when the server is shutting down.
   204         /// </summary>
   205         [OperationContract(IsOneWay = true)]
   206         void OnCloseOrder();
   207     }
   208 
   209 
   210 
   211 }