Beispiel #1
0
        static void Main(string[] args)
        {
            var app = new CommandLineApplication();

            app.FullName = "Azure SignalR Serverless Sample";
            app.HelpOption("--help");

            var connectionStringOption = app.Option("-c|--connectionstring", "Set ConnectionString", CommandOptionType.SingleValue, true);
            var hubOption = app.Option("-h|--hub", "Set hub", CommandOptionType.SingleValue, true);

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddUserSecrets <Program>()
                                .Build();

            app.Command("client", cmd =>
            {
                cmd.Description = "Start a client to listen to the service";
                cmd.HelpOption("--help");

                var clientCount = cmd.Argument("<clients>", "Set number of clients");

                cmd.OnExecute(async() =>
                {
                    var connectionString = connectionStringOption.Value() ?? configuration["Azure:SignalR:ConnectionString"];

                    if (string.IsNullOrEmpty(connectionString) || !hubOption.HasValue())
                    {
                        MissOptions();
                        return(0);
                    }
                    var counter = new Counter();
                    var client  = new ClientHandler(connectionString, hubOption.Value(), Convert.ToInt32(clientCount.Value), counter);
                    counter.StartPrint();
                    await client.StartAsync();
                    Console.WriteLine("Client started...");
                    Console.ReadLine();

                    await client.DisposeAsync();

                    return(0);
                });
            });

            app.Command("server", cmd =>
            {
                cmd.Description = "Start a server to broadcast message through RestAPI";
                cmd.HelpOption("--help");

                var sendServer = cmd.Argument("<servers>", "Set number of sending server");
                var sendSize   = cmd.Argument("<sendSize>", "Set size of message");
                cmd.OnExecute(() =>
                {
                    var connectionString = connectionStringOption.Value() ?? configuration["Azure:SignalR:ConnectionString"];
                    if (string.IsNullOrEmpty(connectionString) || !hubOption.HasValue())
                    {
                        MissOptions();
                        return(0);
                    }

                    var counter = new Counter();
                    var server  = new ServerHandler(connectionString, hubOption.Value(), counter,
                                                    Convert.ToInt32(sendServer.Value), Convert.ToInt32(sendSize.Value));
                    counter.StartPrint();
                    server.Start();
                    Console.WriteLine("Server started...");
                    Console.ReadLine();
                    server.Stop();
                    server.Dispose();
                    return(0);
                });
            });

            app.Execute(args);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var app = new CommandLineApplication();

            app.FullName = "Azure SignalR Serverless Sample";
            app.HelpOption("--help");

            var connectionStringOption = app.Option("-c|--connectionstring", "Set ConnectionString", CommandOptionType.SingleValue, true);
            var hubOption = app.Option("-h|--hub", "Set hub", CommandOptionType.SingleValue, true);

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddUserSecrets <Program>()
                                .Build();

            app.Command("client", cmd =>
            {
                cmd.Description = "Start a client to listen to the service";
                cmd.HelpOption("--help");

                CommandArgument userId = cmd.Argument("<userId>", "Set User ID");



                cmd.OnExecute(async() =>
                {
                    var connectionString = connectionStringOption.Value() ?? configuration["Azure:SignalR:ConnectionString"];

                    if (string.IsNullOrEmpty(connectionString) || !hubOption.HasValue())
                    {
                        MissOptions();
                        return(0);
                    }

                    Console.WriteLine("<userId> is {0}", userId.Value);

                    var client = new ClientHandler(connectionString, hubOption.Value(), userId.Value);

                    await client.StartAsync();
                    Console.WriteLine("Client started...");
                    Console.ReadLine();
                    await client.DisposeAsync();

                    return(0);
                });
            });

            app.Command("server", cmd =>
            {
                cmd.Description = "Start a server to send message through RestAPI";
                cmd.HelpOption("--help");

                cmd.OnExecute(async() =>
                {
                    var connectionString = connectionStringOption.Value() ?? configuration["Azure:SignalR:ConnectionString"];

                    if (string.IsNullOrEmpty(connectionString) || !hubOption.HasValue())
                    {
                        MissOptions();
                        return(0);
                    }

                    var server = new ServerHandler(connectionString, hubOption.Value());
                    await server.Start();
                    return(0);
                });
            });

            app.Execute(args);
        }