Skip to content

Commit dd11d72

Browse files
committed
feat(cli): Add test commands for RDM messages
1 parent 71b8822 commit dd11d72

File tree

1 file changed

+127
-10
lines changed

1 file changed

+127
-10
lines changed

dotnet/Devolutions.NowClient.Cli/Program.cs

Lines changed: 127 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,22 @@ static async Task<int> Main(params string[] args)
4545

4646
Console.WriteLine($"Negotiated NowProto client version: {client.Capabilities.Version}");
4747

48+
// Set up RDM notification callback
49+
await client.SetRdmAppNotifyHandler((appState, reasonCode, notifyData) =>
50+
{
51+
Console.WriteLine($"[RDM NOTIFICATION] State: {appState}, Reason: {reasonCode}, Data: {notifyData}");
52+
});
53+
4854

4955
bool repeat;
5056
do
5157
{
5258
repeat = true;
5359

54-
Console.Write("Operation (msg/run/pwsh/logoff/lock/rdm-run/rdm-version/exit): ");
55-
var operation = Console.ReadLine()?.Trim().ToLowerInvariant() ?? string.Empty;
60+
Console.Write("Operation (msg/run/pwsh/logoff/lock/rdm-version/rdm-run/rdm-action/help/exit): ");
61+
var operation = Console.ReadLine()?.Trim() ?? string.Empty;
5662

57-
switch (operation)
63+
switch (operation.ToLowerInvariant())
5864
{
5965
case "run":
6066
Console.Write("ShellExecute command: ");
@@ -104,18 +110,25 @@ static async Task<int> Main(params string[] args)
104110
await client.SessionLock();
105111
Console.WriteLine("OK");
106112
break;
107-
case "rdm-run":
108-
await ExecuteRdmRunCommand(client);
109-
break;
110113
case "rdm-version":
111114
await ExecuteRdmVersionCommand(client);
112115
break;
116+
case var cmd when cmd.StartsWith("rdm-run"):
117+
await ExecuteRdmRunCommand(client, operation);
118+
break;
119+
case var cmd when cmd.StartsWith("rdm-action"):
120+
await ExecuteRdmActionCommand(client, operation);
121+
break;
113122
case "exit":
114123
Console.WriteLine("Exiting...");
115124
repeat = false;
116125
break;
126+
case "help":
127+
case "?":
128+
ShowHelp();
129+
break;
117130
default:
118-
Console.WriteLine("Unknown command.");
131+
Console.WriteLine("Unknown command. Type 'help' for available commands.");
119132
break;
120133
}
121134
} while (repeat);
@@ -253,8 +266,9 @@ private static async Task ExecutePowerShellCommand(NowClient client, string comm
253266

254267
/// <summary>
255268
/// Executes the RDM run command - starts an RDM application.
269+
/// Syntax: rdm-run <FLAGS> where FLAGS is letters F,M or J. F - fullscreen, M - maximized, J - jump mode.
256270
/// </summary>
257-
private static async Task ExecuteRdmRunCommand(NowClient client)
271+
private static async Task ExecuteRdmRunCommand(NowClient client, string commandLine)
258272
{
259273
try
260274
{
@@ -267,9 +281,33 @@ private static async Task ExecuteRdmRunCommand(NowClient client)
267281
return;
268282
}
269283

284+
// Parse flags from command line
285+
var parts = commandLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);
286+
var flags = NowRdmLaunchFlags.None;
287+
288+
if (parts.Length > 1)
289+
{
290+
var flagString = parts[1].ToUpperInvariant();
291+
if (flagString.Contains('F'))
292+
flags |= NowRdmLaunchFlags.Fullscreen;
293+
if (flagString.Contains('M'))
294+
flags |= NowRdmLaunchFlags.Maximized;
295+
if (flagString.Contains('J'))
296+
flags |= NowRdmLaunchFlags.JumpMode;
297+
298+
Console.WriteLine($"Using launch flags: {flags}");
299+
}
300+
else
301+
{
302+
Console.WriteLine("No flags specified, using default launch mode.");
303+
}
304+
270305
// Start RDM application
271306
Console.WriteLine("Starting RDM application...");
272-
var startParams = new RdmStartParams();
307+
var startParams = new RdmStartParams
308+
{
309+
LaunchFlags = flags
310+
};
273311

274312
await client.RdmStart(startParams);
275313
Console.WriteLine("RDM application started successfully.");
@@ -281,12 +319,18 @@ private static async Task ExecuteRdmRunCommand(NowClient client)
281319
}
282320

