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