/// <returns>A task that represents the asynchronous operation</returns> protected virtual async Task <SqlConnectionStringBuilder> GetConnectionStringBuilderAsync() { var connectionString = (await DataSettingsManager.LoadSettingsAsync()).ConnectionString; return(new SqlConnectionStringBuilder(connectionString)); }
/// <summary> /// Database connection string /// </summary> protected async Task<string> GetCurrentConnectionStringAsync() { return (await DataSettingsManager.LoadSettingsAsync()).ConnectionString; }
public virtual async Task <IActionResult> Index(InstallModel model) { if (await DataSettingsManager.IsDatabaseInstalledAsync()) { return(RedirectToRoute("Homepage")); } model.DisableSampleDataOption = _appSettings.InstallationConfig.DisableSampleData; model.InstallRegionalResources = _appSettings.InstallationConfig.InstallRegionalResources; PrepareAvailableDataProviders(model); PrepareLanguageList(model); PrepareCountryList(model); //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(); foreach (var dir in dirsToCheck) { if (!FilePermissionHelper.CheckPermissions(dir, false, true, true, false)) { ModelState.AddModelError(string.Empty, string.Format(_locService.GetResource("ConfigureDirectoryPermissions"), CurrentOSUser.FullName, dir)); } } var filesToCheck = FilePermissionHelper.GetFilesWrite(); foreach (var file in filesToCheck) { if (!_fileProvider.FileExists(file)) { continue; } if (!FilePermissionHelper.CheckPermissions(file, false, true, true, true)) { ModelState.AddModelError(string.Empty, string.Format(_locService.GetResource("ConfigureFilePermissions"), CurrentOSUser.FullName, file)); } } if (!ModelState.IsValid) { return(View(model)); } try { var dataProvider = DataProviderManager.GetDataProvider(model.DataProvider); var connectionString = model.ConnectionStringRaw ? model.ConnectionString : dataProvider.BuildConnectionString(model); if (string.IsNullOrEmpty(connectionString)) { throw new Exception(_locService.GetResource("ConnectionStringWrongFormat")); } await DataSettingsManager.SaveSettingsAsync(new DataSettings { DataProvider = model.DataProvider, ConnectionString = connectionString }, _fileProvider); await DataSettingsManager.LoadSettingsAsync(reloadSettings : true); if (model.CreateDatabaseIfNotExists) { try { dataProvider.CreateDatabase(model.Collation); } catch (Exception ex) { throw new Exception(string.Format(_locService.GetResource("DatabaseCreationError"), ex.Message)); } } else { //check whether database exists if (!await dataProvider.DatabaseExistsAsync()) { throw new Exception(_locService.GetResource("DatabaseNotExists")); } } dataProvider.InitializeDatabase(); var cultureInfo = new CultureInfo(NopCommonDefaults.DefaultLanguageCulture); var regionInfo = new RegionInfo(NopCommonDefaults.DefaultLanguageCulture); var languagePackInfo = (DownloadUrl : string.Empty, Progress : 0); if (model.InstallRegionalResources) { //try to get CultureInfo and RegionInfo try { cultureInfo = new CultureInfo(model.Country[3..]); regionInfo = new RegionInfo(model.Country[3..]);