Quick and dirty usage of our new SharpDisplay layout for packed mode.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Collections.Generic;
15 using System.Diagnostics;
16 using System.Windows.Forms;
18 using OpenHardwareMonitor.Hardware;
19 using OpenHardwareMonitor.Utilities;
20 using System.Runtime.InteropServices;
23 using System.ServiceModel;
24 using System.Runtime.Serialization;
27 namespace SharpDisplay
33 /// For client to specify a specific layout.
36 public class TableLayout
40 Columns = new List<ColumnStyle>();
41 Rows = new List<RowStyle>();
42 Cells = new List<DataField>();
45 public TableLayout(int aColumnCount, int aRowCount)
47 Columns = new List<ColumnStyle>();
48 Rows = new List<RowStyle>();
50 for (int i = 0; i < aColumnCount; i++)
52 Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount));
55 for (int i = 0; i < aRowCount; i++)
57 Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount));
62 public List<DataField> Cells { get; set; }
65 public List<ColumnStyle> Columns { get; set; }
68 public List<RowStyle> Rows { get; set; }
76 public class DataField
79 public int Column { get; set; }
82 public int Row { get; set; }
85 public int ColumnSpan { get; set; }
88 public int RowSpan { get; set; }
94 /// TextField can be send to our server to be displayed on the screen.
97 public class TextField : DataField
103 Alignment = ContentAlignment.MiddleLeft;
106 public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
110 Alignment = aAlignment;
114 public int Index { get; set; }
117 public string Text { get; set; }
120 public ContentAlignment Alignment { get; set; }
124 /// Define our SharpDisplay service.
125 /// Clients and servers must implement it to communicate with one another.
126 /// Through this service clients can send requests to a server.
127 /// Through this service a server session can receive requests from a client.
129 [ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
130 public interface IService
133 /// Set the name of this client.
134 /// Name is a convenient way to recognize your client.
135 /// Naming you client is not mandatory.
136 /// In the absence of a name the session ID is often used instead.
138 /// <param name="aClientName"></param>
139 [OperationContract(IsOneWay = true)]
140 void SetName(string aClientName);
145 /// <param name="aLayout"></param>
146 [OperationContract(IsOneWay = true)]
147 void SetLayout(TableLayout aLayout);
150 /// Put the given text in the given field on your display.
151 /// Fields are often just lines of text.
153 /// <param name="aTextFieldIndex"></param>
154 [OperationContract(IsOneWay = true)]
155 void SetText(TextField aTextField);
158 /// Allows a client to set multiple text fields at once.
160 /// <param name="aTexts"></param>
161 [OperationContract(IsOneWay = true)]
162 void SetTexts(System.Collections.Generic.IList<TextField> aTextFields);
165 /// Provides the number of clients currently connected
167 /// <returns></returns>
168 [OperationContract()]
174 /// SharDisplay callback provides a means for a server to notify its clients.
176 public interface ICallback
178 [OperationContract(IsOneWay = true)]
182 /// Tell our client to close its connection.
183 /// Notably sent when the server is shutting down.
185 [OperationContract(IsOneWay = true)]
195 namespace SharpDisplay
201 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
202 public class Client : DuplexClientBase<IService>
204 public string Name { get; set; }
205 public string SessionId { get { return InnerChannel.SessionId; } }
207 public Client(ICallback aCallback)
208 : base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
211 public void SetName(string aClientName)
214 Channel.SetName(aClientName);
217 public void SetLayout(TableLayout aLayout)
219 Channel.SetLayout(aLayout);
222 public void SetText(TextField aTextField)
224 Channel.SetText(aTextField);
227 public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
229 Channel.SetTexts(aTextFields);
232 public int ClientCount()
234 return Channel.ClientCount();
237 public bool IsReady()
239 return State == CommunicationState.Opened;