Ejemplo n.º 1
0
        static void ConfigureWcfCountCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("count", (countCommand) =>
            {
                countCommand.Description = "Get WCF Relay Count";

                var connectionStringArgument = countCommand.Argument("connectionString", "Relay ConnectionString");

                countCommand.OnExecute(async() =>
                {
                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    if (string.IsNullOrEmpty(connectionString))
                    {
                        TraceMissingArgument(connectionStringArgument.Name);
                        countCommand.ShowHelp();
                        return(1);
                    }

                    var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                    Uri namespaceUri     = namespaceManager.Address;
                    string namespaceHost = namespaceUri.Host;
                    var tokenProvider    = namespaceManager.Settings.TokenProvider;

                    RelayTraceSource.TraceVerbose($"Getting WcfRelay count for '{namespaceUri}");

                    int count = await NamespaceUtility.GetEntityCountAsync(namespaceUri, tokenProvider, "Relays");
                    RelayTraceSource.TraceInfo(string.Format($"{{0,-{namespaceHost.Length}}}  {{1}}", "Namespace", "WcfRelayCount"));
                    RelayTraceSource.TraceInfo(string.Format($"{{0,-{namespaceHost.Length}}}  {{1}}", namespaceHost, count));

                    return(0);
                });
            });
        }
Ejemplo n.º 2
0
        static void ConfigureWcfDeleteCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("delete", (deleteCmd) =>
            {
                deleteCmd.Description        = "Delete a WcfRelay";
                var pathArgument             = deleteCmd.Argument("path", "WcfRelay path");
                var connectionStringArgument = deleteCmd.Argument("connectionString", "Relay ConnectionString");
                var protocolOption           = deleteCmd.AddSecurityProtocolOption();

                deleteCmd.OnExecute(async() =>
                {
                    ConfigureSecurityProtocol(protocolOption);
                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(pathArgument.Value))
                    {
                        TraceMissingArgument(string.IsNullOrEmpty(connectionString) ? connectionStringArgument.Name : pathArgument.Name);
                        deleteCmd.ShowHelp();
                        return(1);
                    }

                    var connectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
                    RelayTraceSource.TraceInfo($"Deleting WcfRelay '{pathArgument.Value}' in {connectionStringBuilder.Endpoints.First().Host}...");
                    var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                    await namespaceManager.DeleteRelayAsync(pathArgument.Value);
                    RelayTraceSource.TraceInfo($"Deleting WcfRelay '{pathArgument.Value}' in {connectionStringBuilder.Endpoints.First().Host} succeeded");
                    return(0);
                });
            });
        }
Ejemplo n.º 3
0
        static void ConfigureWcfListenCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("listen", (listenCmd) =>
            {
                listenCmd.Description        = "WcfRelay listen command";
                var pathArgument             = listenCmd.Argument("path", "WcfRelay path");
                var connectionStringArgument = listenCmd.Argument("connectionString", "Relay ConnectionString");

                var bindingOption                = listenCmd.Option(BindingOptionTemplate, BindingOptionDescription, CommandOptionType.SingleValue);
                var noClientAuthOption           = listenCmd.Option("--no-client-auth", "Skip client authentication", CommandOptionType.NoValue);
                var connectivityModeOption       = listenCmd.Option(CommandStrings.ConnectivityModeTemplate, CommandStrings.ConnectivityModeDescription, CommandOptionType.SingleValue);
                var responseOption               = listenCmd.Option("--response <response>", "Response to return", CommandOptionType.SingleValue);
                var protocolOption               = listenCmd.AddSecurityProtocolOption();
                var maxConcurrentSessionsOption  = listenCmd.Option("--max-concurrent-sessions <count>", "Max Concurrent Sessions", CommandOptionType.SingleValue);
                var maxConcurrentInstancesOption = listenCmd.Option("--max-concurrent-instances <count>", "Max Concurrent Instances", CommandOptionType.SingleValue);

                listenCmd.OnExecute(() =>
                {
                    ConfigureSecurityProtocol(protocolOption);

                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    string path             = pathArgument.Value ?? DefaultPath;
                    if (string.IsNullOrEmpty(connectionString))
                    {
                        TraceMissingArgument(connectionStringArgument.Name);
                        listenCmd.ShowHelp();
                        return(1);
                    }

                    Binding binding = GetBinding(bindingOption, noClientAuthOption, null, null, null);
                    try
                    {
                        var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                        namespaceManager.Settings.OperationTimeout = TimeSpan.FromSeconds(5);
                        if (!string.IsNullOrEmpty(path) && namespaceManager.RelayExists(path))
                        {
                            dynamic dynamicBinding   = binding;
                            dynamicBinding.IsDynamic = false;
                        }
                    }
                    catch (Exception exception)
                    {
                        RelayTraceSource.TraceException(exception, "Error calling RelayExists");
                    }

                    var throttlingBehavior = GetThrottlingBehavior(maxConcurrentSessionsOption, maxConcurrentInstancesOption);
                    return(VerifyListen(connectionString, path, binding, GetConnectivityMode(connectivityModeOption), responseOption.Value(), throttlingBehavior));
                });
            });
        }
