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