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