in src/Azure.IIoT.OpcUa.Publisher.Service.Sdk/cli/Program.cs [69:450]
public async Task RunAsync(string[] args)
{
var interactive = false;
do
{
if (interactive)
{
Console.Write("> ");
args = CliOptions.ParseAsCommandLine(Console.ReadLine());
}
try
{
if (args.Length < 1)
{
throw new ArgumentException("Need a command!");
}
CliOptions options;
var command = args[0].ToLowerInvariant();
switch (command)
{
case "exit":
interactive = false;
break;
case "console":
Console.WriteLine(@"
___ _ _ _ _ ___ _____
|_ _| _ __ __| | _ _ ___ | |_ _ __ (_) __ _ | | |_ _| ___ |_ _|
| | | '_ \ / _` | | | | | / __| | __| | '__| | | / _` | | | _____ | | / _ \ | |
| | | | | | | (_| | | |_| | \__ \ | |_ | | | | | (_| | | | |_____| | | | (_) | | |
|___| |_| |_| \__,_| \__,_| |___/ \__| |_| |_| \__,_| |_| |___| \___/ |_|
");
interactive = true;
break;
case "status":
options = new CliOptions(args);
await GetStatusAsync().ConfigureAwait(false);
break;
case "monitor":
options = new CliOptions(args);
await MonitorAllAsync().ConfigureAwait(false);
break;
case "apps":
if (args.Length < 2)
{
throw new ArgumentException("Need a command!");
}
command = args[1].ToLowerInvariant();
options = new CliOptions(args, 2);
switch (command)
{
case "sites":
await ListSitesAsync(options).ConfigureAwait(false);
break;
case "register":
await RegisterApplicationAsync(options).ConfigureAwait(false);
break;
case "add":
await RegisterServerAsync(options).ConfigureAwait(false);
break;
case "discover":
await DiscoverServersAsync(options).ConfigureAwait(false);
break;
case "cancel":
await CancelDiscoveryAsync(options).ConfigureAwait(false);
break;
case "update":
await UpdateApplicationAsync(options).ConfigureAwait(false);
break;
case "disable":
await DisableApplicationAsync(options).ConfigureAwait(false);
break;
case "enable":
await EnableApplicationAsync(options).ConfigureAwait(false);
break;
case "remove":
case "unregister":
await UnregisterApplicationAsync(options).ConfigureAwait(false);
break;
case "purge":
await PurgeDisabledApplicationsAsync(options).ConfigureAwait(false);
break;
case "list":
await ListApplicationsAsync(options).ConfigureAwait(false);
break;
case "monitor":
await MonitorApplicationsAsync().ConfigureAwait(false);
break;
case "select":
await SelectApplicationAsync(options).ConfigureAwait(false);
break;
case "query":
await QueryApplicationsAsync(options).ConfigureAwait(false);
break;
case "get":
await GetApplicationAsync(options).ConfigureAwait(false);
break;
case "-?":
case "-h":
case "--help":
case "help":
PrintApplicationsHelp();
break;
default:
throw new ArgumentException($"Unknown command {command}.");
}
break;
case "endpoints":
if (args.Length < 2)
{
throw new ArgumentException("Need a command!");
}
command = args[1].ToLowerInvariant();
options = new CliOptions(args, 2);
switch (command)
{
case "get":
await GetEndpointAsync(options).ConfigureAwait(false);
break;
case "add":
await RegisterEndpointAsync(options).ConfigureAwait(false);
break;
case "list":
await ListEndpointsAsync(options).ConfigureAwait(false);
break;
case "monitor":
await MonitorEndpointsAsync().ConfigureAwait(false);
break;
case "select":
await SelectEndpointsAsync(options).ConfigureAwait(false);
break;
case "query":
await QueryEndpointsAsync(options).ConfigureAwait(false);
break;
case "info":
await GetServerCapablitiesAsync(options).ConfigureAwait(false);
break;
case "validate":
await GetEndpointCertificateAsync(options).ConfigureAwait(false);
break;
case "-?":
case "-h":
case "--help":
case "help":
PrintEndpointsHelp();
break;
default:
throw new ArgumentException($"Unknown command {command}.");
}
break;
case "discoverers":
if (args.Length < 2)
{
throw new ArgumentException("Need a command!");
}
command = args[1].ToLowerInvariant();
options = new CliOptions(args, 2);
switch (command)
{
case "get":
await GetDiscovererAsync(options).ConfigureAwait(false);
break;
case "update":
await UpdateDiscovererAsync(options).ConfigureAwait(false);
break;
case "monitor":
await MonitorDiscoverersAsync(options).ConfigureAwait(false);
break;
case "list":
await ListDiscoverersAsync(options).ConfigureAwait(false);
break;
case "select":
await SelectDiscovererAsync(options).ConfigureAwait(false);
break;
case "query":
await QueryDiscoverersAsync(options).ConfigureAwait(false);
break;
case "-?":
case "-h":
case "--help":
case "help":
PrintDiscoverersHelp();
break;
default:
throw new ArgumentException($"Unknown command {command}.");
}
break;
case "supervisors":
if (args.Length < 2)
{
throw new ArgumentException("Need a command!");
}
command = args[1].ToLowerInvariant();
options = new CliOptions(args, 2);
switch (command)
{
case "get":
await GetSupervisorAsync(options).ConfigureAwait(false);
break;
case "update":
await UpdateSupervisorAsync(options).ConfigureAwait(false);
break;
case "monitor":
await MonitorSupervisorsAsync().ConfigureAwait(false);
break;
case "list":
await ListSupervisorsAsync(options).ConfigureAwait(false);
break;
case "select":
await SelectSupervisorAsync(options).ConfigureAwait(false);
break;
case "query":
await QuerySupervisorsAsync(options).ConfigureAwait(false);
break;
case "-?":
case "-h":
case "--help":
case "help":
PrintSupervisorsHelp();
break;
default:
throw new ArgumentException($"Unknown command {command}.");
}
break;
case "publishers":
if (args.Length < 2)
{
throw new ArgumentException("Need a command!");
}
command = args[1].ToLowerInvariant();
options = new CliOptions(args, 2);
switch (command)
{
case "get":
await GetPublisherAsync(options).ConfigureAwait(false);
break;
case "update":
await UpdatePublisherAsync(options).ConfigureAwait(false);
break;
case "monitor":
await MonitorPublishersAsync().ConfigureAwait(false);
break;
case "get-config":
await GetConfiguredEndpointsAsync(options).ConfigureAwait(false);
break;
case "set-config":
await SetConfiguredEndpointsAsync(options).ConfigureAwait(false);
break;
case "list":
await ListPublishersAsync(options).ConfigureAwait(false);
break;
case "select":
await SelectPublisherAsync(options).ConfigureAwait(false);
break;
case "query":
await QueryPublishersAsync(options).ConfigureAwait(false);
break;
case "-?":
case "-h":
case "--help":
case "help":
PrintPublishersHelp();
break;
default:
throw new ArgumentException($"Unknown command {command}.");
}
break;
case "gateways":
if (args.Length < 2)
{
throw new ArgumentException("Need a command!");
}
command = args[1].ToLowerInvariant();
options = new CliOptions(args, 2);
switch (command)
{
case "get":
await GetGatewayAsync(options).ConfigureAwait(false);
break;
case "update":
await UpdateGatewayAsync(options).ConfigureAwait(false);
break;
case "monitor":
await MonitorGatewaysAsync().ConfigureAwait(false);
break;
case "list":
await ListGatewaysAsync(options).ConfigureAwait(false);
break;
case "select":
await SelectGatewayAsync(options).ConfigureAwait(false);
break;
case "query":
await QueryGatewaysAsync(options).ConfigureAwait(false);
break;
case "-?":
case "-h":
case "--help":
case "help":
PrintGatewaysHelp();
break;
default:
throw new ArgumentException($"Unknown command {command}.");
}
break;
case "nodes":
if (args.Length < 2)
{
throw new ArgumentException("Need a command!");
}
command = args[1].ToLowerInvariant();
options = new CliOptions(args, 2);
switch (command)
{
case "browse":
await BrowseAsync(options).ConfigureAwait(false);
break;
case "select":
await SelectNodeAsync(options).ConfigureAwait(false);
break;
case "publish":
await PublishAsync(options).ConfigureAwait(false);
break;
case "monitor":
await MonitorSamplesAsync(options).ConfigureAwait(false);
break;
case "unpublish":
await UnpublishAsync(options).ConfigureAwait(false);
break;
case "list":
await ListPublishedNodesAsync(options).ConfigureAwait(false);
break;
case "read":
await ReadAsync(options).ConfigureAwait(false);
break;
case "write":
await WriteAsync(options).ConfigureAwait(false);
break;
case "metadata":
await MethodMetadataAsync(options).ConfigureAwait(false);
break;
case "call":
await MethodCallAsync(options).ConfigureAwait(false);
break;
case "-?":
case "-h":
case "--help":
case "help":
PrintNodesHelp();
break;
default:
throw new ArgumentException($"Unknown command {command}.");
}
break;
case "-?":
case "-h":
case "--help":
case "help":
PrintHelp();
break;
default:
throw new ArgumentException($"Unknown command {command}.");
}
}
catch (ArgumentException e)
{
Console.WriteLine(e.Message);
if (!interactive)
{
PrintHelp();
return;
}
}
catch (Exception e)
{
Console.WriteLine("==================");
Console.WriteLine(e);
Console.WriteLine("==================");
}
}
while (interactive);
}