Beispiel #1
0
        private static void InteractiveRun(string[] args)
        {
            var ioTestRequest = new GenericPerformanceTestRequest();

            string backupLocation            = null;
            string restoreLocation           = null;
            string restoreDatabaseName       = null;
            string restoreFilesystemName     = null;
            bool   restoreDisableReplication = false;
            bool   defrag = false;
            var    requiresRestoreAction = new HashSet <string>();
            bool   isRestoreAction       = false;
            var    requiresIoTestAction  = new HashSet <string>();
            bool   isIoTestAction        = false;
            Action actionToTake          = null;
            bool   launchBrowser         = false;
            bool   noLog = false;
            var    ravenConfiguration  = new RavenConfiguration();
            bool   waitForRestore      = true;
            int?   restoreStartTimeout = 15;

            var optionSet = new OptionSet();

            optionSet.Add("set={==}", OptionCategory.None, "The configuration {0:option} to set to the specified {1:value}", (key, value) =>
            {
                ravenConfiguration.Settings[key] = value;
                ravenConfiguration.Initialize();
            });
            optionSet.Add("nolog", OptionCategory.General, "Don't use the default log", s => noLog = true);
            optionSet.Add("config=", OptionCategory.General, "The config {0:file} to use", ravenConfiguration.LoadFrom);
            optionSet.Add("install", OptionCategory.Service, "Installs the RavenDB service", key => actionToTake = () => AdminRequired(InstallAndStart));
            optionSet.Add("allow-blank-password-use", OptionCategory.Other, "Allow to log on by using a Windows account that has a blank password", key => actionToTake = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(0)));
            optionSet.Add("deny-blank-password-use", OptionCategory.Other, "Deny to log on by using a Windows account that has a blank password", key => actionToTake   = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(1)));
            optionSet.Add("service-name=", OptionCategory.Service, "The {0:service name} to use when installing or uninstalling the service, default to RavenDB", name => ProjectInstaller.SERVICE_NAME = name);
            optionSet.Add("uninstall", OptionCategory.Service, "Uninstalls the RavenDB service", key => actionToTake = () => AdminRequired(EnsureStoppedAndUninstall));
            optionSet.Add("start", OptionCategory.Service, "Starts the RavenDB service", key => actionToTake         = () => AdminRequired(StartService));
            optionSet.Add("restart", OptionCategory.Service, "Restarts the RavenDB service", key => actionToTake     = () => AdminRequired(RestartService));
            optionSet.Add("stop", OptionCategory.Service, "Stops the RavenDB service", key => actionToTake           = () => AdminRequired(StopService));
            optionSet.Add("ram", OptionCategory.General, "Run RavenDB in RAM only", key =>
            {
                ravenConfiguration.Settings[Constants.RunInMemory] = "true";
                ravenConfiguration.RunInMemory = true;
                ravenConfiguration.Initialize();
                actionToTake = () => RunInDebugMode(AnonymousUserAccessMode.Admin, ravenConfiguration, launchBrowser, noLog);
            });
            optionSet.Add("debug", OptionCategory.General, "Run RavenDB in debug mode", key => actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog));
            optionSet.Add("browser|launchbrowser", OptionCategory.General, "After the server starts, launches the browser", key => launchBrowser = true);
            optionSet.Add("help", OptionCategory.Help, "Help about the command line interface", key =>
            {
                actionToTake = () => PrintUsage(optionSet);
            });
            optionSet.Add("config-help", OptionCategory.Help, "Help about configuration databaseOptions", key =>
            {
                actionToTake = () => PrintConfig(ravenConfiguration.GetConfigOptionsDocs());
            });
            optionSet.Add("restore", OptionCategory.RestoreDatabase, "[Obsolete] Use --restore-system-database or --restore-database", key =>
            {
                actionToTake = () =>
                {
                    throw new OptionException("This method is obsolete, use --restore-system-database or --restore-database", "restore");
                };
                isRestoreAction = true;
            });
            optionSet.Add("restore-system-database", OptionCategory.RestoreDatabase, "Restores a SYSTEM database from backup.", key =>
            {
                actionToTake = () =>
                {
                    if (backupLocation == null || restoreLocation == null)
                    {
                        throw new OptionException("When using --restore-system-database, --restore-source and --restore-destination must be specified", "restore-system-database");
                    }
                    RunSystemDatabaseRestoreOperation(backupLocation, restoreLocation, defrag);
                };
                isRestoreAction = true;
            });
            optionSet.Add("restore-database=", OptionCategory.RestoreDatabase, "Starts a restore operation from a backup on a REMOTE server found under specified {0:url}.", url =>
            {
                actionToTake = () =>
                {
                    if (backupLocation == null)
                    {
                        throw new OptionException("When using --restore-database, --restore-source must be specified", "restore-database");
                    }

                    Uri uri;
                    if (Uri.TryCreate(url, UriKind.Absolute, out uri) == false)
                    {
                        throw new OptionException("Specified destination server url is not valid", "restore-database");
                    }

                    RunRemoteDatabaseRestoreOperation(backupLocation, restoreLocation, restoreDatabaseName, defrag, restoreDisableReplication, uri, waitForRestore, restoreStartTimeout);
                    Environment.Exit(0);
                };
                isRestoreAction = true;
            });
            optionSet.Add("restore-filesystem=", OptionCategory.RestoreFileSystem, "Starts a restore operation from a backup on a REMOTE server found under specified {0:url}.", url =>
            {
                actionToTake = () =>
                {
                    if (backupLocation == null)
                    {
                        throw new OptionException("When using --restore-filesystem, --restore-source must be specified", "restore-filesystem");
                    }

                    Uri uri;
                    if (Uri.TryCreate(url, UriKind.Absolute, out uri) == false)
                    {
                        throw new OptionException("Specified destination server url is not valid", "restore-database");
                    }

                    RunRemoteFilesystemRestoreOperation(backupLocation, restoreLocation, restoreFilesystemName, defrag, uri, waitForRestore, restoreStartTimeout);
                    Environment.Exit(0);
                };
                isRestoreAction = true;
            });
            optionSet.Add("restore-disable-replication", OptionCategory.RestoreDatabase, "Disables replication destinations in newly restored database", value =>
            {
                restoreDisableReplication = true;
                requiresRestoreAction.Add("restore-disable-replication");
            });
            optionSet.Add("restore-no-wait", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "Return immediately without waiting for a restore to complete", value =>
            {
                waitForRestore = false;
                requiresRestoreAction.Add("restore-no-wait");
            });
            optionSet.Add("restore-start-timeout=", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "The maximum {0:timeout} in seconds to wait for another restore to complete. Default: 15 seconds.", value =>
            {
                int timeout;
                if (int.TryParse(value, out timeout) == false)
                {
                    throw new OptionException("Specified restore start timeout is not valid", "restore-start-timeout");
                }
                restoreStartTimeout = timeout;
                requiresRestoreAction.Add("restore-start-timeout");
            });
            optionSet.Add("restore-defrag", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "Applicable only during restore, execute defrag after the restore is completed", key =>
            {
                defrag = true;
                requiresRestoreAction.Add("restore-defrag");
            });
            optionSet.Add("restore-destination=", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "The {0:path} of the new database. If not specified it will be located in default data directory", value =>
            {
                restoreLocation = value;
                requiresRestoreAction.Add("restore-destination");
            });
            optionSet.Add("restore-source=", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "The {0:path} of the backup", value =>
            {
                backupLocation = value;
                requiresRestoreAction.Add("restore-source");
            });
            optionSet.Add("restore-database-name=", OptionCategory.RestoreDatabase, "The {0:name} of the new database. If not specified, it will be extracted from backup. Only applicable during REMOTE restore", value =>
            {
                restoreDatabaseName = value;
                requiresRestoreAction.Add("restore-database-name");
            });
            optionSet.Add("restore-filesystem-name", OptionCategory.RestoreFileSystem, "The {0:name} of the new filesystem. If not specified, it will be extracted from backup.", value =>
            {
                restoreFilesystemName = value;
                requiresRestoreAction.Add("restore-filesystem-name");
            });
            optionSet.Add("io-test=", OptionCategory.IOTest, "Performs disk io test using {0:dir} as temporary dir path", path =>
            {
                ioTestRequest.Path = path;
                actionToTake       = () => IoTest(ioTestRequest);
                isIoTestAction     = true;
            });
            optionSet.Add("io-test-file-size=", OptionCategory.IOTest, "The {0:size} of test file for io test in MB (default: 1024MB)", value =>
            {
                int fileSize;
                if (int.TryParse(value, out fileSize) == false)
                {
                    throw new OptionException("Specified test file size is not valid", "io-test-file-size");
                }
                ioTestRequest.FileSize = fileSize * 1024 * 1024;
                requiresIoTestAction.Add("io-test-file-size");
            });
            optionSet.Add("io-test-threads=", OptionCategory.IOTest, "The {0:number} of threads to use during test", value =>
            {
                int threads;
                if (int.TryParse(value, out threads) == false)
                {
                    throw new OptionException("Specified amount of threads is not valid", "io-test-threads");
                }
                ioTestRequest.ThreadCount = threads;
                requiresIoTestAction.Add("io-test-threads");
            });
            optionSet.Add("io-test-time=", OptionCategory.IOTest, "The {0:number} of seconds to run the test (default: 30)", value =>
            {
                int testTime;
                if (int.TryParse(value, out testTime) == false)
                {
                    throw new OptionException("Specified test time is not valid", "io-test-time");
                }
                ioTestRequest.TimeToRunInSeconds = testTime;
                requiresIoTestAction.Add("io-test-time");
            });
            optionSet.Add("io-test-seed=", OptionCategory.IOTest, "The {0:seed} for random generator", value =>
            {
                int seed;
                if (int.TryParse(value, out seed) == false)
                {
                    throw new OptionException("Specified random seed is not valid", "io-test-seed");
                }
                ioTestRequest.RandomSeed = seed;
                requiresIoTestAction.Add("io-test-seed");
            });
            optionSet.Add("io-test-mode=", OptionCategory.IOTest, "The operation {0:mode} (read,write,mix) (default: write)", value =>
            {
                OperationType opType;
                if (Enum.TryParse(value, true, out opType) == false)
                {
                    throw new OptionException("Specified test mode is not valid", "io-test-mode");
                }
                ioTestRequest.OperationType = opType;
                requiresIoTestAction.Add("io-test-mode");
            });
            optionSet.Add("io-test-chunk-size=", OptionCategory.IOTest, "The {0:value} for chunk size in KB (default: 4 KB)", value =>
            {
                int chunkSize;
                if (int.TryParse(value, out chunkSize) == false)
                {
                    throw new OptionException("Specified test chunk size is not valid", "io-test-chunk-size");
                }
                ioTestRequest.ChunkSize = chunkSize * 1024;
                requiresIoTestAction.Add("io-test-chunk-size");
            });
            optionSet.Add("io-test-sequential", OptionCategory.IOTest, "Perform sequential read/write (default: random)", value =>
            {
                ioTestRequest.Sequential = true;
                requiresIoTestAction.Add("io-test-sequential");
            });
            optionSet.Add("io-test-buffering-type", OptionCategory.IOTest, "Buffering type (None,Read, ReadAndWrite) (default: None)", value =>
            {
                BufferingType bufferingType;
                if (Enum.TryParse(value, true, out bufferingType) == false)
                {
                    throw new OptionException("Specified buffering type is not valid", "io-test-buffering-type");
                }
                ioTestRequest.BufferingType = bufferingType;
                requiresIoTestAction.Add("io-test-buffering-type");
            });
            optionSet.Add("encrypt-self-config", OptionCategory.Encryption, "Encrypt the RavenDB configuration file", file =>
            {
                actionToTake = () => ProtectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            });
            optionSet.Add("encrypt-config=", OptionCategory.Encryption, "Encrypt the specified {0:configuration file}", file =>
            {
                actionToTake = () => ProtectConfiguration(file);
            });
            optionSet.Add("decrypt-self-config", OptionCategory.Encryption, "Decrypt the RavenDB configuration file", file =>
            {
                actionToTake = () => UnprotectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            });
            optionSet.Add("decrypt-config=", OptionCategory.Encryption, "Decrypt the specified {0:configuration file}", file =>
            {
                actionToTake = () => UnprotectConfiguration(file);
            });
            optionSet.Add("installSSL={==}", OptionCategory.SSL, "Bind X509 certificate specified in {0:option} with optional password from {1:option} with 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
            {
                actionToTake = () => InstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
            });
            optionSet.Add("uninstallSSL={==}", OptionCategory.SSL, "Unbind X509 certificate specified in {0:option} with optional password from {2:option} from 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
            {
                actionToTake = () => UninstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
            });
            optionSet.Add("update-version=", OptionCategory.Update, "Updates the specified {0:databaseName} to newest version", dbName =>
            {
                actionToTake = () => UpdateVersion(dbName);
            });

            try
            {
                if (args.Length == 0)                 // we default to executing in debug mode
                {
                    args = new[] { "--debug" }
                }
                ;

                optionSet.Parse(args);
            }
            catch (Exception e)
            {
                ConsoleWriteLineWithColor(ConsoleColor.Red, e.Message);
                PrintUsage(optionSet);
                ConsoleWriteLineWithColor(ConsoleColor.Red, e.Message);
                Environment.Exit(-1);
                return;
            }

            if (!isRestoreAction && requiresRestoreAction.Any())
            {
                var joinedActions = string.Join(", ", requiresRestoreAction);
                throw new OptionException(string.Format("When using {0}, --restore-source must be specified", joinedActions), joinedActions);
            }

            if (!isIoTestAction && requiresIoTestAction.Any())
            {
                var joinedActions = string.Join(", ", requiresRestoreAction);
                throw new OptionException(string.Format("When using {0}, --io-test must be specified", joinedActions), joinedActions);
            }

            if (actionToTake == null)
            {
                actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog);
            }

            actionToTake();
        }
