/// <summary> /// Initializes a new instance of the <see cref="DatabaseInitialiser"/> class. /// </summary> /// <param name="mongoConfiguration">The MongoDB configuration settings.</param> /// <param name="installOptions">The database install options.</param> /// <param name="variables">A cache of install variables.</param> /// <param name="installLogger">Logs installation results.</param> public DatabaseInitialiser(IMongoConfiguration mongoConfiguration, DatabaseInitialiserOptions installOptions, InstallVariables variables, InstallLogger installLogger) { this.mongoConfiguration = mongoConfiguration; this.installConfiguration = installOptions; this.installVariables = variables; this.installLogger = installLogger; this.ReadInput = delegate { return string.Empty; }; this.ReadPassword = delegate { return string.Empty; }; }
public string Init(string hostName, string orgName, string adminEmail, string adminPassword, string smtp) { try { if (this.workbenchManager.GetBaseOrganisation() != null) { throw new InvalidOperationException(); } IMongoConfiguration mongoConfiguration = Global.DependencyInjectionContainer.Resolve<IMongoConfiguration>(); DatabaseInitialiserOptions dbInitOptions = new DatabaseInitialiserOptions { WebsiteName = hostName, OrgName = orgName, AdminEmail = adminEmail, AdminPassword = adminPassword }; InstallVariables variables = new InstallVariables(); DatabaseInitialiser dbManager = new DatabaseInitialiser(mongoConfiguration, dbInitOptions, variables, new InstallLogger(true)); if (RoleEnvironment.IsAvailable) { dbManager.ServiceAccountCreated += this.ServiceAccountCreatedAzure; JObject jobject = JObject.Parse(smtp); this.SmtpAzure(jobject); this.CryptoAzure(); } dbManager.Run(); return JsonConvert.SerializeObject(new { }); } catch (Exception e) { bool rethrow = ExceptionPolicy.HandleException(e, "Default"); if (rethrow) { throw; } Context.Response.Clear(); Context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; Context.Response.TrySkipIisCustomErrors = true; return JsonConvert.SerializeObject(new { e.Message, SessionExpired = false }); } }
/// <summary> /// Run the installation / uninstallation process. /// </summary> /// <param name="options">The install options.</param> private void Run(InstallOptions options) { int exitCode = 0; this.installOptions = options; try { if (string.IsNullOrEmpty(this.installOptions.LogFileRelative)) { this.installOptions.LogFileAbsolute = this.installOptions.Mode + ".log"; } installLogger.SetLogFile(options.LogFileAbsolute); if (!this.IsUserAdministrator()) { throw new UnauthorizedAccessException(Messages.MAIN_AdminRequired); } this.installVariables.BasePath = this.FindBasePath(); this.CheckParameters(options); this.webManager = new WebManager(this.installOptions, this.installVariables, installLogger); this.taskManager = new ScheduledTaskManager(this.installOptions, this.installVariables, installLogger); if (options.Mode != InstallerMode.Uninstall) { IMongoConfiguration mongoConfiguration = new MongoConfiguration { Host = this.installOptions.MongoHost, Port = this.installOptions.MongoPort.Value, Database = this.installOptions.MongoDatabase, Username = this.installOptions.MongoUsername, Password = this.installOptions.MongoPassword }; var websiteName = this.installOptions.WebsiteName; if (this.installOptions.RootSite != null) { websiteName = string.Format("{0}/{1}", this.installOptions.HostName, this.installOptions.WebsiteName); } DatabaseInitialiserOptions dbInitOptions = new DatabaseInitialiserOptions { WebsiteName = websiteName, OrgName = this.installOptions.OrgName, AdminEmail = this.installOptions.AdminEmail, AdminPassword = this.installOptions.AdminPassword }; this.dbManager = new DatabaseInitialiser(mongoConfiguration, dbInitOptions, this.installVariables, installLogger) { ReadInput = this.ReadInput, ReadPassword = this.ReadInput }; } if (options.Mode == InstallerMode.Install) { this.RunInstall(options.Type); } if (options.Mode == InstallerMode.Repair) { this.dbManager.Run(); } if (options.Mode != InstallerMode.Uninstall) { if (options.Api && !string.IsNullOrEmpty(this.installOptions.IapplyWebsiteName)) { this.installOptions.WebsiteName = this.installOptions.IapplyWebsiteName; } ConfigurationUpdater updater = new ConfigurationUpdater(this.installOptions, this.installVariables); updater.UpdateXmlConfig(options.Type); updater.UpdateJsConfig(options.Type); updater.WriteDbConfig(); if (options.Mode != InstallerMode.Repair) { updater.GenerateNewCryptoKeys(); } installLogger.LogLine(Messages.MAIN_InstallationComplete); } if (options.Mode == InstallerMode.Uninstall) { this.RunUninstall(options.Type); } } catch (Exception e) { installLogger.LogError(e); exitCode = 1; } if (!this.installOptions.Quiet) { Console.Write(Environment.NewLine + Strings.PressAnyKey); Console.ReadKey(); } Environment.Exit(exitCode); }