283321
/// <summary>
284-
/// Executes the RDM version command - displays RDM version information.
322+
/// Executes the RDM version command - syncs/negotiates RDM and displays version information.
285323
/// </summary>
286324
private static async Task ExecuteRdmVersionCommand(NowClient client)
287325
{
288326
try
289327
{
328+
Console.WriteLine("Performing RDM capabilities negotiation...");
329+
330+
// Perform RDM sync/negotiation
331+
await client.RdmSync();
332+
Console.WriteLine("RDM capabilities negotiated successfully.");
333+
290334
// Check if RDM is available
291335
var isAvailable = await client.IsRdmAppAvailable();
292336
if (!isAvailable)
@@ -317,4 +361,77 @@ private static async Task ExecuteRdmVersionCommand(NowClient client)
317361
Console.Error.WriteLine($"Error executing RDM version command: {ex.Message}");
318362
}
319363
}
364+
365+
/// <summary>
366+
/// Executes the RDM action command.
367+
/// Syntax: rdm-action <CLOSE|FOCUS> (case insensitive)
368+
/// </summary>
369+
private static async Task ExecuteRdmActionCommand(NowClient client, string commandLine)
370+
{
371+
try
372+
{
373+
// Parse action from command line
374+
var parts = commandLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);
375+
if (parts.Length < 2)
376+
{
377+
Console.WriteLine("Usage: rdm-action <CLOSE|FOCUS>");
378+
return;
379+
}
380+
381+
var actionString = parts[1].ToUpperInvariant();
382+
NowRdmAppAction action;
383+
384+
switch (actionString)
385+
{
386+
case "CLOSE":
387+
action = NowRdmAppAction.Close;
388+
break;
389+
case "FOCUS":
390+
// Focus is typically implemented as Restore action in RDM
391+
action = NowRdmAppAction.Restore;
392+
break;
393+
default:
394+
Console.WriteLine($"Unknown action: {parts[1]}. Valid actions are: CLOSE, FOCUS");
395+
return;
396+
}
397+
398+
Console.WriteLine($"Executing RDM action: {actionString}");
399+
await client.RdmAction(action);
400+
Console.WriteLine("RDM action executed successfully.");
401+
}
402+
catch (Exception ex)
403+
{
404+
Console.Error.WriteLine($"Error executing RDM action command: {ex.Message}");
405+
}
406+
}
407+
408+
/// <summary>
409+
/// Shows help information for available commands.
410+
/// </summary>
411+
private static void ShowHelp()
412+
{
413+
Console.WriteLine();
414+
Console.WriteLine("Available Commands:");
415+
Console.WriteLine("==================");
416+
Console.WriteLine("msg - Send a message box to the remote desktop");
417+
Console.WriteLine("run - Execute a shell command on the remote desktop");
418+
Console.WriteLine("pwsh - Execute a PowerShell command with IO redirection");
419+
Console.WriteLine("logoff - Log off the current session");
420+
Console.WriteLine("lock - Lock the remote desktop session");
421+
Console.WriteLine();
422+
Console.WriteLine("RDM Commands:");
423+
Console.WriteLine("-------------");
424+
Console.WriteLine("rdm-version - Sync/negotiate RDM capabilities and show version");
425+
Console.WriteLine("rdm-run [FLAGS] - Start RDM application with optional flags");
426+
Console.WriteLine(" FLAGS: F=Fullscreen, M=Maximized, J=JumpMode");
427+
Console.WriteLine(" Example: 'rdm-run FM' (fullscreen + maximized)");
428+
Console.WriteLine("rdm-action <ACTION> - Send action to RDM application");
429+
Console.WriteLine(" ACTION: CLOSE or FOCUS (case insensitive)");
430+
Console.WriteLine();
431+
Console.WriteLine("Other:");
432+
Console.WriteLine("-------");
433+
Console.WriteLine("help, ? - Show this help information");
434+
Console.WriteLine("exit - Exit the CLI application");
435+
Console.WriteLine();
436+
}
320437
}

0 commit comments

Comments
 (0)