Beispiel #1
0
        public static void Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                FullName = "Azure SignalR Management Sample: Message Publisher"
            };

            app.HelpOption("--help");
            app.Description = "Message publisher using Azure SignalR Service Management SDK.";

            var connectionStringOption     = app.Option("-c|--connectionstring", "Set connection string.", CommandOptionType.SingleValue, true);
            var serviceTransportTypeOption = app.Option("-t|--transport", "Set service transport type. Options: <transient>|<persistent>. Default value: transient. Transient: calls REST API for each message. Persistent: Establish a WebSockets connection and send all messages in the connection.", CommandOptionType.SingleValue, true); // todo: description
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddUserSecrets <Program>()
                                .AddEnvironmentVariables()
                                .Build();


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

                if (string.IsNullOrEmpty(connectionString))
                {
                    MissOptions();
                    return(-1);
                }

                ServiceTransportType serviceTransportType;
                if (string.IsNullOrEmpty(serviceTransportTypeOption.Value()))
                {
                    serviceTransportType = ServiceTransportType.Transient;
                }
                else
                {
                    serviceTransportType = Enum.Parse <ServiceTransportType>(serviceTransportTypeOption.Value(), true);
                }

                var publisher = new MessagePublisher(connectionString, serviceTransportType);
                await publisher.InitAsync();

                await StartAsync(publisher);

                return(0);
            });

            app.Execute(args);
        }