Interface/Interface.cs
author sl
Fri, 03 Oct 2014 18:43:55 +0200
changeset 65 464486b81635
parent 64 ab4ff9d33c73
child 66 a02bd242f219
permissions -rw-r--r--
Adding current client concept.
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@62
    59
    }
sl@62
    60
sl@62
    61
    /// <summary>
sl@62
    62
    ///
sl@62
    63
    /// </summary>
sl@62
    64
    [DataContract]
sl@62
    65
    public class DataField
sl@62
    66
    {
sl@62
    67
        [DataMember]
sl@62
    68
        public int Column { get; set; }
sl@62
    69
sl@62
    70
        [DataMember]
sl@62
    71
        public int Row { get; set; }
sl@62
    72
sl@62
    73
        [DataMember]
sl@62
    74
        public int ColumnSpan { get; set; }
sl@62
    75
sl@62
    76
        [DataMember]
sl@62
    77
        public int RowSpan { get; set; }
sl@62
    78
sl@62
    79
    }
sl@62
    80
sl@62
    81
sl@62
    82
    /// <summary>
sl@62
    83
    /// TextField can be send to our server to be displayed on the screen.
sl@62
    84
    /// </summary>
sl@62
    85
    [DataContract]
sl@62
    86
    public class TextField : DataField
sl@43
    87
    {
sl@43
    88
        public TextField()
sl@43
    89
        {
sl@43
    90
            Index = 0;
sl@43
    91
            Text = "";
sl@43
    92
            Alignment = ContentAlignment.MiddleLeft;
sl@43
    93
        }
sl@43
    94
sl@43
    95
        public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
sl@43
    96
        {
sl@43
    97
            Index = aIndex;
sl@43
    98
            Text = aText;
sl@43
    99
            Alignment = aAlignment;
sl@43
   100
        }
sl@43
   101
sl@43
   102
        [DataMember]
sl@43
   103
        public int Index { get; set; }
sl@43
   104
sl@43
   105
        [DataMember]
sl@43
   106
        public string Text { get; set; }
sl@43
   107
sl@43
   108
        [DataMember]
sl@43
   109
        public ContentAlignment Alignment { get; set; }
sl@43
   110
    }
sl@43
   111
sl@56
   112
    /// <summary>
sl@56
   113
    /// Define our SharpDisplay service.
sl@56
   114
    /// Clients and servers must implement it to communicate with one another.
sl@56
   115
    /// Through this service clients can send requests to a server.
sl@56
   116
    /// Through this service a server session can receive requests from a client.
sl@56
   117
    /// </summary>
sl@55
   118
    [ServiceContract(   CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
sl@55
   119
    public interface IService
sl@24
   120
    {
sl@32
   121
        /// <summary>
sl@32
   122
        /// Set the name of this client.
sl@32
   123
        /// Name is a convenient way to recognize your client.
sl@32
   124
        /// Naming you client is not mandatory.
sl@32
   125
        /// In the absence of a name the session ID is often used instead.
sl@32
   126
        /// </summary>
sl@32
   127
        /// <param name="aClientName"></param>
sl@24
   128
        [OperationContract(IsOneWay = true)]
sl@32
   129
        void SetName(string aClientName);
sl@24
   130
sl@62
   131
        /// <summary>
sl@62
   132
        /// </summary>
sl@62
   133
        /// <param name="aLayout"></param>
sl@62
   134
        [OperationContract(IsOneWay = true)]
sl@62
   135
        void SetLayout(TableLayout aLayout);
sl@62
   136
sl@32
   137
        /// <summary>
sl@32
   138
        /// Put the given text in the given field on your display.
sl@32
   139
        /// Fields are often just lines of text.
sl@32
   140
        /// </summary>
sl@43
   141
        /// <param name="aTextFieldIndex"></param>
sl@24
   142
        [OperationContract(IsOneWay = true)]
sl@43
   143
        void SetText(TextField aTextField);
sl@26
   144
sl@32
   145
        /// <summary>
sl@32
   146
        /// Allows a client to set multiple text fields at once.
sl@32
   147
        /// </summary>
sl@32
   148
        /// <param name="aTexts"></param>
sl@24
   149
        [OperationContract(IsOneWay = true)]
sl@43
   150
        void SetTexts(System.Collections.Generic.IList<TextField> aTextFields);
sl@32
   151
sl@32
   152
        /// <summary>
sl@32
   153
        /// Provides the number of clients currently connected
sl@32
   154
        /// </summary>
sl@32
   155
        /// <returns></returns>
sl@32
   156
        [OperationContract()]
sl@32
   157
        int ClientCount();
sl@32
   158
sl@24
   159
    }
sl@24
   160
sl@56
   161
    /// <summary>
sl@56
   162
    /// SharDisplay callback provides a means for a server to notify its clients.
sl@56
   163
    /// </summary>
sl@55
   164
    public interface ICallback
sl@24
   165
    {
sl@24
   166
        [OperationContract(IsOneWay = true)]
sl@24
   167
        void OnConnected();
sl@24
   168
sl@32
   169
        /// <summary>
sl@32
   170
        /// Tell our client to close its connection.
sl@32
   171
        /// Notably sent when the server is shutting down.
sl@32
   172
        /// </summary>
sl@24
   173
        [OperationContract(IsOneWay = true)]
sl@32
   174
        void OnCloseOrder();
sl@24
   175
    }
sl@24
   176
sl@24
   177
sl@24
   178
sl@24
   179
}