Interface/Interface.cs
author StephaneLenclud
Sun, 21 Jun 2015 12:40:05 +0200
changeset 145 53dbdcf73f08
parent 77 042c1fa136b9
child 148 878904899ff0
permissions -rw-r--r--
Merge
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@56
    19
    /// <summary>
StephaneLenclud@64
    20
    /// For client to specify a specific layout.
StephaneLenclud@138
    21
    /// A table layout is sent from client to server and defines data fields layout on our display.
sl@56
    22
    /// </summary>
sl@43
    23
    [DataContract]
sl@62
    24
    public class TableLayout
sl@62
    25
    {
sl@62
    26
        public TableLayout()
sl@62
    27
        {
sl@63
    28
            Columns = new List<ColumnStyle>();
sl@63
    29
            Rows = new List<RowStyle>();
sl@62
    30
        }
sl@62
    31
StephaneLenclud@138
    32
        /// <summary>
StephaneLenclud@138
    33
        /// Construct our table layout.
StephaneLenclud@138
    34
        /// </summary>
StephaneLenclud@138
    35
        /// <param name="aColumnCount">Number of column in our table.</param>
StephaneLenclud@138
    36
        /// <param name="aRowCount">Number of rows in our table.</param>
sl@62
    37
        public TableLayout(int aColumnCount, int aRowCount)
sl@62
    38
        {
sl@63
    39
            Columns = new List<ColumnStyle>();
sl@63
    40
            Rows = new List<RowStyle>();
sl@63
    41
sl@63
    42
            for (int i = 0; i < aColumnCount; i++)
sl@63
    43
            {
sl@63
    44
                Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount));
sl@63
    45
            }
sl@63
    46
sl@63
    47
            for (int i = 0; i < aRowCount; i++)
sl@63
    48
            {
sl@63
    49
                Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount));
sl@63
    50
            }
sl@62
    51
        }
sl@62
    52
sl@62
    53
        [DataMember]
sl@63
    54
        public List<ColumnStyle> Columns { get; set; }
sl@62
    55
sl@62
    56
        [DataMember]
sl@63
    57
        public List<RowStyle> Rows { get; set; }
sl@62
    58
    }
sl@62
    59
sl@62
    60
    /// <summary>
StephaneLenclud@138
    61
    /// Define a data field on our display.
StephaneLenclud@138
    62
    /// Data field can be either text or bitmap.
sl@62
    63
    /// </summary>
sl@62
    64
    [DataContract]
sl@62
    65
    public class DataField
sl@62
    66
    {
sl@66
    67
        public DataField()
sl@66
    68
        {
sl@66
    69
            Index = 0;
sl@66
    70
            ColumnSpan = 1;
sl@66
    71
            RowSpan = 1;
sl@72
    72
            //Text
sl@72
    73
            Text = "";
sl@72
    74
            Alignment = ContentAlignment.MiddleLeft;
sl@72
    75
            //Bitmap
sl@72
    76
            Bitmap = null;
sl@66
    77
        }
sl@66
    78
sl@72
    79
        //Text constructor
sl@72
    80
        public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
sl@72
    81
        {
sl@72
    82
            ColumnSpan = 1;
sl@72
    83
            RowSpan = 1;
sl@72
    84
            Index = aIndex;
sl@72
    85
            Text = aText;
sl@72
    86
            Alignment = aAlignment;
sl@72
    87
            //
sl@72
    88
            Bitmap = null;
sl@72
    89
        }
sl@72
    90
sl@72
    91
        //Bitmap constructor
sl@72
    92
        public DataField(int aIndex, Bitmap aBitmap)
sl@72
    93
        {
sl@72
    94
            ColumnSpan = 1;
sl@72
    95
            RowSpan = 1;
sl@72
    96
            Index = aIndex;
sl@72
    97
            Bitmap = aBitmap;
sl@72
    98
            //Text
sl@72
    99
            Text = "";
sl@72
   100
            Alignment = ContentAlignment.MiddleLeft;
sl@72
   101
        }
sl@72
   102
sl@72
   103
sl@72
   104
        //Generic layout properties
sl@66
   105
        [DataMember]
sl@66
   106
        public int Index { get; set; }
sl@66
   107
sl@62
   108
        [DataMember]
sl@62
   109
        public int Column { get; set; }
sl@62
   110
sl@62
   111
        [DataMember]
sl@62
   112
        public int Row { get; set; }
sl@62
   113
sl@62
   114
        [DataMember]
sl@62
   115
        public int ColumnSpan { get; set; }
sl@62
   116
sl@62
   117
        [DataMember]
sl@62
   118
        public int RowSpan { get; set; }
sl@74
   119
sl@72
   120
        //Text properties
sl@43
   121
        [DataMember]
sl@43
   122
        public string Text { get; set; }
sl@43
   123
sl@43
   124
        [DataMember]
sl@43
   125
        public ContentAlignment Alignment { get; set; }
sl@43
   126
sl@72
   127
        //Bitmap properties
sl@66
   128
        [DataMember]
sl@66
   129
        public Bitmap Bitmap { get; set; }
sl@72
   130
sl@72
   131
        //
sl@75
   132
        public bool IsBitmap { get{ return Bitmap!=null;} }
sl@75
   133
        //
sl@75
   134
        public bool IsText { get { return Bitmap == null; } }
sl@75
   135
        //
sl@75
   136
        public bool IsSameLayout(DataField aField)
sl@75
   137
        {
sl@75
   138
            return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan);
sl@75
   139
        }
