Пример #1
0
        public static T Read(string root, string name, T defaultValue = default)
        {
            if (ConfigFileSettingsReader <T> .TryRead(root, name, out var value))
            {
                return(value);
            }

            return(RegistryReader <T> .Read(root, name, defaultValue));
        }
Пример #2
0
        public HostArguments(string[] args)
        {
            if (ConfigFileSettingsReader <bool> .Read("MaintenanceMode"))
            {
                args = args.Concat(new[]
                {
                    "-m"
                }).ToArray();
            }

            var executionMode = ExecutionMode.Run;

            Commands = new List <Type> {
                typeof(RunCommand)
            };
            ServiceName = Settings.DEFAULT_SERVICE_NAME;

            var defaultOptions = new OptionSet
            {
                {
                    "?|h|help", "Help about the command line options.", key => { Help = true; }
                },
            };

            var maintenanceOptions = new OptionSet
            {
                {
                    "m|maint|maintenance",
                    @"Run RavenDB only - use for DB maintenance",
                    s => {
                        Commands = new List <Type>
                        {
                            typeof(MaintCommand)
                        };
                        executionMode = ExecutionMode.Maintenance;
                    }
                }
            };

            // Not documented in help - Used by SC installer only
            var externalInstallerOptions = new OptionSet
            {
                {
                    "s|setup",
                    @"Internal use - for new installer"
                    , s =>
                    {
                        Commands = new List <Type> {
                            typeof(SetupCommand)
                        };
                        executionMode = ExecutionMode.RunInstallers;
                    }
                },
                {
                    "serviceName=",
                    @"Specify the service name for the installed service."
                    , s => { ServiceName = s; }
                },
                {
                    "userName="******"Username for the account the service should run under."
                    , s => { Username = s; }
                }
            };

            var externalUnitTestRunnerOptions = new OptionSet
            {
                {
                    "p|portable",
                    @"Internal use - runs as a console app, even non-interactively",
                    s => { Portable = true; }
                }
            };

            try
            {
                externalInstallerOptions.Parse(args);
                if (executionMode == ExecutionMode.RunInstallers)
                {
                    return;
                }

                maintenanceOptions.Parse(args);
                if (executionMode == ExecutionMode.Maintenance)
                {
                    return;
                }

                defaultOptions.Parse(args);
                externalUnitTestRunnerOptions.Parse(args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Help = true;
            }
        }