Interface/Interface.cs
author sl
Sun, 21 Sep 2014 19:07:18 +0200
changeset 57 544132d07c3b
parent 55 b5ed2e29be23
child 62 ac698f4e1b36
permissions -rw-r--r--
Simplifying client construction.
Fixing our borders and sorting out our color issues.
Adding inverse colors options.
     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 TextField
    23     {
    24         public TextField()
    25         {
    26             Index = 0;
    27             Text = "";
    28             Alignment = ContentAlignment.MiddleLeft;
    29         }
    30 
    31         public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
    32         {
    33             Index = aIndex;
    34             Text = aText;
    35             Alignment = aAlignment;
    36         }
    37 
    38         [DataMember]
    39         public int Index { get; set; }
    40 
    41         [DataMember]
    42         public string Text { get; set; }
    43 
    44         [DataMember]
    45         public ContentAlignment Alignment { get; set; }
    46     }
    47 
    48     /// <summary>
    49     /// Define our SharpDisplay service.
    50     /// Clients and servers must implement it to communicate with one another.
    51     /// Through this service clients can send requests to a server.
    52     /// Through this service a server session can receive requests from a client.
    53     /// </summary>
    54     [ServiceContract(   CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
    55     public interface IService
    56     {
    57         /// <summary>
    58         /// Set the name of this client.
    59         /// Name is a convenient way to recognize your client.
    60         /// Naming you client is not mandatory.
    61         /// In the absence of a name the session ID is often used instead.
    62         /// </summary>
    63         /// <param name="aClientName"></param>
    64         [OperationContract(IsOneWay = true)]
    65         void SetName(string aClientName);
    66 
    67         /// <summary>
    68         /// Put the given text in the given field on your display.
    69         /// Fields are often just lines of text.
    70         /// </summary>
    71         /// <param name="aTextFieldIndex"></param>
    72         [OperationContract(IsOneWay = true)]
    73         void SetText(TextField aTextField);
    74 
    75         /// <summary>
    76         /// Allows a client to set multiple text fields at once.
    77         /// </summary>
    78         /// <param name="aTexts"></param>
    79         [OperationContract(IsOneWay = true)]
    80         void SetTexts(System.Collections.Generic.IList<TextField> aTextFields);
    81 
    82         /// <summary>
    83         /// Provides the number of clients currently connected
    84         /// </summary>
    85         /// <returns></returns>
    86         [OperationContract()]
    87         int ClientCount();
    88 
    89     }
    90 
    91     /// <summary>
    92     /// SharDisplay callback provides a means for a server to notify its clients.
    93     /// </summary>
    94     public interface ICallback
    95     {
    96         [OperationContract(IsOneWay = true)]
    97         void OnConnected();
    98 
    99         /// <summary>
   100         /// Tell our client to close its connection.
   101         /// Notably sent when the server is shutting down.
   102         /// </summary>
   103         [OperationContract(IsOneWay = true)]
   104         void OnCloseOrder();
   105     }
   106 
   107 
   108 
   109 }