Beispiel #2
0
        private static void InteractiveRun(string[] args)
        {
            string backupLocation     = null;
            string restoreLocation    = null;
            Action actionToTake       = null;
            bool   launchBrowser      = false;
            var    ravenConfiguration = new RavenConfiguration();

            OptionSet optionSet = null;

            optionSet = new OptionSet
            {
                { "set={==}", "The configuration {0:option} to set to the specified {1:value}", (key, value) =>
                  {
                      ravenConfiguration.Settings[key] = value;
                      ravenConfiguration.Initialize();
                  } },
                { "config=", "The config {0:file} to use", path => ravenConfiguration.LoadFrom(path) },
                { "install", "Installs the RavenDB service", key => actionToTake = () => AdminRequired(InstallAndStart, key) },
                { "service-name=", "The {0:service name} to use when installing or uninstalling the service, default to RavenDB", name => ProjectInstaller.SERVICE_NAME = name },
                { "uninstall", "Uninstalls the RavenDB service", key => actionToTake = () => AdminRequired(EnsureStoppedAndUninstall, key) },
                { "start", "Starts the RavenDB service", key => actionToTake = () => AdminRequired(StartService, key) },
                { "restart", "Restarts the RavenDB service", key => actionToTake = () => AdminRequired(RestartService, key) },
                { "stop", "Stops the RavenDB service", key => actionToTake = () => AdminRequired(StopService, key) },
                { "ram", "Run RavenDB in RAM only", key =>
                  {
                      ravenConfiguration.Settings["Raven/RunInMemory"] = "true";
                      ravenConfiguration.RunInMemory = true;
                      actionToTake = () => RunInDebugMode(AnonymousUserAccessMode.All, ravenConfiguration, launchBrowser);
                  } },
                { "debug", "Runs RavenDB in debug mode", key => actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser) },
                { "browser|launchbrowser", "After the server starts, launches the browser", key => launchBrowser = true },
                { "help", "Help about the command line interface", key =>
                  {
                      actionToTake = () => PrintUsage(optionSet);
                  } },
                { "config-help", "Help about configuration options", key =>
                  {
                      actionToTake = () => PrintConfig(ravenConfiguration.GetConfigOptionsDocs());
                  } },
                { "restore",
                  "Restores a RavenDB database from backup",
                  key => actionToTake = () =>
                  {
                      if (backupLocation == null || restoreLocation == null)
                      {
                          throw new OptionException("when using restore, source and destination must be specified", "restore");
                      }
                      RunRestoreOperation(backupLocation, restoreLocation);
                  } },
                { "dest=|destination=", "The {0:path} of the new new database", value => restoreLocation = value },
                { "src=|source=", "The {0:path} of the backup", value => backupLocation = value },
                { "encrypt-self-config", "Encrypt the RavenDB configuration file", file =>
                  {
                      actionToTake = () => ProtectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                  } },
                { "encrypt-config=", "Encrypt the specified {0:configuration file}", file =>
                  {
                      actionToTake = () => ProtectConfiguration(file);
                  } },
                { "decrypt-self-config", "Decrypt the RavenDB configuration file", file =>
                  {
                      actionToTake = () => UnprotectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                  } },
                { "decrypt-config=", "Decrypt the specified {0:configuration file}", file =>
                  {
                      actionToTake = () => UnprotectConfiguration(file);
                  } }
            };


            try
            {
                if (args.Length == 0)                 // we default to executing in debug mode
                {
                    args = new[] { "--debug" }
                }
                ;

                optionSet.Parse(args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                PrintUsage(optionSet);
                return;
            }

            if (actionToTake == null)
            {
                actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser);
            }

            actionToTake();
        }
