Command line options for the server.
Inheritance: CommandLineOptionsBase
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var options = new NodeOptions();
            var config = ConfigurationManager.AppSettings["params"] ?? "";

            if (!CommandLineParser.Default.ParseArguments(config.Split(' '), options))
            {
                Console.WriteLine("Can not parse parameters from configuration file.");
                return;
            }

            var cliOptions = new NodeOptions();

            var lineAsString = string.Join(" ", args);

            if (lineAsString == "/?" || lineAsString == "--help")
            {
                Console.WriteLine("Usage");
                Console.WriteLine(cliOptions.GetUsage());
                return;
            }

            if (!CommandLineParser.Default.ParseArguments(args, cliOptions))
            {
                Console.WriteLine("Can not parse parameters from command line.");
                return;
            }

            // Override app.config options with values from command line
            if (!cliOptions.StoreLocation.Equals(NodeOptions.StoreLocationDefault))
                options.StoreLocation = cliOptions.StoreLocation;

            if (cliOptions.HttpPort != NodeOptions.HttpPortDefault)
                options.HttpPort = cliOptions.HttpPort;

            if (cliOptions.KillSwitch != NodeOptions.KillSwitchDefault)
                options.KillSwitch = cliOptions.KillSwitch;

            var node = NodeEntryPoint.StartWithOptions(options, i => Environment.Exit(i));

            if (options.KillSwitch > 0)
            {
                node.RequestServiceStopIn(options.KillSwitch);
            }
            var interactiveMode = options.KillSwitch <= 0;

            if (interactiveMode)
            {
                Console.Title = String.Format("Test server : {0} : {1}", options.HttpPort, options.StoreLocation);
                Console.WriteLine("Starting everything. Press enter to initiate shutdown");
                Console.ReadLine();
                node.RequestServiceStop();
                Console.ReadLine();
            }
            else
            {
                node.WaitForServiceToExit();
            }
        }
Exemplo n.º 2
0
        public static NodeEntryPoint StartWithOptions(NodeOptions options, Action <int> termination)
        {
            var slim = new ManualResetEventSlim(false);
            var list = String.Join(Environment.NewLine,
                                   options.GetPairs().Select(p => String.Format("{0} : {1}", p.Key, p.Value)));

            Log.Info(list);

            var bus        = new InMemoryBus("OutputBus");
            var controller = new NodeController(bus);
            var mainQueue  = new QueuedHandler(controller, "Main Queue");

            controller.SetMainQueue(mainQueue);
            Application.Start(i =>
            {
                slim.Set();
                termination(i);
            });

            var http = new PlatformServerApiService(mainQueue, String.Format("http://{0}:{1}/", options.LocalHttpIp, options.HttpPort));

            bus.Subscribe <SystemMessage.Init>(http);
            bus.Subscribe <SystemMessage.StartShutdown>(http);


            var timer = new TimerService(new ThreadBasedScheduler(new RealTimeProvider()));

            bus.Subscribe <TimerMessage.Schedule>(timer);

            // switch, based on configuration
            AzureStoreConfiguration azureConfig;

            if (AzureStoreConfiguration.TryParse(options.StoreLocation, out azureConfig))
            {
                var storageService = new AzureStorageService(azureConfig, mainQueue);
                bus.Subscribe <ClientMessage.AppendEvents>(storageService);
                bus.Subscribe <SystemMessage.Init>(storageService);
                bus.Subscribe <ClientMessage.ImportEvents>(storageService);
                bus.Subscribe <ClientMessage.RequestStoreReset>(storageService);
            }
            else
            {
                var storageService = new FileStorageService(options.StoreLocation, mainQueue);
                bus.Subscribe <ClientMessage.AppendEvents>(storageService);
                bus.Subscribe <SystemMessage.Init>(storageService);
                bus.Subscribe <ClientMessage.ImportEvents>(storageService);
                bus.Subscribe <ClientMessage.RequestStoreReset>(storageService);
            }


            mainQueue.Start();

            mainQueue.Enqueue(new SystemMessage.Init());
            return(new NodeEntryPoint(mainQueue, slim));
        }
