Interface/Interface.cs
author sl
Sun, 18 Jan 2015 18:32:32 +0100
changeset 95 a4a02cc952a0
parent 76 906d88eb53fb
parent 74 60d584bad780
child 138 426cc984fd18
permissions -rw-r--r--
Adding tray icon context menu.
     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     /// <summary>
    20     /// For client to specify a specific layout.
    21     /// </summary>
    22     [DataContract]
    23     public class TableLayout
    24     {
    25         public TableLayout()
    26         {
    27             Columns = new List<ColumnStyle>();
    28             Rows = new List<RowStyle>();
    29             Cells = new List<DataField>();
    30         }
    31 
    32         public TableLayout(int aColumnCount, int aRowCount)
    33         {
    34             Columns = new List<ColumnStyle>();
    35             Rows = new List<RowStyle>();
    36 
    37             for (int i = 0; i < aColumnCount; i++)
    38             {
    39                 Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount));
    40             }
    41 
    42             for (int i = 0; i < aRowCount; i++)
    43             {
    44                 Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount));
    45             }
    46         }
    47 
    48         [DataMember]
    49         public List<DataField> Cells { get; set; }
    50 
    51         [DataMember]
    52         public List<ColumnStyle> Columns { get; set; }
    53 
    54         [DataMember]
    55         public List<RowStyle> Rows { get; set; }
    56     }
    57 
    58     /// <summary>
    59     ///
    60     /// </summary>
    61     [DataContract]
    62     public class DataField
    63     {
    64         public DataField()
    65         {
    66             Index = 0;
    67             ColumnSpan = 1;
    68             RowSpan = 1;
    69             //Text
    70             Text = "";
    71             Alignment = ContentAlignment.MiddleLeft;
    72             //Bitmap
    73             Bitmap = null;
    74         }
    75 
    76         //Text constructor
    77         public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
    78         {
    79             ColumnSpan = 1;
    80             RowSpan = 1;
    81             Index = aIndex;
    82             Text = aText;
    83             Alignment = aAlignment;
    84             //
    85             Bitmap = null;
    86         }
    87 
    88         //Bitmap constructor
    89         public DataField(int aIndex, Bitmap aBitmap)
    90         {
    91             ColumnSpan = 1;
    92             RowSpan = 1;
    93             Index = aIndex;
    94             Bitmap = aBitmap;
    95             //Text
    96             Text = "";
    97             Alignment = ContentAlignment.MiddleLeft;
    98         }
    99 
   100 
   101         //Generic layout properties
   102         [DataMember]
   103         public int Index { get; set; }
   104 
   105         [DataMember]
   106         public int Column { get; set; }
   107 
   108         [DataMember]
   109         public int Row { get; set; }
   110 
   111         [DataMember]
   112         public int ColumnSpan { get; set; }
   113 
   114         [DataMember]
   115         public int RowSpan { get; set; }
   116 
   117         //Text properties
   118         [DataMember]
   119         public string Text { get; set; }
   120 
   121         [DataMember]
   122         public ContentAlignment Alignment { get; set; }
   123 
   124         //Bitmap properties
   125         [DataMember]
   126         public Bitmap Bitmap { get; set; }
   127 
   128         //
   129         public bool IsBitmap { get{ return Bitmap!=null;} }
   130         //
   131         public bool IsText { get { return Bitmap == null; } }
   132         //
   133         public bool IsSameLayout(DataField aField)
   134         {
   135             return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan);
   136         }
   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         /// Set the given field on your display.
   166         /// Fields are often just lines of text or bitmaps.
   167         /// </summary>
   168         /// <param name="aTextFieldIndex"></param>
   169         [OperationContract(IsOneWay = true)]
   170         void SetField(DataField aField);
   171 
   172         /// <summary>
   173         /// Allows a client to set multiple fields at once.
   174         /// </summary>
   175         /// <param name="aFields"></param>
   176         [OperationContract(IsOneWay = true)]
   177         void SetFields(System.Collections.Generic.IList<DataField> aFields);
   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 }