StephaneLenclud@445: /* StephaneLenclud@445: StephaneLenclud@445: This Source Code Form is subject to the terms of the Mozilla Public StephaneLenclud@445: License, v. 2.0. If a copy of the MPL was not distributed with this StephaneLenclud@445: file, You can obtain one at http://mozilla.org/MPL/2.0/. StephaneLenclud@445: StephaneLenclud@445: Copyright (C) 2009-2012 Michael Möller StephaneLenclud@445: StephaneLenclud@445: */ StephaneLenclud@445: StephaneLenclud@445: using System; StephaneLenclud@445: using System.Collections.Generic; StephaneLenclud@445: using System.Drawing; StephaneLenclud@445: using System.Text; StephaneLenclud@445: using System.Diagnostics; StephaneLenclud@445: using System.Windows.Forms; StephaneLenclud@445: using System.Windows; StephaneLenclud@445: using OpenHardwareMonitor.Hardware; StephaneLenclud@445: using OpenHardwareMonitor.Utilities; StephaneLenclud@445: using System.Runtime.InteropServices; StephaneLenclud@445: using UacHelpers; StephaneLenclud@445: // StephaneLenclud@445: using System.ServiceModel; StephaneLenclud@445: using System.Runtime.Serialization; StephaneLenclud@445: using SharpDisplay; StephaneLenclud@445: StephaneLenclud@445: namespace SharpDisplay StephaneLenclud@445: { StephaneLenclud@445: //That contract need to be in the same namespace than the original assembly StephaneLenclud@445: //otherwise our parameter won't make to the server. StephaneLenclud@445: //See: http://stackoverflow.com/questions/14956377/passing-an-object-using-datacontract-in-wcf/25455292#25455292 StephaneLenclud@445: [DataContract] StephaneLenclud@445: public class TextField StephaneLenclud@445: { StephaneLenclud@445: public TextField() StephaneLenclud@445: { StephaneLenclud@445: Index = 0; StephaneLenclud@445: Text = ""; StephaneLenclud@445: Alignment = ContentAlignment.MiddleLeft; StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) StephaneLenclud@445: { StephaneLenclud@445: Index = aIndex; StephaneLenclud@445: Text = aText; StephaneLenclud@445: Alignment = aAlignment; StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: [DataMember] StephaneLenclud@445: public int Index { get; set; } StephaneLenclud@445: StephaneLenclud@445: [DataMember] StephaneLenclud@445: public string Text { get; set; } StephaneLenclud@445: StephaneLenclud@445: [DataMember] StephaneLenclud@445: public ContentAlignment Alignment { get; set; } StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: StephaneLenclud@445: [ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)] StephaneLenclud@445: public interface IService StephaneLenclud@445: { StephaneLenclud@445: /// StephaneLenclud@445: /// Set the name of this client. StephaneLenclud@445: /// Name is a convenient way to recognize your client. StephaneLenclud@445: /// Naming you client is not mandatory. StephaneLenclud@445: /// In the absence of a name the session ID is often used instead. StephaneLenclud@445: /// StephaneLenclud@445: /// StephaneLenclud@445: [OperationContract(IsOneWay = true)] StephaneLenclud@445: void SetName(string aClientName); StephaneLenclud@445: StephaneLenclud@445: /// StephaneLenclud@445: /// Put the given text in the given field on your display. StephaneLenclud@445: /// Fields are often just lines of text. StephaneLenclud@445: /// StephaneLenclud@445: /// StephaneLenclud@445: [OperationContract(IsOneWay = true)] StephaneLenclud@445: void SetText(TextField aTextField); StephaneLenclud@445: StephaneLenclud@445: /// StephaneLenclud@445: /// Allows a client to set multiple text fields at once. StephaneLenclud@445: /// StephaneLenclud@445: /// StephaneLenclud@445: [OperationContract(IsOneWay = true)] StephaneLenclud@445: void SetTexts(System.Collections.Generic.IList aTextFields); StephaneLenclud@445: StephaneLenclud@445: /// StephaneLenclud@445: /// Provides the number of clients currently connected StephaneLenclud@445: /// StephaneLenclud@445: /// StephaneLenclud@445: [OperationContract()] StephaneLenclud@445: int ClientCount(); StephaneLenclud@445: StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: StephaneLenclud@445: public interface ICallback StephaneLenclud@445: { StephaneLenclud@445: [OperationContract(IsOneWay = true)] StephaneLenclud@445: void OnConnected(); StephaneLenclud@445: StephaneLenclud@445: /// StephaneLenclud@445: /// Tell our client to close its connection. StephaneLenclud@445: /// Notably sent when the server is shutting down. StephaneLenclud@445: /// StephaneLenclud@445: [OperationContract(IsOneWay = true)] StephaneLenclud@445: void OnCloseOrder(); StephaneLenclud@445: } StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: StephaneLenclud@445: StephaneLenclud@445: namespace SharpDisplay StephaneLenclud@445: { StephaneLenclud@445: StephaneLenclud@445: /// StephaneLenclud@445: /// StephaneLenclud@445: /// StephaneLenclud@445: [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] StephaneLenclud@445: public class Client : DuplexClientBase StephaneLenclud@445: { StephaneLenclud@445: public string Name { get; set; } StephaneLenclud@445: public string SessionId { get { return InnerChannel.SessionId; } } StephaneLenclud@445: StephaneLenclud@445: public Client(ICallback aCallback) StephaneLenclud@445: : base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService")) StephaneLenclud@445: { } StephaneLenclud@445: StephaneLenclud@445: public void SetName(string aClientName) StephaneLenclud@445: { StephaneLenclud@445: Name = aClientName; StephaneLenclud@445: Channel.SetName(aClientName); StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: public void SetText(TextField aTextField) StephaneLenclud@445: { StephaneLenclud@445: Channel.SetText(aTextField); StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: public void SetTexts(System.Collections.Generic.IList aTextFields) StephaneLenclud@445: { StephaneLenclud@445: Channel.SetTexts(aTextFields); StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: public int ClientCount() StephaneLenclud@445: { StephaneLenclud@445: return Channel.ClientCount(); StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: public bool IsReady() StephaneLenclud@445: { StephaneLenclud@445: return State == CommunicationState.Opened; StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: } StephaneLenclud@445: StephaneLenclud@445: StephaneLenclud@445: }