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