Interface/Interface.cs
author sl
Sat, 25 Oct 2014 13:35:11 +0200
changeset 72 fd0bb39a7818
parent 67 6e50baf5a811
child 74 60d584bad780
child 75 2549a8055bd1
permissions -rw-r--r--
Now having a single class for both text and bitmap field.
Thus we should soon be able to use common functions to pass in fields.
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@72
    69
            //Text
sl@72
    70
            Text = "";
sl@72
    71
            Alignment = ContentAlignment.MiddleLeft;
sl@72
    72
            //Bitmap
sl@72
    73
            Bitmap = null;
sl@66
    74
        }
sl@66
    75
sl@72
    76
        //Text constructor
sl@72
    77
        public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
sl@72
    78
        {
sl@72
    79
            ColumnSpan = 1;
sl@72
    80
            RowSpan = 1;
sl@72
    81
            Index = aIndex;
sl@72
    82
            Text = aText;
sl@72
    83
            Alignment = aAlignment;
sl@72
    84
            //
sl@72
    85
            Bitmap = null;
sl@72
    86
        }
sl@72
    87
sl@72
    88
        //Bitmap constructor
sl@72
    89
        public DataField(int aIndex, Bitmap aBitmap)
sl@72
    90
        {
sl@72
    91
            ColumnSpan = 1;
sl@72
    92
            RowSpan = 1;
sl@72
    93
            Index = aIndex;
sl@72
    94
            Bitmap = aBitmap;
sl@72
    95
            //Text
sl@72
    96
            Text = "";
sl@72
    97
            Alignment = ContentAlignment.MiddleLeft;
sl@72
    98
        }
sl@72
    99
sl@72
   100
sl@72
   101
        //Generic layout properties
sl@66
   102
        [DataMember]
sl@66
   103
        public int Index { get; set; }
sl@66
   104
sl@62
   105
        [DataMember]
sl@62
   106
        public int Column { get; set; }
sl@62
   107
sl@62
   108
        [DataMember]
sl@62
   109
        public int Row { get; set; }
sl@62
   110
sl@62
   111
        [DataMember]
sl@62
   112
        public int ColumnSpan { get; set; }
sl@62
   113
sl@62
   114
        [DataMember]
sl@62
   115
        public int RowSpan { get; set; }
sl@72
   116
        
sl@72
   117
        //Text properties
sl@43
   118
        [DataMember]
sl@43
   119
        public string Text { get; set; }
sl@43
   120
sl@43
   121
        [DataMember]
sl@43
   122
        public ContentAlignment Alignment { get; set; }
sl@43
   123
sl@72
   124
        //Bitmap properties
sl@66
   125
        [DataMember]
sl@66
   126
        public Bitmap Bitmap { get; set; }
sl@72
   127
sl@72
   128
        //
sl@72
   129
        public bool HasBitmap { get{ return Bitmap!=null;} }
sl@72
   130
sl@66
   131
    }
sl@66
   132
sl@66
   133
    /// <summary>
sl@56
   134
    /// Define our SharpDisplay service.
sl@56
   135
    /// Clients and servers must implement it to communicate with one another.
sl@56
   136
    /// Through this service clients can send requests to a server.
sl@56
   137
    /// Through this service a server session can receive requests from a client.
sl@56
   138
    /// </summary>
sl@55
   139
    [ServiceContract(   CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
sl@55
   140
    public interface IService
sl@24
   141
    {
sl@32
   142
        /// <summary>
sl@32
   143
        /// Set the name of this client.
sl@32
   144
        /// Name is a convenient way to recognize your client.
sl@32
   145
        /// Naming you client is not mandatory.
sl@32
   146
        /// In the absence of a name the session ID is often used instead.
sl@32
   147
        /// </summary>
sl@32
   148
        /// <param name="aClientName"></param>
sl@24
   149
        [OperationContract(IsOneWay = true)]
sl@32
   150
        void SetName(string aClientName);
sl@24
   151
sl@62
   152
        /// <summary>
sl@62
   153
        /// </summary>
sl@62
   154
        /// <param name="aLayout"></param>
sl@62
   155
        [OperationContract(IsOneWay = true)]
sl@62
   156
        void SetLayout(TableLayout aLayout);
sl@62
   157
sl@32
   158
        /// <summary>
sl@32
   159
        /// Put the given text in the given field on your display.
sl@32
   160
        /// Fields are often just lines of text.
sl@32
   161
        /// </summary>
sl@43
   162
        /// <param name="aTextFieldIndex"></param>
sl@24
   163
        [OperationContract(IsOneWay = true)]
sl@72
   164
        void SetText(DataField aField);
sl@26
   165
sl@32
   166
        /// <summary>
sl@32
   167
        /// Allows a client to set multiple text fields at once.
sl@32
   168
        /// </summary>
sl@32
   169
        /// <param name="aTexts"></param>
sl@24
   170
        [OperationContract(IsOneWay = true)]
sl@72
   171
        void SetTexts(System.Collections.Generic.IList<DataField> aFields);
sl@32
   172
sl@32
   173
        /// <summary>
sl@67
   174
        /// Put the given bitmap in the given field on your display.
sl@67
   175
        /// Fields are often just lines of text.
sl@67
   176
        /// </summary>
sl@67
   177
        /// <param name="aBitmapField"></param>
sl@67
   178
        [OperationContract(IsOneWay = true)]
sl@72
   179
        void SetBitmap(DataField aBitmapField);
sl@67
   180
sl@67
   181
        /// <summary>
sl@32
   182
        /// Provides the number of clients currently connected
sl@32
   183
        /// </summary>
sl@32
   184
        /// <returns></returns>
sl@32
   185
        [OperationContract()]
sl@32
   186
        int ClientCount();
sl@32
   187
sl@24
   188
    }
sl@24
   189
sl@56
   190
    /// <summary>
sl@56
   191
    /// SharDisplay callback provides a means for a server to notify its clients.
sl@56
   192
    /// </summary>
sl@55
   193
    public interface ICallback
sl@24
   194
    {
sl@24
   195
        [OperationContract(IsOneWay = true)]
sl@24
   196
        void OnConnected();
sl@24
   197
sl@32
   198
        /// <summary>
sl@32
   199
        /// Tell our client to close its connection.
sl@32
   200
        /// Notably sent when the server is shutting down.
sl@32
   201
        /// </summary>
sl@24
   202
        [OperationContract(IsOneWay = true)]
sl@32
   203
        void OnCloseOrder();
sl@24
   204
    }
sl@24
   205
sl@24
   206
sl@24
   207
sl@24
   208
}