author | sl |
Sun, 21 Sep 2014 21:55:36 +0200 | |
changeset 403 | 1d10b3a8a235 |
child 404 | 7b7fad708159 |
permissions | -rw-r--r-- |
sl@403 | 1 |
/* |
sl@403 | 2 |
|
sl@403 | 3 |
This Source Code Form is subject to the terms of the Mozilla Public |
sl@403 | 4 |
License, v. 2.0. If a copy of the MPL was not distributed with this |
sl@403 | 5 |
file, You can obtain one at http://mozilla.org/MPL/2.0/. |
sl@403 | 6 |
|
sl@403 | 7 |
Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org> |
sl@403 | 8 |
|
sl@403 | 9 |
*/ |
sl@403 | 10 |
|
sl@403 | 11 |
using System; |
sl@403 | 12 |
using System.Collections.Generic; |
sl@403 | 13 |
using System.Drawing; |
sl@403 | 14 |
using System.Text; |
sl@403 | 15 |
using System.Diagnostics; |
sl@403 | 16 |
using System.Windows.Forms; |
sl@403 | 17 |
using System.Windows; |
sl@403 | 18 |
using OpenHardwareMonitor.Hardware; |
sl@403 | 19 |
using OpenHardwareMonitor.Utilities; |
sl@403 | 20 |
using System.Runtime.InteropServices; |
sl@403 | 21 |
using UacHelpers; |
sl@403 | 22 |
// |
sl@403 | 23 |
using System.ServiceModel; |
sl@403 | 24 |
using System.Runtime.Serialization; |
sl@403 | 25 |
using SharpDisplay; |
sl@403 | 26 |
|
sl@403 | 27 |
namespace SharpDisplay |
sl@403 | 28 |
{ |
sl@403 | 29 |
//That contract need to be in the same namespace than the original assembly |
sl@403 | 30 |
//otherwise our parameter won't make to the server. |
sl@403 | 31 |
//See: http://stackoverflow.com/questions/14956377/passing-an-object-using-datacontract-in-wcf/25455292#25455292 |
sl@403 | 32 |
[DataContract] |
sl@403 | 33 |
public class TextField |
sl@403 | 34 |
{ |
sl@403 | 35 |
public TextField() |
sl@403 | 36 |
{ |
sl@403 | 37 |
Index = 0; |
sl@403 | 38 |
Text = ""; |
sl@403 | 39 |
Alignment = ContentAlignment.MiddleLeft; |
sl@403 | 40 |
} |
sl@403 | 41 |
|
sl@403 | 42 |
public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) |
sl@403 | 43 |
{ |
sl@403 | 44 |
Index = aIndex; |
sl@403 | 45 |
Text = aText; |
sl@403 | 46 |
Alignment = aAlignment; |
sl@403 | 47 |
} |
sl@403 | 48 |
|
sl@403 | 49 |
[DataMember] |
sl@403 | 50 |
public int Index { get; set; } |
sl@403 | 51 |
|
sl@403 | 52 |
[DataMember] |
sl@403 | 53 |
public string Text { get; set; } |
sl@403 | 54 |
|
sl@403 | 55 |
[DataMember] |
sl@403 | 56 |
public ContentAlignment Alignment { get; set; } |
sl@403 | 57 |
} |
sl@403 | 58 |
|
sl@403 | 59 |
|
sl@403 | 60 |
[ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)] |
sl@403 | 61 |
public interface IService |
sl@403 | 62 |
{ |
sl@403 | 63 |
/// <summary> |
sl@403 | 64 |
/// Set the name of this client. |
sl@403 | 65 |
/// Name is a convenient way to recognize your client. |
sl@403 | 66 |
/// Naming you client is not mandatory. |
sl@403 | 67 |
/// In the absence of a name the session ID is often used instead. |
sl@403 | 68 |
/// </summary> |
sl@403 | 69 |
/// <param name="aClientName"></param> |
sl@403 | 70 |
[OperationContract(IsOneWay = true)] |
sl@403 | 71 |
void SetName(string aClientName); |
sl@403 | 72 |
|
sl@403 | 73 |
/// <summary> |
sl@403 | 74 |
/// Put the given text in the given field on your display. |
sl@403 | 75 |
/// Fields are often just lines of text. |
sl@403 | 76 |
/// </summary> |
sl@403 | 77 |
/// <param name="aTextFieldIndex"></param> |
sl@403 | 78 |
[OperationContract(IsOneWay = true)] |
sl@403 | 79 |
void SetText(TextField aTextField); |
sl@403 | 80 |
|
sl@403 | 81 |
/// <summary> |
sl@403 | 82 |
/// Allows a client to set multiple text fields at once. |
sl@403 | 83 |
/// </summary> |
sl@403 | 84 |
/// <param name="aTexts"></param> |
sl@403 | 85 |
[OperationContract(IsOneWay = true)] |
sl@403 | 86 |
void SetTexts(System.Collections.Generic.IList<TextField> aTextFields); |
sl@403 | 87 |
|
sl@403 | 88 |
/// <summary> |
sl@403 | 89 |
/// Provides the number of clients currently connected |
sl@403 | 90 |
/// </summary> |
sl@403 | 91 |
/// <returns></returns> |
sl@403 | 92 |
[OperationContract()] |
sl@403 | 93 |
int ClientCount(); |
sl@403 | 94 |
|
sl@403 | 95 |
} |
sl@403 | 96 |
|
sl@403 | 97 |
|
sl@403 | 98 |
public interface ICallback |
sl@403 | 99 |
{ |
sl@403 | 100 |
[OperationContract(IsOneWay = true)] |
sl@403 | 101 |
void OnConnected(); |
sl@403 | 102 |
|
sl@403 | 103 |
/// <summary> |
sl@403 | 104 |
/// Tell our client to close its connection. |
sl@403 | 105 |
/// Notably sent when the server is shutting down. |
sl@403 | 106 |
/// </summary> |
sl@403 | 107 |
[OperationContract(IsOneWay = true)] |
sl@403 | 108 |
void OnCloseOrder(); |
sl@403 | 109 |
} |
sl@403 | 110 |
} |
sl@403 | 111 |
|
sl@403 | 112 |
|
sl@403 | 113 |
|
sl@403 | 114 |
namespace SharpDisplay |
sl@403 | 115 |
{ |
sl@403 | 116 |
|
sl@403 | 117 |
/// <summary> |
sl@403 | 118 |
/// |
sl@403 | 119 |
/// </summary> |
sl@403 | 120 |
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] |
sl@403 | 121 |
public class Client : DuplexClientBase<IService> |
sl@403 | 122 |
{ |
sl@403 | 123 |
public string Name { get; set; } |
sl@403 | 124 |
public string SessionId { get { return InnerChannel.SessionId; } } |
sl@403 | 125 |
|
sl@403 | 126 |
public Client(ICallback aCallback) |
sl@403 | 127 |
: base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService")) |
sl@403 | 128 |
{ } |
sl@403 | 129 |
|
sl@403 | 130 |
public void SetName(string aClientName) |
sl@403 | 131 |
{ |
sl@403 | 132 |
Name = aClientName; |
sl@403 | 133 |
Channel.SetName(aClientName); |
sl@403 | 134 |
} |
sl@403 | 135 |
|
sl@403 | 136 |
public void SetText(TextField aTextField) |
sl@403 | 137 |
{ |
sl@403 | 138 |
Channel.SetText(aTextField); |
sl@403 | 139 |
} |
sl@403 | 140 |
|
sl@403 | 141 |
public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields) |
sl@403 | 142 |
{ |
sl@403 | 143 |
Channel.SetTexts(aTextFields); |
sl@403 | 144 |
} |
sl@403 | 145 |
|
sl@403 | 146 |
public int ClientCount() |
sl@403 | 147 |
{ |
sl@403 | 148 |
return Channel.ClientCount(); |
sl@403 | 149 |
} |
sl@403 | 150 |
|
sl@403 | 151 |
public bool IsReady() |
sl@403 | 152 |
{ |
sl@403 | 153 |
return State == CommunicationState.Opened; |
sl@403 | 154 |
} |
sl@403 | 155 |
|
sl@403 | 156 |
} |
sl@403 | 157 |
|
sl@403 | 158 |
|
sl@403 | 159 |
} |