Ejemplo n.º 4
0
        static void ConfigureWcfListCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("list", (listCmd) =>
            {
                listCmd.Description          = "List WcfRelay(s)";
                var pathArgument             = listCmd.Argument("path", "Optional WcfRelay path");
                var connectionStringArgument = listCmd.Argument("connectionString", "Relay ConnectionString");
                var protocolOption           = listCmd.AddSecurityProtocolOption();

                listCmd.OnExecute(async() =>
                {
                    ConfigureSecurityProtocol(protocolOption);
                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    if (string.IsNullOrEmpty(connectionString))
                    {
                        TraceMissingArgument(connectionStringArgument.Name);
                        listCmd.ShowHelp();
                        return(1);
                    }

                    string path = pathArgument.Value;

                    var connectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
                    var namespaceManager        = NamespaceManager.CreateFromConnectionString(connectionString);
                    IEnumerable <RelayDescription> relays;
                    if (string.IsNullOrEmpty(path))
                    {
                        RelayTraceSource.TraceInfo($"Listing WcfRelays for {connectionStringBuilder.Endpoints.First().Host}");
                        relays = await namespaceManager.GetRelaysAsync();
                    }
                    else
                    {
                        RelayTraceSource.TraceInfo($"Getting WcfRelay {connectionStringBuilder.Endpoints.First().Host}/{path}");
                        relays = new[] { await namespaceManager.GetRelayAsync(path) };
                    }

                    RelayTraceSource.TraceInfo($"{"Path",-38} {"ListenerCount",-15} {"RequiresClientAuth",-20} RelayType");
                    foreach (var relay in relays)
                    {
                        RelayTraceSource.TraceInfo($"{relay.Path,-38} {relay.ListenerCount,-15} {relay.RequiresClientAuthorization,-20} {relay.RelayType}");
                    }

                    return(0);
                });
            });
        }
Ejemplo n.º 5
0
        static void ConfigureWcfSendCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("send", (sendCmd) =>
            {
                sendCmd.Description          = "WcfRelay send command";
                var pathArgument             = sendCmd.Argument("path", "WcfRelay path");
                var connectionStringArgument = sendCmd.Argument("connectionString", "Relay ConnectionString");

                var numberOption           = sendCmd.Option(CommandStrings.NumberTemplate, CommandStrings.NumberDescription, CommandOptionType.SingleValue);
                var bindingOption          = sendCmd.Option(BindingOptionTemplate, BindingOptionDescription, CommandOptionType.SingleValue);
                var noClientAuthOption     = sendCmd.Option("--no-client-auth", "Skip client authentication", CommandOptionType.NoValue);
                var connectivityModeOption = sendCmd.Option(CommandStrings.ConnectivityModeTemplate, CommandStrings.ConnectivityModeDescription, CommandOptionType.SingleValue);
                var requestOption          = sendCmd.Option(CommandStrings.RequestTemplate, CommandStrings.RequestDescription, CommandOptionType.SingleValue);
                var requestDelayOption     = sendCmd.Option("-rd|--request-delay <delay>", "A TimeSpan indicating how long the listener should delay before responding to request", CommandOptionType.SingleValue);
                var openTimeoutOption      = sendCmd.Option("-ot|--open-timeout <timeout>", "A TimeSpan for configuring the Binding.OpenTimeout", CommandOptionType.SingleValue);
                var sendTimeoutOption      = sendCmd.Option("-st|--send-timeout <timeout>", "A TimeSpan for configuring the Binding.SendTimeout", CommandOptionType.SingleValue);
                var readTimeoutOption      = sendCmd.Option("-rt|--receive-timeout <timeout>", "A TimeSpan for configuring the Binding.ReceiveTimeout", CommandOptionType.SingleValue);
                var protocolOption         = sendCmd.AddSecurityProtocolOption();

                sendCmd.OnExecute(() =>
                {
                    ConfigureSecurityProtocol(protocolOption);

                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    string path             = pathArgument.Value ?? DefaultPath;
                    string request          = GetStringOption(requestOption, "Test Message Data");
                    if (string.IsNullOrEmpty(connectionString))
                    {
                        TraceMissingArgument(connectionStringArgument.Name);
                        sendCmd.ShowHelp();
                        return(1);
                    }

                    int number = GetIntOption(numberOption, 1);
                    var connectionStringBuilder       = new ServiceBusConnectionStringBuilder(connectionString);
                    Binding binding                   = GetBinding(bindingOption, noClientAuthOption, openTimeoutOption, sendTimeoutOption, readTimeoutOption);
                    ConnectivityMode connectivityMode = GetConnectivityMode(connectivityModeOption);
                    TimeSpan requestDelay             = requestDelayOption.HasValue() ? TimeSpan.Parse(requestDelayOption.Value()) : TimeSpan.Zero;
                    return(VerifySend(request, connectionStringBuilder, path, number, binding, noClientAuthOption.HasValue(), connectivityMode, requestDelay));
                });
            });
        }