Beispiel #3
0
		private static void InteractiveRun(string[] args)
		{
			var ioTestRequest = new GenericPerformanceTestRequest();

			string backupLocation = null;
			string restoreLocation = null;
			string restoreDatabaseName = null;
			string restoreFilesystemName = null;
			bool restoreDisableReplication = false;
			bool defrag = false;
			var requiresRestoreAction = new HashSet<string>();
			bool isRestoreAction = false;
			var requiresIoTestAction = new HashSet<string>();
			bool isIoTestAction = false;
			Action actionToTake = null;
			bool launchBrowser = false;
			bool noLog = false;
			var ravenConfiguration = new RavenConfiguration();
			bool waitForRestore = true;
			int? restoreStartTimeout = 15;

			var optionSet = new OptionSet();
			optionSet.Add("set={==}", OptionCategory.None, "The configuration {0:option} to set to the specified {1:value}", (key, value) =>
			{
				ravenConfiguration.Settings[key] = value;
				ravenConfiguration.Initialize();
			});
			optionSet.Add("nolog", OptionCategory.General, "Don't use the default log", s => noLog = true);
			optionSet.Add("config=", OptionCategory.General, "The config {0:file} to use", ravenConfiguration.LoadFrom);
			optionSet.Add("install", OptionCategory.Service, "Installs the RavenDB service", key => actionToTake = () => AdminRequired(InstallAndStart));
			optionSet.Add("allow-blank-password-use", OptionCategory.Other, "Allow to log on by using a Windows account that has a blank password", key => actionToTake = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(0)));
			optionSet.Add("deny-blank-password-use", OptionCategory.Other, "Deny to log on by using a Windows account that has a blank password", key => actionToTake = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(1)));
			optionSet.Add("service-name=", OptionCategory.Service, "The {0:service name} to use when installing or uninstalling the service, default to RavenDB", name => ProjectInstaller.SERVICE_NAME = name);
			optionSet.Add("uninstall", OptionCategory.Service, "Uninstalls the RavenDB service", key => actionToTake = () => AdminRequired(EnsureStoppedAndUninstall));
			optionSet.Add("start", OptionCategory.Service, "Starts the RavenDB service", key => actionToTake = () => AdminRequired(StartService));
			optionSet.Add("restart", OptionCategory.Service, "Restarts the RavenDB service", key => actionToTake = () => AdminRequired(RestartService));
			optionSet.Add("stop", OptionCategory.Service, "Stops the RavenDB service", key => actionToTake = () => AdminRequired(StopService));
			optionSet.Add("ram", OptionCategory.General, "Run RavenDB in RAM only", key =>
			{
                ravenConfiguration.Settings[Constants.RunInMemory] = "true";
				ravenConfiguration.RunInMemory = true;
				ravenConfiguration.Initialize();
				actionToTake = () => RunInDebugMode(AnonymousUserAccessMode.Admin, ravenConfiguration, launchBrowser, noLog);
			});
			optionSet.Add("debug", OptionCategory.General, "Run RavenDB in debug mode", key => actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog));
			optionSet.Add("browser|launchbrowser", OptionCategory.General, "After the server starts, launches the browser", key => launchBrowser = true);
			optionSet.Add("help", OptionCategory.Help, "Help about the command line interface", key =>
			{
				actionToTake = () => PrintUsage(optionSet);
			});
			optionSet.Add("config-help", OptionCategory.Help, "Help about configuration databaseOptions", key =>
			{
				actionToTake = () => PrintConfig(ravenConfiguration.GetConfigOptionsDocs());
			});
			optionSet.Add("restore", OptionCategory.RestoreDatabase, "[Obsolete] Use --restore-system-database or --restore-database", key =>
			{
				actionToTake = () =>
				{
					throw new OptionException("This method is obsolete, use --restore-system-database or --restore-database", "restore");
				};
				isRestoreAction = true;
			});
			optionSet.Add("restore-system-database", OptionCategory.RestoreDatabase, "Restores a SYSTEM database from backup.", key =>
			{
				actionToTake = () =>
				{
					if (backupLocation == null || restoreLocation == null)
					{
						throw new OptionException("When using --restore-system-database, --restore-source and --restore-destination must be specified", "restore-system-database");
					}
					RunSystemDatabaseRestoreOperation(backupLocation, restoreLocation, defrag);
				};
				isRestoreAction = true;
			});
			optionSet.Add("restore-database=", OptionCategory.RestoreDatabase, "Starts a restore operation from a backup on a REMOTE server found under specified {0:url}.", url =>
			{
				actionToTake = () =>
				{
					if (backupLocation == null)
					{
						throw new OptionException("When using --restore-database, --restore-source must be specified", "restore-database");
					}

					Uri uri;
					if (Uri.TryCreate(url, UriKind.Absolute, out uri) == false)
					{
						throw new OptionException("Specified destination server url is not valid", "restore-database");
					}

					RunRemoteDatabaseRestoreOperation(backupLocation, restoreLocation, restoreDatabaseName, defrag, restoreDisableReplication, uri, waitForRestore, restoreStartTimeout);
					Environment.Exit(0);
				};
				isRestoreAction = true;
			});
			optionSet.Add("restore-filesystem=", OptionCategory.RestoreFileSystem, "Starts a restore operation from a backup on a REMOTE server found under specified {0:url}.", url =>
			{
				actionToTake = () =>
				{
					if (backupLocation == null)
					{
						throw new OptionException("When using --restore-filesystem, --restore-source must be specified", "restore-filesystem");
					}

					Uri uri;
					if (Uri.TryCreate(url, UriKind.Absolute, out uri) == false)
					{
						throw new OptionException("Specified destination server url is not valid", "restore-database");
					}

					RunRemoteFilesystemRestoreOperation(backupLocation, restoreLocation, restoreFilesystemName, defrag, uri, waitForRestore, restoreStartTimeout);
					Environment.Exit(0);
				};
				isRestoreAction = true;
			});
			optionSet.Add("restore-disable-replication", OptionCategory.RestoreDatabase, "Disables replication destinations in newly restored database", value =>
			{
				restoreDisableReplication = true;
				requiresRestoreAction.Add("restore-disable-replication");
			});
			optionSet.Add("restore-no-wait", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "Return immediately without waiting for a restore to complete", value =>
			{
				waitForRestore = false;
				requiresRestoreAction.Add("restore-no-wait");
			});
			optionSet.Add("restore-start-timeout=", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "The maximum {0:timeout} in seconds to wait for another restore to complete. Default: 15 seconds.", value =>
			{
				int timeout;
				if (int.TryParse(value, out timeout) == false)
				{
					throw new OptionException("Specified restore start timeout is not valid", "restore-start-timeout");
				}
				restoreStartTimeout = timeout;
				requiresRestoreAction.Add("restore-start-timeout");
			});
			optionSet.Add("restore-defrag", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "Applicable only during restore, execute defrag after the restore is completed", key =>
			{
				defrag = true;
				requiresRestoreAction.Add("restore-defrag");
			});
			optionSet.Add("restore-destination=", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "The {0:path} of the new database. If not specified it will be located in default data directory", value =>
			{
				restoreLocation = value;
				requiresRestoreAction.Add("restore-destination");
			});
			optionSet.Add("restore-source=", OptionCategory.RestoreDatabase | OptionCategory.RestoreFileSystem, "The {0:path} of the backup", value =>
			{
				backupLocation = value;
				requiresRestoreAction.Add("restore-source");
			});
			optionSet.Add("restore-database-name=", OptionCategory.RestoreDatabase, "The {0:name} of the new database. If not specified, it will be extracted from backup. Only applicable during REMOTE restore", value =>
			{
				restoreDatabaseName = value;
				requiresRestoreAction.Add("restore-database-name");
			});
			optionSet.Add("restore-filesystem-name", OptionCategory.RestoreFileSystem, "The {0:name} of the new filesystem. If not specified, it will be extracted from backup.", value =>
			{
				restoreFilesystemName = value;
				requiresRestoreAction.Add("restore-filesystem-name");
			});
			optionSet.Add("io-test=", OptionCategory.IOTest, "Performs disk io test using {0:dir} as temporary dir path", path =>
			{
				ioTestRequest.Path = path;
				actionToTake = () => IoTest(ioTestRequest);
				isIoTestAction = true;
			});
			optionSet.Add("io-test-file-size=", OptionCategory.IOTest, "The {0:size} of test file for io test in MB (default: 1024MB)", value =>
			{
				int fileSize;
				if (int.TryParse(value, out fileSize) == false)
				{
					throw new OptionException("Specified test file size is not valid", "io-test-file-size");
				}
				ioTestRequest.FileSize = fileSize * 1024 * 1024;
				requiresIoTestAction.Add("io-test-file-size");
			});
			optionSet.Add("io-test-threads=", OptionCategory.IOTest, "The {0:number} of threads to use during test", value =>
			{
				int threads;
				if (int.TryParse(value, out threads) == false)
				{
					throw new OptionException("Specified amount of threads is not valid", "io-test-threads");
				}
				ioTestRequest.ThreadCount = threads;
				requiresIoTestAction.Add("io-test-threads");
			});
			optionSet.Add("io-test-time=", OptionCategory.IOTest, "The {0:number} of seconds to run the test (default: 30)", value =>
			{
				int testTime;
				if (int.TryParse(value, out testTime) == false)
				{
					throw new OptionException("Specified test time is not valid", "io-test-time");
				}
				ioTestRequest.TimeToRunInSeconds = testTime;
				requiresIoTestAction.Add("io-test-time");
			});
			optionSet.Add("io-test-seed=", OptionCategory.IOTest, "The {0:seed} for random generator", value =>
			{
				int seed;
				if (int.TryParse(value, out seed) == false)
				{
					throw new OptionException("Specified random seed is not valid", "io-test-seed");
				}
				ioTestRequest.RandomSeed = seed;
				requiresIoTestAction.Add("io-test-seed");
			});
			optionSet.Add("io-test-mode=", OptionCategory.IOTest, "The operation {0:mode} (read,write,mix) (default: write)", value =>
			{
				OperationType opType;
				if (Enum.TryParse(value, true, out opType) == false)
				{
					throw new OptionException("Specified test mode is not valid", "io-test-mode");
				}
				ioTestRequest.OperationType = opType;
				requiresIoTestAction.Add("io-test-mode");
			});
			optionSet.Add("io-test-chunk-size=", OptionCategory.IOTest, "The {0:value} for chunk size in KB (default: 4 KB)", value =>
			{
				int chunkSize;
				if (int.TryParse(value, out chunkSize) == false)
				{
					throw new OptionException("Specified test chunk size is not valid", "io-test-chunk-size");
				}
				ioTestRequest.ChunkSize = chunkSize * 1024;
				requiresIoTestAction.Add("io-test-chunk-size");
			});
			optionSet.Add("io-test-sequential", OptionCategory.IOTest, "Perform sequential read/write (default: random)", value =>
			{
				ioTestRequest.Sequential = true;
				requiresIoTestAction.Add("io-test-sequential");
			});
			optionSet.Add("io-test-buffering-type", OptionCategory.IOTest, "Buffering type (None,Read, ReadAndWrite) (default: None)", value =>
			{
				BufferingType bufferingType;
				if (Enum.TryParse(value, true, out bufferingType) == false)
				{
					throw new OptionException("Specified buffering type is not valid", "io-test-buffering-type");
				}
				ioTestRequest.BufferingType = bufferingType;
				requiresIoTestAction.Add("io-test-buffering-type");
			});
			optionSet.Add("encrypt-self-config", OptionCategory.Encryption, "Encrypt the RavenDB configuration file", file =>
			{
				actionToTake = () => ProtectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
			});
			optionSet.Add("encrypt-config=", OptionCategory.Encryption, "Encrypt the specified {0:configuration file}", file =>
			{
				actionToTake = () => ProtectConfiguration(file);
			});
			optionSet.Add("decrypt-self-config", OptionCategory.Encryption, "Decrypt the RavenDB configuration file", file =>
			{
				actionToTake = () => UnprotectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
			});
			optionSet.Add("decrypt-config=", OptionCategory.Encryption, "Decrypt the specified {0:configuration file}", file =>
			{
				actionToTake = () => UnprotectConfiguration(file);
			});
			optionSet.Add("installSSL={==}", OptionCategory.SSL, "Bind X509 certificate specified in {0:option} with optional password from {1:option} with 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
			{
				actionToTake = () => InstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
			});
			optionSet.Add("uninstallSSL={==}", OptionCategory.SSL, "Unbind X509 certificate specified in {0:option} with optional password from {2:option} from 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
			{
				actionToTake = () => UninstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
			});
			optionSet.Add("update-version=", OptionCategory.Update, "Updates the specified {0:databaseName} to newest version", dbName =>
			{
				actionToTake = () => UpdateVersion(dbName);
			});

			try
			{
				if (args.Length == 0) // we default to executing in debug mode 
					args = new[] { "--debug" };

				optionSet.Parse(args);
			}
			catch (Exception e)
			{
				ConsoleWriteLineWithColor(ConsoleColor.Red, e.Message);
				PrintUsage(optionSet);
				ConsoleWriteLineWithColor(ConsoleColor.Red, e.Message);
				Environment.Exit(-1);
				return;
			}

			if (!isRestoreAction && requiresRestoreAction.Any())
			{
				var joinedActions = string.Join(", ", requiresRestoreAction);
				throw new OptionException(string.Format("When using {0}, --restore-source must be specified", joinedActions), joinedActions);
			}

			if (!isIoTestAction && requiresIoTestAction.Any())
			{
				var joinedActions = string.Join(", ", requiresRestoreAction);
				throw new OptionException(string.Format("When using {0}, --io-test must be specified", joinedActions), joinedActions);
			}

			if (actionToTake == null)
				actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog);

			actionToTake();
		}