Exemplo n.º 3
0
        public static NodeEntryPoint StartWithOptions(NodeOptions options, Action<int> termination)
        {
            var slim = new ManualResetEventSlim(false);
            var list = String.Join(Environment.NewLine,
                options.GetPairs().Select(p => String.Format("{0} : {1}", p.Key, p.Value)));

            Log.Info(list);

            var bus = new InMemoryBus("OutputBus");
            var controller = new NodeController(bus);
            var mainQueue = new QueuedHandler(controller, "Main Queue");
            controller.SetMainQueue(mainQueue);
            Application.Start(i =>
                {
                    slim.Set();
                    termination(i);
                });

            var http = new PlatformServerApiService(mainQueue, String.Format("http://{0}:{1}/", options.LocalHttpIp, options.HttpPort));

            bus.Subscribe<SystemMessage.Init>(http);
            bus.Subscribe<SystemMessage.StartShutdown>(http);

            var timer = new TimerService(new ThreadBasedScheduler(new RealTimeProvider()));
            bus.Subscribe<TimerMessage.Schedule>(timer);

            // switch, based on configuration
            AzureStoreConfiguration azureConfig;
            if (AzureStoreConfiguration.TryParse(options.StoreLocation, out azureConfig))
            {
                var storageService = new AzureStorageService(azureConfig, mainQueue);
                bus.Subscribe<ClientMessage.AppendEvents>(storageService);
                bus.Subscribe<SystemMessage.Init>(storageService);
                bus.Subscribe<ClientMessage.ImportEvents>(storageService);
                bus.Subscribe<ClientMessage.RequestStoreReset>(storageService);
            }
            else
            {
                var storageService = new FileStorageService(options.StoreLocation, mainQueue);
                bus.Subscribe<ClientMessage.AppendEvents>(storageService);
                bus.Subscribe<SystemMessage.Init>(storageService);
                bus.Subscribe<ClientMessage.ImportEvents>(storageService);
                bus.Subscribe<ClientMessage.RequestStoreReset>(storageService);
            }

            mainQueue.Start();

            mainQueue.Enqueue(new SystemMessage.Init());
            return new NodeEntryPoint(mainQueue,slim);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var options = new NodeOptions();
            var config  = ConfigurationManager.AppSettings["params"] ?? "";

            if (!CommandLineParser.Default.ParseArguments(config.Split(' '), options))
            {
                Console.WriteLine("Can not parse parameters from configuration file.");
                return;
            }

            var cliOptions = new NodeOptions();

            var lineAsString = string.Join(" ", args);

            if (lineAsString == "/?" || lineAsString == "--help")
            {
                Console.WriteLine("Usage");
                Console.WriteLine(cliOptions.GetUsage());
                return;
            }

            if (!CommandLineParser.Default.ParseArguments(args, cliOptions))
            {
                Console.WriteLine("Can not parse parameters from command line.");
                return;
            }

            // Override app.config options with values from command line
            if (!cliOptions.StoreLocation.Equals(NodeOptions.StoreLocationDefault))
            {
                options.StoreLocation = cliOptions.StoreLocation;
            }

            if (cliOptions.HttpPort != NodeOptions.HttpPortDefault)
            {
                options.HttpPort = cliOptions.HttpPort;
            }

            if (cliOptions.KillSwitch != NodeOptions.KillSwitchDefault)
            {
                options.KillSwitch = cliOptions.KillSwitch;
            }

            var node = NodeEntryPoint.StartWithOptions(options, i => Environment.Exit(i));

            if (options.KillSwitch > 0)
            {
                node.RequestServiceStopIn(options.KillSwitch);
            }
            var interactiveMode = options.KillSwitch <= 0;

            if (interactiveMode)
            {
                Console.Title = String.Format("Test server : {0} : {1}", options.HttpPort, options.StoreLocation);
                Console.WriteLine("Starting everything. Press enter to initiate shutdown");
                Console.ReadLine();
                node.RequestServiceStop();
                Console.ReadLine();
            }
            else
            {
                node.WaitForServiceToExit();
            }
        }