sl@66
   140
    }
sl@66
   141
sl@66
   142
    /// <summary>
sl@56
   143
    /// Define our SharpDisplay service.
sl@56
   144
    /// Clients and servers must implement it to communicate with one another.
sl@56
   145
    /// Through this service clients can send requests to a server.
sl@56
   146
    /// Through this service a server session can receive requests from a client.
sl@56
   147
    /// </summary>
sl@55
   148
    [ServiceContract(   CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
sl@55
   149
    public interface IService
sl@24
   150
    {
sl@32
   151
        /// <summary>
sl@32
   152
        /// Set the name of this client.
sl@32
   153
        /// Name is a convenient way to recognize your client.
sl@32
   154
        /// Naming you client is not mandatory.
sl@32
   155
        /// In the absence of a name the session ID is often used instead.
sl@32
   156
        /// </summary>
sl@32
   157
        /// <param name="aClientName"></param>
sl@24
   158
        [OperationContract(IsOneWay = true)]
sl@32
   159
        void SetName(string aClientName);
sl@24
   160
sl@62
   161
        /// <summary>
sl@62
   162
        /// </summary>
sl@62
   163
        /// <param name="aLayout"></param>
sl@62
   164
        [OperationContract(IsOneWay = true)]
sl@62
   165
        void SetLayout(TableLayout aLayout);
sl@62
   166
sl@32
   167
        /// <summary>
sl@75
   168
        /// Set the given field on your display.
sl@75
   169
        /// Fields are often just lines of text or bitmaps.
sl@32
   170
        /// </summary>
sl@43
   171
        /// <param name="aTextFieldIndex"></param>
sl@24
   172
        [OperationContract(IsOneWay = true)]
sl@74
   173
        void SetField(DataField aField);
sl@26
   174
sl@32
   175
        /// <summary>
sl@75
   176
        /// Allows a client to set multiple fields at once.
sl@32
   177
        /// </summary>
sl@75
   178
        /// <param name="aFields"></param>
sl@24
   179
        [OperationContract(IsOneWay = true)]
sl@74
   180
        void SetFields(System.Collections.Generic.IList<DataField> aFields);
sl@67
   181
sl@67
   182
        /// <summary>
sl@32
   183
        /// Provides the number of clients currently connected
sl@32
   184
        /// </summary>
sl@32
   185
        /// <returns></returns>
sl@32
   186
        [OperationContract()]
sl@32
   187
        int ClientCount();
sl@32
   188
sl@24
   189
    }
sl@24
   190
sl@56
   191
    /// <summary>
sl@56
   192
    /// SharDisplay callback provides a means for a server to notify its clients.
sl@56
   193
    /// </summary>
sl@55
   194
    public interface ICallback
sl@24
   195
    {
sl@24
   196
        [OperationContract(IsOneWay = true)]
sl@24
   197
        void OnConnected();
sl@24
   198
sl@32
   199
        /// <summary>
sl@32
   200
        /// Tell our client to close its connection.
sl@32
   201
        /// Notably sent when the server is shutting down.
sl@32
   202
        /// </summary>
sl@24
   203
        [OperationContract(IsOneWay = true)]
sl@32
   204
        void OnCloseOrder();
sl@24
   205
    }
sl@24
   206
sl@24
   207
}