コード例 #1
0
ファイル: Program.cs プロジェクト: dlstucki/RelayUtil
        static int MainCore(string[] args)
        {
            var app = new CommandLineApplication();

            app.Name        = nameof(RelayUtil);
            app.Description = "Azure Relay Utility Commands";
            RelayCommands.CommonSetup(app);

            try
            {
                app.OnExecute(() =>
                {
                    app.ShowHelp();
                    return(0);
                });

                DiagnosticCommands.ConfigureCommands(app);
                WcfRelayCommands.ConfigureCommands(app);
                HybridConnectionCommands.ConfigureCommands(app);
                SharedAccessSignatureCommands.ConfigureCommands(app);

                return(app.Execute(args));
            }
            catch (Exception exception)
            {
                RelayTraceSource.TraceException(exception);
                return(exception.HResult);
            }
        }
コード例 #2
0
ファイル: RelayCommands.cs プロジェクト: dlstucki/RelayUtil
        internal static async Task RunTestAsync(string testName, Regex testNameRegex, IList <TestResult> testResults, Func <Task> testFunc)
        {
            if (testNameRegex != null && !testNameRegex.IsMatch(testName))
            {
                // Filter specified and test name doesn't match
                return;
            }

            TraceCommandHeader(testName);
            try
            {
                await testFunc();

                testResults.Add(new TestResult {
                    Passed = true, TestName = testName
                });
            }
            catch (Exception exception)
            {
                RelayTraceSource.TraceException(exception, testName);
                testResults.Add(new TestResult {
                    Passed = false, TestName = testName
                });
            }
        }
コード例 #3
0
 static async Task GetCloudServiceTimeAsync(string serviceNamespace)
 {
     try
     {
         var webRequest = WebRequest.CreateHttp(new Uri($"https://{serviceNamespace}"));
         webRequest.Method = "GET";
         using (var response = await webRequest.GetResponseAsync())
         {
             RelayTraceSource.TraceInfo(OutputFormat, "Azure Time:", response.Headers["Date"]); // RFC1123
         }
     }
     catch (Exception exception)
     {
         RelayTraceSource.TraceException(exception, "Getting current time from Relay cloud service");
     }
 }
コード例 #4
0
        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);
                });
            });
        }