Beispiel #4
0
        private static void InteractiveRun(string[] args)
        {
            string backupLocation     = null;
            string restoreLocation    = null;
            bool   defrag             = false;
            string theUser            = null;
            Action actionToTake       = null;
            bool   launchBrowser      = false;
            bool   noLog              = false;
            var    ravenConfiguration = new RavenConfiguration();

            OptionSet optionSet = null;

            optionSet = new OptionSet
            {
                { "set={==}", "The configuration {0:option} to set to the specified {1:value}", (key, value) =>
                  {
                      ravenConfiguration.Settings[key] = value;
                      ravenConfiguration.Initialize();
                  } },
                { "nolog", "Don't use the default log", s => noLog = true },
                { "config=", "The config {0:file} to use", ravenConfiguration.LoadFrom },
                { "install", "Installs the RavenDB service", key => actionToTake = () => AdminRequired(InstallAndStart) },
                { "user="******"Which user will be used", user => theUser = user },
                { "setup-perf-counters", "Setup the performance counters and the related permissions", key => actionToTake = () => AdminRequired(() => SetupPerfCounters(theUser)) },
                { "allow-blank-password-use", "Allow to log on by using a Windows account that has a blank password", key => actionToTake = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(0)) },
                { "deny-blank-password-use", "Deny to log on by using a Windows account that has a blank password", key => actionToTake = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(1)) },
                { "service-name=", "The {0:service name} to use when installing or uninstalling the service, default to RavenDB", name => ProjectInstaller.SERVICE_NAME = name },
                { "uninstall", "Uninstalls the RavenDB service", key => actionToTake = () => AdminRequired(EnsureStoppedAndUninstall) },
                { "start", "Starts the RavenDB service", key => actionToTake = () => AdminRequired(StartService) },
                { "restart", "Restarts the RavenDB service", key => actionToTake = () => AdminRequired(RestartService) },
                { "stop", "Stops the RavenDB service", key => actionToTake = () => AdminRequired(StopService) },
                { "ram", "Run RavenDB in RAM only", key =>
                  {
                      ravenConfiguration.Settings["Raven/RunInMemory"] = "true";
                      ravenConfiguration.RunInMemory = true;
                      actionToTake = () => RunInDebugMode(AnonymousUserAccessMode.Admin, ravenConfiguration, launchBrowser, noLog);
                  } },
                { "debug", "Runs RavenDB in debug mode", key => actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog) },
                { "browser|launchbrowser", "After the server starts, launches the browser", key => launchBrowser = true },
                { "help", "Help about the command line interface", key =>
                  {
                      actionToTake = () => PrintUsage(optionSet);
                  } },
                { "config-help", "Help about configuration options", key =>
                  {
                      actionToTake = () => PrintConfig(ravenConfiguration.GetConfigOptionsDocs());
                  } },
                { "restore",
                  "Restores a RavenDB database from backup",
                  key => actionToTake = () =>
                  {
                      if (backupLocation == null || restoreLocation == null)
                      {
                          throw new OptionException("when using restore, source and destination must be specified", "restore");
                      }
                      RunRestoreOperation(backupLocation, restoreLocation, defrag);
                  } },
                { "defrag",
                  "Applicable only during restore, execute defrag after the restore is completed", key =>
                  {
                      defrag = true;
                  } },
                { "dest=|destination=", "The {0:path} of the new new database", value => restoreLocation = value },
                { "src=|source=", "The {0:path} of the backup", value => backupLocation = value },
                { "encrypt-self-config", "Encrypt the RavenDB configuration file", file =>
                  {
                      actionToTake = () => ProtectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                  } },
                { "encrypt-config=", "Encrypt the specified {0:configuration file}", file =>
                  {
                      actionToTake = () => ProtectConfiguration(file);
                  } },
                { "decrypt-self-config", "Decrypt the RavenDB configuration file", file =>
                  {
                      actionToTake = () => UnprotectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                  } },
                { "decrypt-config=", "Decrypt the specified {0:configuration file}", file =>
                  {
                      actionToTake = () => UnprotectConfiguration(file);
                  } },
                { "installSSL={==}", "Bind X509 certificate specified in {0:option} with optional password from {1:option} with 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
                  {
                      actionToTake = () => InstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
                  } },
                { "uninstallSSL={==}", "Unbind X509 certificate specified in {0:option} with optional password from {2:option} from 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
                  {
                      actionToTake = () => UninstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
                  } }
            };


            try
            {
                if (args.Length == 0)                 // we default to executing in debug mode
                {
                    args = new[] { "--debug" }
                }
                ;

                optionSet.Parse(args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                PrintUsage(optionSet);
                return;
            }

            if (actionToTake == null)
            {
                actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog);
            }

            actionToTake();
        }
