Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RemoteDesktopSession.cs
1using System;
2using System.Text;
3using System.Threading.Tasks;
5using Waher.Events;
6
8{
12 public enum MouseButton
13 {
17 Left,
18
22 Middle,
23
27 Right
28 }
29
34 {
35 private readonly string sessionId;
36 private readonly string remoteJid;
37 private readonly RemoteDesktopClient client;
39 private ScreenInfo[] screens = new ScreenInfo[0];
40 private string deviceName = string.Empty;
41 private int bitsPerPixel = 0;
42 private int left = 0;
43 private int top = 0;
44 private int width = 0;
45 private int height = 0;
46 private int tileSize = 0;
47
55 {
56 this.sessionId = SessionId;
57 this.remoteJid = RemoteJid;
58 this.client = Client;
59 }
60
64 public string SessionId => this.sessionId;
65
69 public string RemoteJid => this.remoteJid;
70
74 public RemoteDesktopClient Client => this.client;
75
79 public RemoteDesktopSessionState State => this.state;
80
81 internal async Task SetState(RemoteDesktopSessionState value)
82 {
83 if (this.state != value)
84 {
85 this.state = value;
86 await this.StateChanged.Raise(this, EventArgs.Empty);
87 }
88 }
89
94
99 {
100 get => this.screens;
101 internal set => this.screens = value;
102 }
103
107 public int BitsPerPixel
108 {
109 get => this.bitsPerPixel;
110 internal set => this.bitsPerPixel = value;
111 }
112
116 public int Left
117 {
118 get => this.left;
119 internal set => this.left = value;
120 }
121
125 public int Top
126 {
127 get => this.top;
128 internal set => this.top = value;
129 }
130
134 public int Width
135 {
136 get => this.width;
137 internal set => this.width = value;
138 }
139
143 public int Height
144 {
145 get => this.height;
146 internal set => this.height = value;
147 }
148
152 public int TileSize
153 {
154 get => this.tileSize;
155 internal set => this.tileSize = value;
156 }
157
161 public string DeviceName
162 {
163 get => this.deviceName;
164 internal set => this.deviceName = value;
165 }
166
167 internal void UpdateTile(int X, int Y, string TileBase64)
168 {
169 this.TileUpdated.Raise(this, new TileEventArgs(this, X, Y, TileBase64));
170 }
171
175 public event EventHandler<TileEventArgs> TileUpdated;
176
177 internal Task ScanCompleted()
178 {
179 return this.ScanComplete.Raise(this, EventArgs.Empty);
180 }
181
186
192 public void MouseMoved(int X, int Y)
193 {
194 StringBuilder Xml = new StringBuilder();
195
196 Xml.Append("<mouseMoved xmlns='");
198 Xml.Append("' sid='");
199 Xml.Append(XML.Encode(this.sessionId));
200 Xml.Append("' x='");
201 Xml.Append(X.ToString());
202 Xml.Append("' y='");
203 Xml.Append(Y.ToString());
204 Xml.Append("'/>");
205
206 this.SendMessage(Xml.ToString());
207 }
208
209 private Task SendMessage(string Xml)
210 {
211 return this.client.E2E.SendMessage(this.client.Client, E2ETransmission.NormalIfNotE2E, QoSLevel.Unacknowledged, MessageType.Normal,
212 string.Empty, this.remoteJid, Xml, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, null, null);
213 }
214
221 public void MouseDown(int X, int Y, MouseButton Button)
222 {
223 StringBuilder Xml = new StringBuilder();
224
225 Xml.Append("<mouseDown xmlns='");
227 Xml.Append("' sid='");
228 Xml.Append(XML.Encode(this.sessionId));
229 Xml.Append("' x='");
230 Xml.Append(X.ToString());
231 Xml.Append("' y='");
232 Xml.Append(Y.ToString());
233 Xml.Append("' b='");
234 Xml.Append(Button.ToString());
235 Xml.Append("'/>");
236
237 this.SendMessage(Xml.ToString());
238 }
239
246 public void MouseUp(int X, int Y, MouseButton Button)
247 {
248 StringBuilder Xml = new StringBuilder();
249
250 Xml.Append("<mouseUp xmlns='");
252 Xml.Append("' sid='");
253 Xml.Append(XML.Encode(this.sessionId));
254 Xml.Append("' x='");
255 Xml.Append(X.ToString());
256 Xml.Append("' y='");
257 Xml.Append(Y.ToString());
258 Xml.Append("' b='");
259 Xml.Append(Button.ToString());
260 Xml.Append("'/>");
261
262 this.SendMessage(Xml.ToString());
263 }
264
271 public void MouseWheel(int X, int Y, int Delta)
272 {
273 StringBuilder Xml = new StringBuilder();
274
275 Xml.Append("<mouseWheel xmlns='");
277 Xml.Append("' sid='");
278 Xml.Append(XML.Encode(this.sessionId));
279 Xml.Append("' x='");
280 Xml.Append(X.ToString());
281 Xml.Append("' y='");
282 Xml.Append(Y.ToString());
283 Xml.Append("' d='");
284 Xml.Append(Delta.ToString());
285 Xml.Append("'/>");
286
287 this.SendMessage(Xml.ToString());
288 }
289
294 public void KeyDown(int KeyCode)
295 {
296 StringBuilder Xml = new StringBuilder();
297
298 Xml.Append("<keyDown xmlns='");
300 Xml.Append("' sid='");
301 Xml.Append(XML.Encode(this.sessionId));
302 Xml.Append("' key='");
303 Xml.Append(KeyCode.ToString());
304 Xml.Append("'/>");
305
306 this.SendMessage(Xml.ToString());
307 }
308
313 public void KeyUp(int KeyCode)
314 {
315 StringBuilder Xml = new StringBuilder();
316
317 Xml.Append("<keyUp xmlns='");
319 Xml.Append("' sid='");
320 Xml.Append(XML.Encode(this.sessionId));
321 Xml.Append("' key='");
322 Xml.Append(KeyCode.ToString());
323 Xml.Append("'/>");
324
325 this.SendMessage(Xml.ToString());
326 }
327 }
328}
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:27
const string RemoteDesktopNamespace
http://waher.se/rdp/1.0
Maintains the client-side state of a Remote Desktop Session.
RemoteDesktopSessionState State
Session state changed.
EventHandler< TileEventArgs > TileUpdated
Event raised when a tile on the remote desktop has been updated.
void KeyDown(int KeyCode)
Reports a key having been pressed.
void MouseDown(int X, int Y, MouseButton Button)
Reports the mouse having been pressed down.
EventHandlerAsync StateChanged
Event raised when state has been changed.
RemoteDesktopSession(string SessionId, string RemoteJid, RemoteDesktopClient Client)
Maintains the client-side state of a Remote Desktop Session.
void MouseUp(int X, int Y, MouseButton Button)
Reports the mouse having been released up.
RemoteDesktopClient Client
Remote Desktop Client
void MouseMoved(int X, int Y)
Reports the mouse having moved to a given position.
ScreenInfo[] Screens
Available remote screens.
EventHandlerAsync ScanComplete
Event raised when the screen has been successfully scanned and transferred.
void MouseWheel(int X, int Y, int Delta)
Reports the mouse wheel having been turned.
void KeyUp(int KeyCode)
Reports a key having been released.
Information about a remote screen.
Definition: ScreenInfo.cs:9
Event arguments for tile events.
Definition: TileEventArgs.cs:9
delegate Task EventHandlerAsync(object Sender, EventArgs e)
Asynchronous version of EventArgs.
RemoteDesktopSessionState
State of a Remote Desktop Session
MouseButton
Enumeration identifying mouse button being used.
QoSLevel
Quality of Service Level for asynchronous messages. Support for QoS Levels must be supported by the r...
Definition: QoSLevel.cs:8
MessageType
Type of message received.
Definition: MessageType.cs:7
E2ETransmission
End-to-end encryption mode.