Support for SharDisplayManager.
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
29 //That contract need to be in the same namespace than the original assembly
30 //otherwise our parameter won't make to the server.
31 //See: http://stackoverflow.com/questions/14956377/passing-an-object-using-datacontract-in-wcf/25455292#25455292
33 public class TextField
39 Alignment = ContentAlignment.MiddleLeft;
42 public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
46 Alignment = aAlignment;
50 public int Index { get; set; }
53 public string Text { get; set; }
56 public ContentAlignment Alignment { get; set; }
60 [ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
61 public interface IService
64 /// Set the name of this client.
65 /// Name is a convenient way to recognize your client.
66 /// Naming you client is not mandatory.
67 /// In the absence of a name the session ID is often used instead.
69 /// <param name="aClientName"></param>
70 [OperationContract(IsOneWay = true)]
71 void SetName(string aClientName);
74 /// Put the given text in the given field on your display.
75 /// Fields are often just lines of text.
77 /// <param name="aTextFieldIndex"></param>
78 [OperationContract(IsOneWay = true)]
79 void SetText(TextField aTextField);
82 /// Allows a client to set multiple text fields at once.
84 /// <param name="aTexts"></param>
85 [OperationContract(IsOneWay = true)]
86 void SetTexts(System.Collections.Generic.IList<TextField> aTextFields);
89 /// Provides the number of clients currently connected
91 /// <returns></returns>
98 public interface ICallback
100 [OperationContract(IsOneWay = true)]
104 /// Tell our client to close its connection.
105 /// Notably sent when the server is shutting down.
107 [OperationContract(IsOneWay = true)]
114 namespace SharpDisplay
120 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
121 public class Client : DuplexClientBase<IService>
123 public string Name { get; set; }
124 public string SessionId { get { return InnerChannel.SessionId; } }
126 public Client(ICallback aCallback)
127 : base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
130 public void SetName(string aClientName)
133 Channel.SetName(aClientName);
136 public void SetText(TextField aTextField)
138 Channel.SetText(aTextField);
141 public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
143 Channel.SetTexts(aTextFields);
146 public int ClientCount()
148 return Channel.ClientCount();
151 public bool IsReady()
153 return State == CommunicationState.Opened;