Beispiel #5
0
		private static void InteractiveRun(string[] args)
		{
			string backupLocation = null;
			string restoreLocation = null;
			bool defrag = false;
			string theUser = null;
			Action actionToTake = null;
			bool launchBrowser = false;
			var ravenConfiguration = new RavenConfiguration();

			OptionSet optionSet = null;
			optionSet = new OptionSet
			{
				{"set={==}", "The configuration {0:option} to set to the specified {1:value}" , (key, value) =>
				{
					ravenConfiguration.Settings[key] = value;
					ravenConfiguration.Initialize();
				}},
				{"config=", "The config {0:file} to use", path => ravenConfiguration.LoadFrom(path)},
				{"install", "Installs the RavenDB service", key => actionToTake= () => AdminRequired(InstallAndStart)},
				{"user="******"Which user will be used", user=> theUser = user},
				{"setup-perf-counters", "Setup the performance counters and the related permissions", key => actionToTake = ()=> AdminRequired(()=>SetupPerfCounters(theUser))},
				{"service-name=", "The {0:service name} to use when installing or uninstalling the service, default to RavenDB", name => ProjectInstaller.SERVICE_NAME = name},
				{"uninstall", "Uninstalls the RavenDB service", key => actionToTake= () => AdminRequired(EnsureStoppedAndUninstall)},
				{"start", "Starts the RavenDB service", key => actionToTake= () => AdminRequired(StartService)},
				{"restart", "Restarts the RavenDB service", key => actionToTake= () => AdminRequired(RestartService)},
				{"stop", "Stops the RavenDB service", key => actionToTake= () => AdminRequired(StopService)},
				{"ram", "Run RavenDB in RAM only", key =>
				{
					ravenConfiguration.Settings["Raven/RunInMemory"] = "true";
					ravenConfiguration.RunInMemory = true;
					actionToTake = () => RunInDebugMode(AnonymousUserAccessMode.All, ravenConfiguration, launchBrowser);		
				}},
				{"debug", "Runs RavenDB in debug mode", key => actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser)},
				{"browser|launchbrowser", "After the server starts, launches the browser", key => launchBrowser = true},
				{"help", "Help about the command line interface", key =>
				{
					actionToTake = () => PrintUsage(optionSet);
				}},
				{"config-help", "Help about configuration options", key=>
				{
					actionToTake = () => PrintConfig(ravenConfiguration.GetConfigOptionsDocs());
				}},
				{"restore", 
					"Restores a RavenDB database from backup",
					key => actionToTake = () =>
					{
						if(backupLocation == null || restoreLocation == null)
						{
							throw new OptionException("when using restore, source and destination must be specified", "restore");
						}
						RunRestoreOperation(backupLocation, restoreLocation, defrag);
					}},
				{"defrag", 
					"Applicable only during restore, execute defrag after the restore is completed", key =>
					{
						defrag = true;
					}},
				{"dest=|destination=", "The {0:path} of the new new database", value => restoreLocation = value},
				{"src=|source=", "The {0:path} of the backup", value => backupLocation = value},
				{"encrypt-self-config", "Encrypt the RavenDB configuration file", file =>
						{
							actionToTake = () => ProtectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
						}},
				{"encrypt-config=", "Encrypt the specified {0:configuration file}", file =>
						{
							actionToTake = () => ProtectConfiguration(file);
						}},
				{"decrypt-self-config", "Decrypt the RavenDB configuration file", file =>
						{
							actionToTake = () => UnprotectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
						}},
				{"decrypt-config=", "Decrypt the specified {0:configuration file}", file =>
						{
							actionToTake = () => UnprotectConfiguration(file);
						}}
			};


			try
			{
				if (args.Length == 0) // we default to executing in debug mode 
					args = new[] { "--debug" };

				optionSet.Parse(args);
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				PrintUsage(optionSet);
				return;
			}

			if (actionToTake == null)
				actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser);

			actionToTake();

		}
