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