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