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