public async Task <JsonResult> Install(InstallModel model) { var t = AsyncRunner.Run( (c, ct, state) => InstallCore(c, (InstallModel)state), model, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); return(Json(await t)); }
public void ShouldHaveErrorWhenConfirmPasswordIsNullOrEmpty() { var model = new InstallModel { ConfirmPassword = null }; _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.ConfirmPassword); model.ConfirmPassword = string.Empty; _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.ConfirmPassword); }
public void ShouldNotHaveErrorWhenPasswordIsSpecified() { var model = new InstallModel { AdminPassword = "******" }; //we know that password should equal confirmation password model.ConfirmPassword = model.AdminPassword; _validator.TestValidate(model).ShouldNotHaveValidationErrorFor(x => x.AdminPassword); }
public void Should_have_error_when_adminEmail_is_null_or_empty() { var model = new InstallModel { AdminEmail = null }; _validator.ShouldHaveValidationErrorFor(x => x.AdminEmail, model); model.AdminEmail = ""; _validator.ShouldHaveValidationErrorFor(x => x.AdminEmail, model); }
public void Should_have_error_when_confirmPassword_is_null_or_empty() { var model = new InstallModel { ConfirmPassword = null }; _validator.ShouldHaveValidationErrorFor(x => x.ConfirmPassword, model); model.ConfirmPassword = ""; _validator.ShouldHaveValidationErrorFor(x => x.ConfirmPassword, model); }
public void ShouldHaveErrorWhenAdminEmailIsNullOrEmpty() { var model = new InstallModel { AdminEmail = null }; _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.AdminEmail); model.AdminEmail = string.Empty; _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.AdminEmail); }
public PackageEditorDemo() { InitializeComponent(); _model = ModelUtils.GetTestModel(); this.packagesListControl1.SetModel(_model); this.packagesListControl1.DataGridView.CellDoubleClick += DataGridView_CellDoubleClick; }
public void Should_not_have_error_when_password_is_specified() { var model = new InstallModel { AdminPassword = "******" }; //we know that password should equal confirmation password model.ConfirmPassword = model.AdminPassword; _validator.ShouldNotHaveValidationErrorFor(x => x.AdminPassword, model); }
public ActionResult Index() { if (DataSettings.DatabaseIsInstalled()) { return(RedirectToRoute("HomePage")); } //set page timeout to 5 minutes this.Server.ScriptTimeout = 300; var model = new InstallModel() { AdminEmail = _locService.GetResource("AdminEmailValue"), //AdminPassword = "******", //ConfirmPassword = "******", InstallSampleData = false, DatabaseConnectionString = "", DataProvider = "sqlce", // "sqlserver", SqlAuthenticationType = "sqlauthentication", SqlConnectionInfo = "sqlconnectioninfo_values", SqlServerCreateDatabase = false, UseCustomCollation = false, Collation = "SQL_Latin1_General_CP1_CI_AS", }; foreach (var lang in _locService.GetAvailableLanguages()) { model.AvailableLanguages.Add(new SelectListItem() { Value = Url.Action("ChangeLanguage", "Install", new { language = lang.Code }), Text = lang.Name, Selected = _locService.GetCurrentLanguage().Code == lang.Code, }); } foreach (var lang in _locService.GetAvailableAppLanguages()) { model.AvailableAppLanguages.Add(new SelectListItem() { Value = lang.Culture, Text = lang.Name, Selected = lang.Culture == Thread.CurrentThread.CurrentCulture.IetfLanguageTag // TODO (?) }); } model.AvailableMediaStorages.Add(new SelectListItem { Value = "db", Text = _locService.GetResource("MediaStorage.DB"), Selected = true }); model.AvailableMediaStorages.Add(new SelectListItem { Value = "fs", Text = _locService.GetResource("MediaStorage.FS") }); return(View(model)); }
public void CreateDatabase(InstallModel model) { //drop database if exists string databaseFullPath = HostingEnvironment.MapPath("~/App_Data/") + DatabaseFileName; if (File.Exists(databaseFullPath)) { File.Delete(databaseFullPath); } using (File.Create(databaseFullPath)) { } }
/// <summary> /// Add admin user /// </summary> /// <param name="model"></param> private void AddAdminUser(InstallModel model) { var user = new User { UserName = model.UserName, Password = Utilities.EncryptHelper.MD5(model.Password), Nickname = model.Nickname, Email = model.Email }; BlogContext.Users.Add(user); }
private InstallModel PrepareAvailableDataProviders(InstallModel model) { model.AvailableDataProviders.AddRange( _locService.Value.GetAvailableProviderTypes() .OrderBy(v => v.Value) .Select(pt => new SelectListItem { Value = pt.Key.ToString(), Text = pt.Value })); return(model); }
public void Should_have_error_when_password_is_null_or_empty() { var model = new InstallModel(); model.AdminPassword = null; //we know that password should equal confirmation password model.ConfirmPassword = model.AdminPassword; _validator.ShouldHaveValidationErrorFor(x => x.AdminPassword, model); model.AdminPassword = ""; //we know that password should equal confirmation password model.ConfirmPassword = model.AdminPassword; _validator.ShouldHaveValidationErrorFor(x => x.AdminPassword, model); }
private InstallModel PrepareLanguageList(InstallModel model) { foreach (var lang in _locService.Value.GetAvailableLanguages()) { model.AvailableLanguages.Add(new SelectListItem { Value = Url.Action("ChangeLanguage", "Install", new { language = lang.Code }), Text = lang.Name, Selected = _locService.Value.GetCurrentLanguage().Code == lang.Code }); } return(model); }
public IActionResult Finish(InstallModel installModel) { DbExtension.InstallDb(installModel.ToDbConfig()); var admin = new AdminEntity(); admin.UserName = installModel.AdminUser; admin.Password = SM3.GetSM3(installModel.AdminPass); admin.Insert(); var settings = new List <SettingsEntity>(); settings.Add(new SettingsEntity() { Name = "title", Value = "JXCMS", Type = "Settings" }); settings.Add(new SettingsEntity() { Name = "logo", Value = "/images/Logo.png", Type = "Settings" }); settings.Add(new SettingsEntity() { Name = "keyword", Value = "JXCMS,急速开发CMS", Type = "Settings" }); settings.Add(new SettingsEntity() { Name = "description", Value = "JXCMS是一款快速开发的CMS程序", Type = "Settings" }); settings.Add(new SettingsEntity() { Name = "copyright", Value = "JXCMS 2019", Type = "Settings" }); settings.Add(new SettingsEntity() { Name = "icp", Value = "", Type = "Settings" }); BaseEntity.Orm.Insert(settings).ExecuteInserted(); System.IO.File.Create("install.lock"); return(View()); }
// // GET: /Install/ public ActionResult Index() { if (_installationService.IsDatabaseInstalled()) { return(RedirectToAction("Index", "Home")); } var model = new InstallModel() { AdminUsername = "" }; return(View(model)); }
private void CustomValidateModel(InstallModel model) { if (model.DbAdminRequired) { if (string.IsNullOrWhiteSpace(model.DbAdminPassword)) { ModelState.AddModelError("DbAdminPassword", Resource.DbAdminPasswordRequiredError); } if (string.IsNullOrWhiteSpace(model.DbAdminUser)) { ModelState.AddModelError("DbAdminUser", Resource.DbAdminUserRequiredError); } } }
public void Install(InstallModel model) { MediaModel mediaModel = _setupEcommerceMedia.Setup(); LayoutModel layoutModel = _setupEcommerceLayouts.Setup(mediaModel); PageModel pageModel = _setupBaseDocuments.Setup(mediaModel); _setupEcommerceSettings.Setup(mediaModel); _setupCurrency.Setup(); _importDummyCategories.Import(mediaModel); _importDummyProducts.Import(); _setupEcommerceWidgets.Setup(pageModel, mediaModel, layoutModel); _setupNewsletterTemplate.Setup(); _indexSetup.ReIndex(); }
public void OnInstalling(ControllerContext controllerContext) { var moduleInfo = ModuleInfo.Get(SampleAreaRegistration.ModuleName); var installModel = new InstallModel(); Kooboo.CMS.Sites.Extension.ModelBindHelper.BindModel <InstallModel>(installModel, controllerContext); moduleInfo.DefaultSettings.CustomSettings["DatabaseServer"] = installModel.DatabaseServer; moduleInfo.DefaultSettings.CustomSettings["UserName"] = installModel.UserName; moduleInfo.DefaultSettings.CustomSettings["Password"] = installModel.Password; ModuleInfo.Save(moduleInfo); // Add code here that will be executed when the module installing. }
public async Task <IActionResult> Index(InstallModel installModel) { if (_installationProvider.IsPlatformInstalled) { return(new StatusCodeResult(StatusCodes.Status405MethodNotAllowed)); } if (!ModelState.IsValid) { return(new StatusCodeResult(StatusCodes.Status400BadRequest)); } var connectionString = _installationProvider.GetConnectionString(installModel); var settingFile = Path.Combine(_hostingEnvironment.ContentRootPath, $"appsettings.{_hostingEnvironment.EnvironmentName}.json"); try { await _installationProvider.InstallPlatform(installModel); //ApplicationManager.Instance.Restart(); await _hubContext.Clients.All.SendAsync("OnUpdateInstallLog", "Restarting the website"); await Task.Run(() => { _hostApplicationLifetime.StopApplication(); }); return(Ok()); } catch (SqlException ex) { var errorMessage = $"Invalid connection to database, kindly check the connection string parameters: {ex.Message}"; ModelState.AddModelError("", errorMessage); _logger.LogError(ex, errorMessage); return(new ObjectResult(errorMessage) { StatusCode = StatusCodes.Status400BadRequest }); } catch (Exception ex) { var errorMessage = ex.Message; ModelState.AddModelError("", errorMessage); _logger.LogError(ex, errorMessage); return(new ObjectResult(errorMessage) { StatusCode = StatusCodes.Status400BadRequest }); } }
public virtual async Task <IActionResult> Index() { if (DataSettingsManager.DatabaseIsInstalled()) { return(RedirectToRoute("HomePage")); } var locService = _serviceProvider.GetRequiredService <IInstallationLocalizedService>(); var installed = await _cacheBase.GetAsync("Installed", async() => { return(await Task.FromResult(false)); }); if (installed) { return(View(new InstallModel() { Installed = true })); } var model = new InstallModel { AdminEmail = "*****@*****.**", InstallSampleData = false, DatabaseConnectionString = "", }; model.AvailableProviders = Enum.GetValues(typeof(DbProvider)).Cast <DbProvider>().Select(v => new SelectListItem { Text = v.ToString(), Value = ((int)v).ToString() }).ToList(); foreach (var lang in locService.GetAvailableLanguages()) { model.AvailableLanguages.Add(new SelectListItem { Value = Url.RouteUrl("InstallChangeLanguage", new { language = lang.Code }), Text = lang.Name, Selected = locService.GetCurrentLanguage().Code == lang.Code, }); } //prepare collation list foreach (var col in locService.GetAvailableCollations()) { model.AvailableCollation.Add(new SelectListItem { Value = col.Value, Text = col.Name, Selected = locService.GetCurrentLanguage().Code == col.Value, }); } return(View(model)); }
private string PrepareDb(InstallModel model) { var csBuilder = model.ConnectionStringBuilder; SetupWorker.SendFriendlyMessage("Checking connection availability. Connection string: {0}", csBuilder.ConnectionString); var success = CheckDb(csBuilder.ConnectionString); if (success) { return(csBuilder.ConnectionString); } if (!string.IsNullOrEmpty(model.DbAdminUser)) { SetupWorker.SendFriendlyMessage("Trying to connect with administrator user {0}.", model.DbAdminUser); // let's try with admin user csBuilder.UserID = model.DbAdminUser; csBuilder.Password = model.DbAdminPassword; success = CheckDb(csBuilder.ConnectionString); } if (!success) { SetupWorker.SendFriendlyMessage("Trying to connect with integrated user."); // let's try with integrated user csBuilder.IntegratedSecurity = true; success = CheckDb(csBuilder.ConnectionString); } if (success) { AddUserToDatabase(csBuilder.ConnectionString, model.DbUserName, model.DbUserPassword); } else { model.DbAdminUser = "******"; model.DbAdminRequired = true; CustomValidateModel(model); throw new Exception(Resource.DbServerAdminRequiredException); } if (csBuilder.InitialCatalog.ToLower() == "master") { throw new Exception("'Master' is reserved for system database, please provide other database name."); } return(csBuilder.ConnectionString); }
public ActionResult CheckAndInstall(InstallModel model) { // Create folder if not exists var subPaths = new string[] { "~/App_Data", "~/images/listing", "~/images/profile" }; foreach (var subPath in subPaths) { bool exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } } ConnectionStringSettings connectionStringSettings = null; string connectionString = null; //SQL CE switch ((DatabaseType)model.DatabaseType) { case DatabaseType.MsSqlCeServer: default: string databaseFileName = string.Format("Dashoor_{0}.sdf", DateTime.Now.ToString("yyyy.MM.dd.HH.mm.ss")); string databasePath = @"|DataDirectory|\" + databaseFileName; connectionString = "Data Source=" + databasePath + ";Persist Security Info=False"; connectionStringSettings = new ConnectionStringSettings("DefaultConnection", connectionString, "System.Data.SqlServerCe.4.0"); break; case DatabaseType.MsSqlServer: connectionString = ConnectionStringHelper.CreateConnectionString(model.UseWindowsAuthentication, model.Server, model.Database, model.DatabaseLogin, model.DatabasePassword); connectionStringSettings = new ConnectionStringSettings("DefaultConnection", connectionString, "System.Data.SqlClient"); break; } var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); ConnectionStringHelper.AddAndSaveOneConnectionStringSettings(configuration, connectionStringSettings); // Set language first before redirection, otherwise, the model will be re-written InstallLanguage(); return(RedirectToAction("Install", model)); }
public void TestCanAddNewInstallPackages() { var model = new InstallModel(); var package1 = new PIDataArchive(); var package2 = new Executable(); var package3 = new OSIAutoExtractSetupPackage(); var package4 = new PowerShellCodeBlock(); model.Add(package1); model.Add(package2); model.Add(package3); model.Add(package4); Assert.IsTrue(model.Items.Count == 4); }
public void ShouldHaveErrorWhenPasswordIsNullOrEmpty() { var model = new InstallModel { AdminPassword = null }; //we know that password should equal confirmation password model.ConfirmPassword = model.AdminPassword; _validator.ShouldHaveValidationErrorFor(x => x.AdminPassword, model); model.AdminPassword = string.Empty; //we know that password should equal confirmation password model.ConfirmPassword = model.AdminPassword; _validator.ShouldHaveValidationErrorFor(x => x.AdminPassword, model); }
public virtual async Task <IActionResult> Index() { if (DataSettingsHelper.DatabaseIsInstalled()) { return(RedirectToRoute("HomePage")); } var locService = _serviceProvider.GetRequiredService <IInstallationLocalizationService>(); var installed = await _cacheManager.GetAsync <bool>("Installed"); if (installed) { return(View(new InstallModel() { Installed = true })); } var model = new InstallModel { AdminEmail = "*****@*****.**", InstallSampleData = false, DatabaseConnectionString = "", DataProvider = "mongodb", }; foreach (var lang in locService.GetAvailableLanguages()) { model.AvailableLanguages.Add(new SelectListItem { Value = Url.Action("ChangeLanguage", "Install", new { language = lang.Code }), Text = lang.Name, Selected = locService.GetCurrentLanguage().Code == lang.Code, }); } //prepare collation list foreach (var col in locService.GetAvailableCollations()) { model.AvailableCollation.Add(new SelectListItem { Value = col.Value, Text = col.Name, Selected = locService.GetCurrentLanguage().Code == col.Value, }); } return(View(model)); }
public string GetConnectionString(InstallModel model) { if (model.DatabaseProvider == DatabaseProvider.SQLServer) { if (model.IsIntegratedSecurity) { return($"Server={model.ServerName};Database={model.DatabaseName};Trusted_Connection=True;MultipleActiveResultSets=true"); } return($"Server={model.ServerName};Database={model.DatabaseName};User Id={model.DBUserName};Password={model.DBPassword}"); } else if (model.DatabaseProvider == DatabaseProvider.SQLLocalDb) { return($"Server={model.ServerName};Database={model.DatabaseName};Trusted_Connection=True;MultipleActiveResultSets=true"); } else if (model.DatabaseProvider == DatabaseProvider.PostgreSQL) { string host = model.ServerName; string port = ""; if (host.Contains(":")) { var hostAndPort = host.Split(':'); host = hostAndPort[0]; port = hostAndPort[1]; } return($"Host={host};{((!string.IsNullOrEmpty(port)) ? $"Port={port};" : "")}Database={model.DatabaseName};User ID={model.DBUserName};Password={model.DBPassword};"); } else if (model.DatabaseProvider == DatabaseProvider.MySQL) { string host = model.ServerName; string port = ""; if (host.Contains(":")) { var hostAndPort = host.Split(':'); host = hostAndPort[0]; port = hostAndPort[1]; } return($"server={host};{((!string.IsNullOrEmpty(port)) ? $"port={port};" : "")}database={model.DatabaseName};user={model.DBUserName};password={model.DBPassword};CharSet=utf8mb4;"); } else { //SQLite return($"Data Source={model.DatabaseName}.db"); } }
private void UpdateIndex(InstallModel model) { var searchConnection = new SearchConnection(ConnectionHelper.GetConnectionString("SearchConnectionString")); if (searchConnection.Provider.Equals( SearchProviders.Lucene.ToString(), StringComparison.OrdinalIgnoreCase) && searchConnection.DataSource.StartsWith("~/")) { var dataSource = searchConnection.DataSource.Replace( "~/", HttpRuntime.AppDomainAppPath + "\\"); searchConnection = new SearchConnection(dataSource, searchConnection.Scope, searchConnection.Provider); } SendFriendlyMessage("Updating search index..."); new UpdateSearchIndex().Index(searchConnection, model.ConnectionStringBuilder.ConnectionString, null, true); }
/// <summary> /// Add settings /// </summary> /// <param name="model"></param> private void AddSettings(InstallModel model) { SettingModel settingModel = new SettingModel(new Dictionary <string, string>(), SettingModelLocalizer); settingModel.Title = model.BlogTitle; settingModel.Host = model.BlogHost; settingModel.Language = model.Language; var settingList = settingModel.Settings.Select(t => new Setting { Key = t.Key, Value = t.Value }); BlogContext.AddRange(settingList); }
public async Task <IActionResult> Index() { if (_installationProvider.IsPlatformInstalled) { return(RedirectToAction("Index", "Home")); } var installModel = new InstallModel { DatabaseProvider = DatabaseProvider.SqlLite, //ServerName = "(localdb)\\mssqllocaldb", IsIntegratedSecurity = true }; return(await ViewAsync(installModel)); }
public ActionResult Index() { var m = new InstallModel() { AdminUsername = WG.Settings.AdminUsername, AllowRegistration = WG.Settings.AllowRegistration, ConnectionString = WG.Settings.ConnectionString, DatabaseProvider = WG.Settings.DatabaseProvider, EnableGoogleLogin = WG.Settings.Auth.EnableGoogleLogin, GitUser = WG.Settings.GitUser, GitPassword = WG.Settings.GitPassword, GoogleAppsDomain = WG.Settings.Auth.GoogleAppsDomain, UseSameGitAccountForAllUsers = WG.Settings.UseSameGitAccountForAllUsers, WikiRepository = WG.Settings.Repository }; return View(m); }
private async Task RenderPage(HttpContext context, InstallModel model) { string file = Path.Combine(ApplicationEnviroment.ApplicationBasePath, "Install/Install.html"); var html = File.ReadAllText(file); html = html.Replace("{Server}", model.Server ?? string.Empty); html = html.Replace("{Database}", model.Database ?? string.Empty); html = html.Replace("{UserID}", model.UserID ?? string.Empty); html = html.Replace("{Password}", model.Password ?? string.Empty); string errorMessage = string.Empty; if (!string.IsNullOrWhiteSpace(model.ErrorMessage)) { errorMessage = string.Format("<div class='alert alert-danger'>{0}</div>", model.ErrorMessage); } html = html.Replace("{ErrorMessage}", errorMessage); await this.RenderHtml(context, html); }
public ActionResult Index(InstallModel model) { if (DataSettingsHelper.DatabaseIsInstalled()) return RedirectToRoute("HomePage"); //set page timeout to 5 minutes this.Server.ScriptTimeout = 300; if (model.DatabaseConnectionString != null) model.DatabaseConnectionString = model.DatabaseConnectionString.Trim(); //prepare language list foreach (var lang in _locService.GetAvailableLanguages()) { model.AvailableLanguages.Add(new SelectListItem { Value = Url.Action("ChangeLanguage", "Install", new { language = lang.Code }), Text = lang.Name, Selected = _locService.GetCurrentLanguage().Code == lang.Code, }); } model.DisableSqlCompact = !String.IsNullOrEmpty(ConfigurationManager.AppSettings["UseFastInstallationService"]) && Convert.ToBoolean(ConfigurationManager.AppSettings["UseFastInstallationService"]); model.DisableSampleDataOption = !String.IsNullOrEmpty(ConfigurationManager.AppSettings["DisableSampleDataDuringInstallation"]) && Convert.ToBoolean(ConfigurationManager.AppSettings["DisableSampleDataDuringInstallation"]); //SQL Server if (model.DataProvider.Equals("sqlserver", StringComparison.InvariantCultureIgnoreCase)) { if (model.SqlConnectionInfo.Equals("sqlconnectioninfo_raw", StringComparison.InvariantCultureIgnoreCase)) { //raw connection string if (string.IsNullOrEmpty(model.DatabaseConnectionString)) ModelState.AddModelError("", _locService.GetResource("ConnectionStringRequired")); try { //try to create connection string new SqlConnectionStringBuilder(model.DatabaseConnectionString); } catch { ModelState.AddModelError("", _locService.GetResource("ConnectionStringWrongFormat")); } } else { //values if (string.IsNullOrEmpty(model.SqlServerName)) ModelState.AddModelError("", _locService.GetResource("SqlServerNameRequired")); if (string.IsNullOrEmpty(model.SqlDatabaseName)) ModelState.AddModelError("", _locService.GetResource("DatabaseNameRequired")); //authentication type if (model.SqlAuthenticationType.Equals("sqlauthentication", StringComparison.InvariantCultureIgnoreCase)) { //SQL authentication if (string.IsNullOrEmpty(model.SqlServerUsername)) ModelState.AddModelError("", _locService.GetResource("SqlServerUsernameRequired")); if (string.IsNullOrEmpty(model.SqlServerPassword)) ModelState.AddModelError("", _locService.GetResource("SqlServerPasswordRequired")); } } } //Consider granting access rights to the resource to the ASP.NET request identity. //ASP.NET has a base process identity //(typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, //and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. //If the application is impersonating via <identity impersonate="true"/>, //the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. var webHelper = EngineContext.Current.Resolve<IWebHelper>(); //validate permissions var dirsToCheck = FilePermissionHelper.GetDirectoriesWrite(webHelper); foreach (string dir in dirsToCheck) if (!FilePermissionHelper.CheckPermissions(dir, false, true, true, false)) ModelState.AddModelError("", string.Format(_locService.GetResource("ConfigureDirectoryPermissions"), WindowsIdentity.GetCurrent().Name, dir)); var filesToCheck = FilePermissionHelper.GetFilesWrite(webHelper); foreach (string file in filesToCheck) if (!FilePermissionHelper.CheckPermissions(file, false, true, true, true)) ModelState.AddModelError("", string.Format(_locService.GetResource("ConfigureFilePermissions"), WindowsIdentity.GetCurrent().Name, file)); if (ModelState.IsValid) { var settingsManager = new DataSettingsManager(); try { string connectionString; if (model.DataProvider.Equals("sqlserver", StringComparison.InvariantCultureIgnoreCase)) { //SQL Server if (model.SqlConnectionInfo.Equals("sqlconnectioninfo_raw", StringComparison.InvariantCultureIgnoreCase)) { //raw connection string //we know that MARS option is required when using Entity Framework //let's ensure that it's specified var sqlCsb = new SqlConnectionStringBuilder(model.DatabaseConnectionString); if (this.UseMars) { sqlCsb.MultipleActiveResultSets = true; } connectionString = sqlCsb.ToString(); } else { //values connectionString = CreateConnectionString(model.SqlAuthenticationType == "windowsauthentication", model.SqlServerName, model.SqlDatabaseName, model.SqlServerUsername, model.SqlServerPassword); } if (model.SqlServerCreateDatabase) { if (!SqlServerDatabaseExists(connectionString)) { //create database var collation = model.UseCustomCollation ? model.Collation : ""; var errorCreatingDatabase = CreateDatabase(connectionString, collation); if (!String.IsNullOrEmpty(errorCreatingDatabase)) throw new Exception(errorCreatingDatabase); //Database cannot be created sometimes. Weird! Seems to be Entity Framework issue //that's just wait 3 seconds Thread.Sleep(3000); } } else { //check whether database exists if (!SqlServerDatabaseExists(connectionString)) throw new Exception(_locService.GetResource("DatabaseNotExists")); } } else { //SQL CE string databaseFileName = "Nop.Db.sdf"; string databasePath = @"|DataDirectory|\" + databaseFileName; connectionString = "Data Source=" + databasePath + ";Persist Security Info=False"; //drop database if exists string databaseFullPath = HostingEnvironment.MapPath("~/App_Data/") + databaseFileName; if (System.IO.File.Exists(databaseFullPath)) { System.IO.File.Delete(databaseFullPath); } } //save settings var dataProvider = model.DataProvider; var settings = new DataSettings { DataProvider = dataProvider, DataConnectionString = connectionString }; settingsManager.SaveSettings(settings); //init data provider var dataProviderInstance = EngineContext.Current.Resolve<BaseDataProviderManager>().LoadDataProvider(); dataProviderInstance.InitDatabase(); //now resolve installation service var installationService = EngineContext.Current.Resolve<IInstallationService>(); installationService.InstallData(model.AdminEmail, model.AdminPassword, model.InstallSampleData); //reset cache DataSettingsHelper.ResetCache(); //register default permissions //var permissionProviders = EngineContext.Current.Resolve<ITypeFinder>().FindClassesOfType<IPermissionProvider>(); var permissionProviders = new List<Type>(); permissionProviders.Add(typeof(StandardPermissionProvider)); foreach (var providerType in permissionProviders) { dynamic provider = Activator.CreateInstance(providerType); EngineContext.Current.Resolve<IPermissionService>().InstallPermissions(provider); } //restart application webHelper.RestartAppDomain(); //Redirect to home page return RedirectToRoute("HomePage"); } catch (Exception exception) { //reset cache DataSettingsHelper.ResetCache(); //clear provider settings if something got wrong settingsManager.SaveSettings(new DataSettings { DataProvider = null, DataConnectionString = null }); ModelState.AddModelError("", string.Format(_locService.GetResource("SetupFailed"), exception.Message)); } } return View(model); }
public ActionResult Index() { if (DataSettingsHelper.DatabaseIsInstalled()) return RedirectToRoute("HomePage"); //set page timeout to 5 minutes this.Server.ScriptTimeout = 300; var model = new InstallModel { AdminEmail = "*****@*****.**", InstallSampleData = false, DatabaseConnectionString = "", DataProvider = "sqlserver", //fast installation service does not support SQL compact DisableSqlCompact = !String.IsNullOrEmpty(ConfigurationManager.AppSettings["UseFastInstallationService"]) && Convert.ToBoolean(ConfigurationManager.AppSettings["UseFastInstallationService"]), DisableSampleDataOption = !String.IsNullOrEmpty(ConfigurationManager.AppSettings["DisableSampleDataDuringInstallation"]) && Convert.ToBoolean(ConfigurationManager.AppSettings["DisableSampleDataDuringInstallation"]), SqlAuthenticationType = "sqlauthentication", SqlConnectionInfo = "sqlconnectioninfo_values", SqlServerCreateDatabase = false, UseCustomCollation = false, Collation = "SQL_Latin1_General_CP1_CI_AS", }; foreach (var lang in _locService.GetAvailableLanguages()) { model.AvailableLanguages.Add(new SelectListItem { Value = Url.Action("ChangeLanguage", "Install", new { language = lang.Code}), Text = lang.Name, Selected = _locService.GetCurrentLanguage().Code == lang.Code, }); } return View(model); }
public ActionResult Index(InstallModel model) { var installer = new Installer(Server.MapPath("~")); if (ModelState.IsValid) { var ret = installer.SetRepository(model.WikiRepository, model.GitUser, model.GitPassword, false); var allIsWell = true; switch(ret) { case InstallerMessage.ExceptionThrown : ModelState.AddModelError("WikiRepository", installer.LastException.Message); allIsWell = false; break; case InstallerMessage.UnkownFailure : ModelState.AddModelError("WikiRepository", "We couldn't clone the wiki repository. Unfortunately, we don't know why :("); allIsWell = false; break; } var conf = WebConfigurationManager.OpenWebConfiguration("~"); ret = installer.SetDbConnection(model.ConnectionString, model.DatabaseProvider); switch (ret) { case InstallerMessage.CouldNotConnectToDb : ModelState.AddModelError("ConnectionString", "Could not connect to the database."); allIsWell = false; break; case InstallerMessage.InvalidConnectionString : ModelState.AddModelError("ConnectionString", "The connection string is invalid."); allIsWell = false; break; case InstallerMessage.InvalidDbProvider: ModelState.AddModelError("DatabaseProvider", "This provider could not be found."); allIsWell = false; break; } if (!allIsWell) return View(); WG.Settings.Repository = model.WikiRepository; WG.Settings.GitUser = model.GitUser; WG.Settings.GitPassword = model.GitPassword; WG.Settings.AdminUsername = model.AdminUsername; WG.Settings.AllowRegistration = model.AllowRegistration; WG.Settings.UseSameGitAccountForAllUsers = model.UseSameGitAccountForAllUsers; WG.Settings.Auth.EnableGoogleLogin = model.EnableGoogleLogin; WG.Settings.Auth.GoogleAppsDomain = model.GoogleAppsDomain; WG.Settings.Save(); conf.Save(ConfigurationSaveMode.Full); // creating or update admin user var admin = _usrRepo.FindByUsername(model.AdminUsername); if (WebSecurity.UserExists(model.AdminUsername)) WebSecurity.ResetPassword(WebSecurity.GeneratePasswordResetToken(model.AdminUsername), model.AdminPassword); else WebSecurity.CreateUserAndAccount(model.AdminUsername, model.AdminPassword); WebSecurity.Login(model.AdminUsername, model.AdminPassword); installer.SetAdmin(model.AdminUsername); return RedirectToAction("Index", "Home"); } return View(); }