Esempio n. 1
0
 public OptionContext(OptionSet set)
 {
     OptionSet    = set;
     OptionValues = new OptionValueCollection(this);
 }
Esempio n. 2
0
        public HostArguments(string[] args)
        {
            var executionMode = ExecutionMode.Run;

            commands = new List <Type> {
                typeof(RunCommand)
            };
            startMode      = StartMode.Automatic;
            ServiceName    = "Particular.ServiceControl";
            DisplayName    = "Particular ServiceControl";
            Description    = "Particular Software ServiceControl for NServiceBus.";
            ServiceAccount = ServiceAccount.LocalSystem;
            Username       = String.Empty;
            Password       = String.Empty;

            defaultOptions = new OptionSet
            {
                {
                    "?|h|help", "Help about the command line options.", key => { Help = true; }
                },
                {
                    "d|set={==}", "The configuration {0:option} to set to the specified {1:value}", (key, value) =>
                    {
                        options[key] = value;

                        commands = new List <Type>
                        {
                            typeof(WriteOptionsCommand),
                        };
                    }
                },
                {
                    "restart",
                    @"Restarts the endpoint."
                    , s =>
                    {
                        commands = new List <Type>
                        {
                            typeof(WriteOptionsCommand),
                            typeof(RestartCommand),
                        };
                    }
                },
                {
                    "start",
                    @"Starts the endpoint."
                    , s =>
                    {
                        commands = new List <Type>
                        {
                            typeof(WriteOptionsCommand),
                            typeof(StartCommand),
                        };
                    }
                },
                {
                    "stop",
                    @"Stops the endpoint."
                    , s =>
                    {
                        commands = new List <Type>
                        {
                            typeof(StopCommand),
                        };
                    }
                },
                {
                    "serviceName=",
                    @"Specify the service name for the installed service."
                    , s => { ServiceName = s; }
                },
            };

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


            uninstallOptions = new OptionSet
            {
                {
                    "?|h|help", "Help about the command line options.", key => { Help = true; }
                },
                {
                    "u|uninstall",
                    @"Uninstall the endpoint as a Windows service."
                    , s =>
                    {
                        commands = new List <Type> {
                            typeof(UninstallCommand)
                        };
                        executionMode = ExecutionMode.Uninstall;
                    }
                },
                {
                    "serviceName=",
                    @"Specify the service name for the installed service."
                    , s => { ServiceName = s; }
                }
            };

            installOptions = new OptionSet
            {
                {
                    "?|h|help",
                    "Help about the command line options.",
                    key => { Help = true; }
                },
                {
                    "i|install",
                    @"Install the endpoint as a Windows service."
                    , s =>
                    {
                        commands = new List <Type>
                        {
                            typeof(WriteOptionsCommand),
                            typeof(CheckMandatoryInstallOptionsCommand),
                            typeof(RunBootstrapperAndNServiceBusInstallers),
                            typeof(InstallCommand)
                        };
                        executionMode = ExecutionMode.Install;
                    }
                },
                {
                    "serviceName=",
                    @"Specify the service name for the installed service."
                    , s => { ServiceName = s; }
                },
                {
                    "displayName=",
                    @"Friendly name for the installed service."
                    , s => { DisplayName = s; }
                },
                {
                    "description=",
                    @"Description for the service."
                    , s => { Description = s; }
                },
                {
                    "username="******"Username for the account the service should run under."
                    , s => { Username = s; }
                },
                {
                    "password="******"Password for the service account."
                    , s => { Password = s; }
                },
                {
                    "localservice",
                    @"Run the service with the local service account."
                    , s => { ServiceAccount = ServiceAccount.LocalService; }
                },
                {
                    "networkservice",
                    @"Run the service with the network service permission."
                    , s => { ServiceAccount = ServiceAccount.NetworkService; }
                },
                {
                    "user",
                    @"Run the service with the specified username and password. Alternative the system will prompt for a valid username and password if values for both the username and password are not specified."
                    , s => { ServiceAccount = ServiceAccount.User; }
                },
                {
                    "delayed",
                    @"The service should start automatically (delayed)."
                    , s => { startMode = StartMode.Delay; }
                },
                {
                    "autostart",
                    @"The service should start automatically (default)."
                    , s => { startMode = StartMode.Automatic; }
                },
                {
                    "disabled",
                    @"The service should be set to disabled."
                    , s => { startMode = StartMode.Disabled; }
                },
                {
                    "manual",
                    @"The service should be started manually."
                    , s => { startMode = StartMode.Manual; }
                },
                {
                    "d|set={==}", "The configuration {0:option} to set to the specified {1:value}", (key, value) =>
                    {
                        options[key] = value;
                    }
                },
            };

            try
            {
                installOptions.Parse(args);
                if (executionMode == ExecutionMode.Install)
                {
                    return;
                }

                uninstallOptions.Parse(args);
                if (executionMode == ExecutionMode.Uninstall)
                {
                    return;
                }
                maintenanceOptions.Parse(args);
                if (executionMode == ExecutionMode.Maintenance)
                {
                    Settings.MaintenanceMode = true;
                    return;
                }

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