Beispiel #6
0
		private static void InteractiveRun(string[] args)
		{
			string backupLocation = null;
			string restoreLocation = null;
			string restoreDatabaseName = null;
		    string restoreFilesystemName = null;
			bool defrag = false;
            var requiresRestoreAction = new HashSet<string>();
		    bool isRestoreAction = false;
			Action actionToTake = null;
			bool launchBrowser = false;
			bool noLog = false;
			var ravenConfiguration = new RavenConfiguration();
		    bool waitForRestore = true;
		    int? restoreStartTimeout = 15;

			OptionSet optionSet = null;
			optionSet = new OptionSet
			{
				{"set={==}", "The configuration {0:option} to set to the specified {1:value}" , (key, value) =>
				{
					ravenConfiguration.Settings[key] = value;
					ravenConfiguration.Initialize();
				}},
				{"nolog", "Don't use the default log", s => noLog=true},
				{"config=", "The config {0:file} to use", ravenConfiguration.LoadFrom},
				{"install", "Installs the RavenDB service", key => actionToTake= () => AdminRequired(InstallAndStart)},
				{"allow-blank-password-use", "Allow to log on by using a Windows account that has a blank password", key => actionToTake = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(0))},
				{"deny-blank-password-use", "Deny to log on by using a Windows account that has a blank password", key => actionToTake = () =>  AdminRequired(() => SetLimitBlankPasswordUseRegValue(1))},
				{"service-name=", "The {0:service name} to use when installing or uninstalling the service, default to RavenDB", name => ProjectInstaller.SERVICE_NAME = name},
				{"uninstall", "Uninstalls the RavenDB service", key => actionToTake= () => AdminRequired(EnsureStoppedAndUninstall)},
				{"start", "Starts the RavenDB service", key => actionToTake= () => AdminRequired(StartService)},
				{"restart", "Restarts the RavenDB service", key => actionToTake= () => AdminRequired(RestartService)},
				{"stop", "Stops the RavenDB service", key => actionToTake= () => AdminRequired(StopService)},
				{"ram", "Run RavenDB in RAM only", key =>
				{
					ravenConfiguration.Settings["Raven/RunInMemory"] = "true";
					ravenConfiguration.RunInMemory = true;
					ravenConfiguration.Initialize();
					actionToTake = () => RunInDebugMode(AnonymousUserAccessMode.Admin, ravenConfiguration, launchBrowser, noLog);		
				}},
				{"debug", "Runs RavenDB in debug mode", key => actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog)},
				{"browser|launchbrowser", "After the server starts, launches the browser", key => launchBrowser = true},
				{"help", "Help about the command line interface", key =>
				{
					actionToTake = () => PrintUsage(optionSet);
				}},
				{"config-help", "Help about configuration options", key=>
				{
					actionToTake = () => PrintConfig(ravenConfiguration.GetConfigOptionsDocs());
				}},
				{"restore", "[Obsolete] Use --restore-system-database or --restore-database",
					key =>
					{
					    actionToTake = () =>
					    {
					        throw new OptionException("This method is obsolete, use --restore-system-database or --restore-database", "restore");
					    };
					    isRestoreAction = true;
					}
				},
				{"restore-system-database", "Restores a SYSTEM database from backup.",
					key =>
					{
					    actionToTake = () =>
					    {
					        if (backupLocation == null || restoreLocation == null)
					        {
					            throw new OptionException("when using --restore-system-database, --restore-source and --restore-destination must be specified", "restore-system-database");
					        }
					        RunSystemDatabaseRestoreOperation(backupLocation, restoreLocation, defrag);
					    };
					    isRestoreAction = true;
					}
				},
				{"restore-database=", "Starts a restore operation from a backup on a REMOTE server found under specified {0:url}.", 
					url =>
					{
					    actionToTake = () =>
					    {
					        if (backupLocation == null)
					        {
					            throw new OptionException("when using --restore-database, --restore-source must be specified", "restore-database");
					        }

					        Uri uri;
					        if (Uri.TryCreate(url, UriKind.Absolute, out uri) == false)
					        {
					            throw new OptionException("specified destination server url is not valid", "restore-database");
					        }

					        RunRemoteDatabaseRestoreOperation(backupLocation, restoreLocation, restoreDatabaseName, defrag, uri, waitForRestore, restoreStartTimeout);
					        Environment.Exit(0);
					    };
					    isRestoreAction = true;
					}
				},
                {"restore-filesystem=", "Starts a restore operation from a backup on a REMOTE server found under specified {0:url}.",
                    url =>
                    {
                        actionToTake = () =>
                        {
                            if (backupLocation == null)
                            {
                                throw new OptionException("when using --restore-filesystem, --restore-source must be specified", "restore-filesystem");
                            }

                            Uri uri;
                            if (Uri.TryCreate(url, UriKind.Absolute, out uri) == false)
                            {
                                throw new OptionException("specified destination server url is not valid", "restore-database");
                            }

                            RunRemoteFilesystemRestoreOperation(backupLocation, restoreLocation, restoreFilesystemName, defrag, uri, waitForRestore, restoreStartTimeout);
                            Environment.Exit(0);
                        };
                        isRestoreAction = true;
                    }
                },
				{
				    "restore-no-wait", "Return immediately without waiting for a restore to complete", value =>
				    {
				        waitForRestore = false;
				        requiresRestoreAction.Add("restore-no-wait");
				    }
				},
                { "restore-start-timeout=", "The maximum {0:timeout} in seconds to wait for another restore to complete. Default: 15 seconds.", value =>
                {
                    int timeout;
                    if (int.TryParse(value, out timeout) == false)
                    {
                        throw new OptionException("specified restore start timeout is not valid", "restore-start-timeout");
                    }
                    restoreStartTimeout = timeout;
                    requiresRestoreAction.Add("restore-start-timeout");
                }},
				{"restore-defrag", 
					"Applicable only during restore, execute defrag after the restore is completed", key =>
					{
						defrag = true;
					    requiresRestoreAction.Add("restore-defrag");
					}},
				{"restore-destination=", "The {0:path} of the new database. If not specified it will be located in default data directory", value =>
				{
				    restoreLocation = value;
				    requiresRestoreAction.Add("restore-destination");
				}},
				{"restore-source=", "The {0:path} of the backup", value =>
				{
				    backupLocation = value;
				    requiresRestoreAction.Add("restore-source");
				}},
				{"restore-database-name=", "The {0:name} of the new database. If not specified, it will be extracted from backup. Only applicable during REMOTE restore", value =>
				{
				    restoreDatabaseName = value;
				    requiresRestoreAction.Add("restore-database-name");
				}},
                {"restore-filesystem-name", "The {0:name} of the new filesystem. If not specified, it will be extracted from backup.", value =>
                {
                    restoreFilesystemName = value;
                    requiresRestoreAction.Add("restore-filesystem-name");
                }},
				{"encrypt-self-config", "Encrypt the RavenDB configuration file", file =>
						{
							actionToTake = () => ProtectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
						}},
				{"encrypt-config=", "Encrypt the specified {0:configuration file}", file =>
						{
							actionToTake = () => ProtectConfiguration(file);
						}},
				{"decrypt-self-config", "Decrypt the RavenDB configuration file", file =>
						{
							actionToTake = () => UnprotectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
						}},
				{"decrypt-config=", "Decrypt the specified {0:configuration file}", file =>
						{
							actionToTake = () => UnprotectConfiguration(file);
						}},
				{"installSSL={==}", "Bind X509 certificate specified in {0:option} with optional password from {1:option} with 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
						{
							actionToTake = () => InstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
						}},
				{"uninstallSSL={==}", "Unbind X509 certificate specified in {0:option} with optional password from {2:option} from 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
						{
							actionToTake = () => UninstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
						}},
                {"update-version=", "Updates the specified {0:databaseName} to newest version", dbName =>
                    {
                        actionToTake = () => UpdateVersion(dbName);
                    }}
			};


			try
			{
				if (args.Length == 0) // we default to executing in debug mode 
					args = new[] { "--debug" };

				optionSet.Parse(args);
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				PrintUsage(optionSet);
				return;
			}

            if (!isRestoreAction && requiresRestoreAction.Any())
            {
                var joinedActions = string.Join(", ", requiresRestoreAction);
                throw new OptionException(string.Format("when using {0}, --restore-source must be specified", joinedActions), joinedActions);
            }

			if (actionToTake == null)
				actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog);

			actionToTake();

		}