Ejemplo n.º 6
0
        static void ConfigureWcfCreateCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("create", (createCmd) =>
            {
                createCmd.Description = "Create a WcfRelay";

                var pathArgument             = createCmd.Argument("path", "WcfRelay path");
                var connectionStringArgument = createCmd.Argument("connectionString", "Relay ConnectionString");

                var relayTypeOption = createCmd.Option(
                    "-t|--relaytype <relaytype>", "The RelayType (nettcp|http)", CommandOptionType.SingleValue);
                var requireClientAuthOption = createCmd.Option(
                    CommandStrings.RequiresClientAuthTemplate, CommandStrings.RequiresClientAuthDescription, CommandOptionType.SingleValue);
                var protocolOption = createCmd.AddSecurityProtocolOption();

                createCmd.OnExecute(async() =>
                {
                    ConfigureSecurityProtocol(protocolOption);
                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(pathArgument.Value))
                    {
                        TraceMissingArgument(string.IsNullOrEmpty(connectionString) ? connectionStringArgument.Name : pathArgument.Name);
                        createCmd.ShowHelp();
                        return(1);
                    }

                    var connectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
                    RelayTraceSource.TraceInfo($"Creating WcfRelay '{pathArgument.Value}' in {connectionStringBuilder.Endpoints.First().Host}...");
                    var relayDescription = new RelayDescription(pathArgument.Value, GetRelayType(relayTypeOption));
                    relayDescription.RequiresClientAuthorization = GetBoolOption(requireClientAuthOption, true);
                    var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                    await namespaceManager.CreateRelayAsync(relayDescription);
                    RelayTraceSource.TraceInfo($"Creating WcfRelay '{pathArgument.Value}' in {connectionStringBuilder.Endpoints.First().Host} succeeded");
                    return(0);
                });
            });
        }
Ejemplo n.º 7
0
        static void ConfigureWcfTestCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("test", (testCmd) =>
            {
                testCmd.Description          = "WcfRelay tests";
                var connectionStringArgument = testCmd.Argument("connectionString", "Relay ConnectionString");
                var numberOption             = testCmd.Option(CommandStrings.NumberTemplate, CommandStrings.NumberDescription, CommandOptionType.SingleValue);
                var testNameOption           = testCmd.Option("-t|--tests", "A regex to pick which tests to run", CommandOptionType.SingleValue);

                testCmd.OnExecute(async() =>
                {
                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    if (string.IsNullOrEmpty(connectionString))
                    {
                        TraceMissingArgument(connectionStringArgument.Name);
                        testCmd.ShowHelp();
                        return(1);
                    }

                    int number = GetIntOption(numberOption, 1);
                    return(await RunWcfTestsAsync(connectionString, number, testNameOption.Value()));
                });
            });
        }