static void ConfigureTestCommand(CommandLineApplication hcCommand) { hcCommand.RelayCommand("test", (testCmd) => { testCmd.Description = "HybridConnection tests"; var connectionStringArgument = testCmd.Argument("connectionString", "Relay ConnectionString"); testCmd.OnExecute(async() => { string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument); if (string.IsNullOrEmpty(connectionString)) { TraceMissingArgument(connectionStringArgument.Name); testCmd.ShowHelp(); return(1); } return(await HybridConnectionTests.RunTestsAsync(new RelayConnectionStringBuilder(connectionString), RelayTraceSource.Instance)); }); }); }
internal static void ConfigureCommands(CommandLineApplication app) { app.RelayCommand("diag", (diagCommand) => { diagCommand.Description = "Operations for diagnosing relay/hc issues (Analyze)"; var namespaceOrConnectionStringArgument = diagCommand.Argument(NamespaceOrConnectionStringArgumentName, NamespaceOrConnectionStringArgumentDescription); CommandOption allOption = diagCommand.Option( "-a|--all", "Show all details", CommandOptionType.NoValue); CommandOption namespaceOption = diagCommand.Option( "-n|-ns|--namespace", "Show namespace details", CommandOptionType.NoValue); CommandOption netStatOption = diagCommand.Option( "--netstat", "Show netstat output", CommandOptionType.NoValue); CommandOption portsOption = diagCommand.Option( "-p|--ports", "Probe Relay Ports", CommandOptionType.NoValue); CommandOption instancePortsOption = diagCommand.Option( "-ip|--instance-ports <instanceCount>", "Probe Relay Instance Level Ports", CommandOptionType.SingleValue); CommandOption osOption = diagCommand.Option( "-o|--os", "Display Platform/OS/.NET information", CommandOptionType.NoValue); CommandOption protocolOption = diagCommand.AddSecurityProtocolOption(); diagCommand.OnExecute(async() => { ConfigureSecurityProtocol(protocolOption); bool defaultOptions = !allOption.HasValue() && !namespaceOption.HasValue() && !netStatOption.HasValue() && !portsOption.HasValue() && !osOption.HasValue(); // Run netstat before we try to lookup the namespace to keep ourself out of the results // NetStat output isn't part of the default run, must specify --netstat or --all if (netStatOption.HasValue() || allOption.HasValue()) { ExecuteNetStatCommand(); } NamespaceDetails namespaceDetails = default; string connectionString = ConnectionStringUtility.ResolveConnectionString(namespaceOrConnectionStringArgument); // Might not be present if (!string.IsNullOrEmpty(connectionString)) { var connectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString); try { namespaceDetails = await NamespaceUtility.GetNamespaceDetailsAsync(connectionStringBuilder.Endpoints.First().Host); } catch (Exception e) { RelayTraceSource.TraceException(e, "Getting namespace details"); } } if (defaultOptions || osOption.HasValue() || allOption.HasValue()) { await ExecutePlatformCommandAsync(namespaceDetails); } if (defaultOptions || namespaceOption.HasValue() || allOption.HasValue()) { ExecuteNamespaceCommand(namespaceDetails); } if (defaultOptions || portsOption.HasValue() || allOption.HasValue() || instancePortsOption.HasValue()) { int gatewayCount = GetIntOption(instancePortsOption, 1); await ExecutePortsCommandAsync(namespaceDetails, gatewayCount); } return(0); }); }); }