Beispiel #7
0
        private static void InteractiveRun(string[] args)
        {
            string backupLocation        = null;
            string restoreLocation       = null;
            string restoreDatabaseName   = null;
            string restoreFilesystemName = null;
            bool   defrag             = false;
            Action actionToTake       = null;
            bool   launchBrowser      = false;
            bool   noLog              = false;
            var    ravenConfiguration = new RavenConfiguration();

            OptionSet optionSet = null;

            optionSet = new OptionSet
            {
                { "set={==}", "The configuration {0:option} to set to the specified {1:value}", (key, value) =>
                  {
                      ravenConfiguration.Settings[key] = value;
                      ravenConfiguration.Initialize();
                  } },
                { "nolog", "Don't use the default log", s => noLog = true },
                { "config=", "The config {0:file} to use", ravenConfiguration.LoadFrom },
                { "install", "Installs the RavenDB service", key => actionToTake = () => AdminRequired(InstallAndStart) },
                { "allow-blank-password-use", "Allow to log on by using a Windows account that has a blank password", key => actionToTake = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(0)) },
                { "deny-blank-password-use", "Deny to log on by using a Windows account that has a blank password", key => actionToTake = () => AdminRequired(() => SetLimitBlankPasswordUseRegValue(1)) },
                { "service-name=", "The {0:service name} to use when installing or uninstalling the service, default to RavenDB", name => ProjectInstaller.SERVICE_NAME = name },
                { "uninstall", "Uninstalls the RavenDB service", key => actionToTake = () => AdminRequired(EnsureStoppedAndUninstall) },
                { "start", "Starts the RavenDB service", key => actionToTake = () => AdminRequired(StartService) },
                { "restart", "Restarts the RavenDB service", key => actionToTake = () => AdminRequired(RestartService) },
                { "stop", "Stops the RavenDB service", key => actionToTake = () => AdminRequired(StopService) },
                { "ram", "Run RavenDB in RAM only", key =>
                  {
                      ravenConfiguration.Settings["Raven/RunInMemory"] = "true";
                      ravenConfiguration.RunInMemory = true;
                      ravenConfiguration.Initialize();
                      actionToTake = () => RunInDebugMode(AnonymousUserAccessMode.Admin, ravenConfiguration, launchBrowser, noLog);
                  } },
                { "debug", "Runs RavenDB in debug mode", key => actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog) },
                { "browser|launchbrowser", "After the server starts, launches the browser", key => launchBrowser = true },
                { "help", "Help about the command line interface", key =>
                  {
                      actionToTake = () => PrintUsage(optionSet);
                  } },
                { "config-help", "Help about configuration options", key =>
                  {
                      actionToTake = () => PrintConfig(ravenConfiguration.GetConfigOptionsDocs());
                  } },
                { "restore", "[Obsolete] Use --restore-system-database or --restore-database",
                  key => actionToTake = () =>
                  {
                      throw new OptionException("This method is obsolete, use --restore-system-database or --restore-database", "restore");
                  } },
                { "restore-system-database", "Restores a SYSTEM database from backup.",
                  key => actionToTake = () =>
                  {
                      if (backupLocation == null || restoreLocation == null)
                      {
                          throw new OptionException("when using --restore-system-database, --restore-source and --restore-destination must be specified", "restore-system-database");
                      }

                      RunSystemDatabaseRestoreOperation(backupLocation, restoreLocation, defrag);
                  } },
                { "restore-database=", "Starts a restore operation from a backup on a REMOTE server found under specified {0:url}.",
                  url => actionToTake = () =>
                  {
                      if (backupLocation == null)
                      {
                          throw new OptionException("when using --restore-database, --restore-source must be specified", "restore-database");
                      }

                      Uri uri;
                      if (Uri.TryCreate(url, UriKind.Absolute, out uri) == false)
                      {
                          throw new OptionException("specified destination server url is not valid", "restore-database");
                      }

                      RunRemoteDatabaseRestoreOperation(backupLocation, restoreLocation, restoreDatabaseName, defrag, uri);
                      Environment.Exit(0);
                  } },
                { "restore-filesystem=", "Starts a restore operation from a backup on a REMOTE server found under specified {0:url}.",
                  url => actionToTake = () =>
                  {
                      if (backupLocation == null)
                      {
                          throw new OptionException("when using --restore-filesystem, --restore-source must be specified", "restore-filesystem");
                      }

                      Uri uri;
                      if (Uri.TryCreate(url, UriKind.Absolute, out uri) == false)
                      {
                          throw new OptionException("specified destination server url is not valid", "restore-database");
                      }

                      RunRemoteFilesystemRestoreOperation(backupLocation, restoreLocation, restoreFilesystemName, defrag, uri);
                      Environment.Exit(0);
                  } },
                { "restore-defrag",
                  "Applicable only during restore, execute defrag after the restore is completed", key =>
                  {
                      defrag = true;
                  } },
                { "restore-destination=", "The {0:path} of the new database. If not specified it will be located in default data directory", value => restoreLocation = value },
                { "restore-source=", "The {0:path} of the backup", value => backupLocation = value },
                { "restore-database-name=", "The {0:name} of the new database. If not specified, it will be extracted from backup. Only applicable during REMOTE restore", value => restoreDatabaseName = value },
                { "restore-filesystem-name", "The {0:name} of the new filesystem. If not specified, it will be extracted from backup.", value => restoreFilesystemName = value },
                { "encrypt-self-config", "Encrypt the RavenDB configuration file", file =>
                  {
                      actionToTake = () => ProtectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                  } },
                { "encrypt-config=", "Encrypt the specified {0:configuration file}", file =>
                  {
                      actionToTake = () => ProtectConfiguration(file);
                  } },
                { "decrypt-self-config", "Decrypt the RavenDB configuration file", file =>
                  {
                      actionToTake = () => UnprotectConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                  } },
                { "decrypt-config=", "Decrypt the specified {0:configuration file}", file =>
                  {
                      actionToTake = () => UnprotectConfiguration(file);
                  } },
                { "installSSL={==}", "Bind X509 certificate specified in {0:option} with optional password from {1:option} with 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
                  {
                      actionToTake = () => InstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
                  } },
                { "uninstallSSL={==}", "Unbind X509 certificate specified in {0:option} with optional password from {2:option} from 'Raven/Port'.", (sslCertificateFile, sslCertificatePassword) =>
                  {
                      actionToTake = () => UninstallSsl(sslCertificateFile, sslCertificatePassword, ravenConfiguration);
                  } },
                { "update-version=", "Updates the specified {0:databaseName} to newest version", dbName =>
                  {
                      actionToTake = () => UpdateVersion(dbName);
                  } }
            };


            try
            {
                if (args.Length == 0)                 // we default to executing in debug mode
                {
                    args = new[] { "--debug" }
                }
                ;

                optionSet.Parse(args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                PrintUsage(optionSet);
                return;
            }

            if (actionToTake == null)
            {
                actionToTake = () => RunInDebugMode(null, ravenConfiguration, launchBrowser, noLog);
            }

            actionToTake();
        }