public Setup(SetupContext context) { switch (context) { case SetupContext.Vehicle: this.context = SetupContext.Vehicle; settings = new VehicleSetupCode(); break; } }
public ExecutionContext(SetupContext setupContext, HttpActionContext httpActionContext) { _setupContext = setupContext; _httpActionContext = httpActionContext; var httpClientHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, }; var handler = !_setupContext.ContentMD5() ? (HttpMessageHandler) httpClientHandler : new ContentMd5Handler() { InnerHandler = httpClientHandler }; _httpClient = new HttpClient(handler, true); }
public MockSetupContextWithJson() { _id = Guid.Parse("4fc99dd1-9aad-4d63-a247-75c9b72de204").ToString(); _name1 = "Foo"; _name2 = "f00Baz"; var body = new { id = _id, company1 = new { name = _name1 }, company2 = new { name = _name2 } }; _setup = new SetupContext(); _setup.Body(body); }
public Control GetVisualControl(SetupContext context) { return(new UI.DownloaderUIPanel(this)); }
public async Task <string> SetupInternalAsync(SetupContext context) { string executionId; if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Running setup for tenant '{TenantName}'.", context.ShellSettings.Name); } // Features to enable for Setup string[] hardcoded = { _applicationName, //TODO }; context.EnabledFeatures = hardcoded.Union(context.EnabledFeatures ?? Enumerable.Empty <string>()).Distinct().ToArray(); // Set shell state to "Initializing" so that subsequent HTTP requests are responded to with "Service Unavailable" while Orchard is setting up. context.ShellSettings.State = TenantState.Initializing; var shellSettings = new ShellSettings(context.ShellSettings); shellSettings["ConnectionString"] = context.DatabaseConnectionString; // Creating a standalone environment based on a "minimum shell descriptor". // In theory this environment can be used to resolve any normal components by interface, and those // components will exist entirely in isolation - no crossover between the safemode container currently in effect // It is used to initialize the database before the recipe is run. var shellDescriptor = new ShellDescriptor { Features = context.EnabledFeatures.Select(id => new ShellFeature { Id = id }).ToList() }; using (var shellContext = await _shellContextFactory.CreateDescribedContextAsync(shellSettings, shellDescriptor)) { using (var scope = shellContext.CreateScope()) { var hasErrors = false; void reportError(string key, string message) { hasErrors = true; context.SetError(key, message); } try { await this.InitializeDatabaseForTenantAsync(context, scope, reportError); if (hasErrors) { _logger.LogError("An error occurred while initializing the tenant {0}", context.DbName); return(null); } } catch (Exception e) { // Tables already exist or database was not found // The issue is that the user creation needs the tables to be present, // if the user information is not valid, the next POST will try to recreate the // tables. The tables should be rolled back if one of the steps is invalid, // unless the recipe is executing? _logger.LogError(e, "An error occurred while initializing the datastore."); context.SetError("DatabaseProvider", T["An error occurred while initializing the datastore: {0}", e.Message]); return(null); } // Create the "minimum shell descriptor" await scope .ServiceProvider .GetService <IShellDescriptorManager>() .UpdateShellDescriptorAsync(0, shellContext.Blueprint.Descriptor.Features); // TODO FIXME /* * var deferredTaskEngine = scope.ServiceProvider.GetService<IDeferredTaskEngine>(); * * if (deferredTaskEngine != null && deferredTaskEngine.HasPendingTasks) { * var taskContext = new DeferredTaskContext(scope.ServiceProvider); * await deferredTaskEngine.ExecuteTasksAsync(taskContext); * } */ } executionId = Guid.NewGuid().ToString("n"); /* * var recipeExecutor = shellContext.ServiceProvider.GetRequiredService<IRecipeExecutor>(); * * await recipeExecutor.ExecuteAsync(executionId, context.Recipe, new * { * SiteName = context.SiteName, * AdminUsername = context.AdminUsername, * AdminEmail = context.AdminEmail, * AdminPassword = context.AdminPassword, * DatabaseProvider = context.DatabaseProvider, * DatabaseConnectionString = context.DatabaseConnectionString, * DatabaseTablePrefix = context.DatabaseTablePrefix * }, * * _applicationLifetime.ApplicationStopping); */ } // Reloading the shell context as the recipe has probably updated its features using (var shellContext = await _shellHost.GetOrCreateShellContextAsync(shellSettings)) { using (var scope = shellContext.CreateScope()) { var hasErrors = false; void reportError(string key, string message) { hasErrors = true; context.SetError(key, message); } // Invoke modules to react to the setup event var setupEventHandlers = scope.ServiceProvider.GetServices <ISetupEventHandler>(); var logger = scope.ServiceProvider.GetRequiredService <ILogger <SetupService> >(); //Notify all registered event handlers await setupEventHandlers.InvokeAsync(x => x.Setup(context, reportError), logger); if (hasErrors) { return(executionId); } /* TODO FIXME * var deferredTaskEngine = scope.ServiceProvider.GetService<IDeferredTaskEngine>(); * * if (deferredTaskEngine != null && deferredTaskEngine.HasPendingTasks) { * var taskContext = new DeferredTaskContext(scope.ServiceProvider); * await deferredTaskEngine.ExecuteTasksAsync(taskContext); * } */ } } // Update the shell state shellSettings.State = TenantState.Running; await _shellHost.UpdateShellSettingsAsync(shellSettings); return(executionId); }
public ActionResult IndexPOST(SetupViewModel model) { // sets the setup request timeout to 10 minutes to give enough time to execute custom recipes. HttpContext.Server.ScriptTimeout = 600; //var recipes = OrderRecipes(_setupService.Recipes()); if (string.IsNullOrEmpty(model.DatabaseConnectionString)) { ModelState.AddModelError("DatabaseConnectionString", "A connection string is required"); } if (!String.IsNullOrWhiteSpace(model.ConfirmPassword) && model.AdminPassword != model.ConfirmPassword) { ModelState.AddModelError("ConfirmPassword", "Password confirmation must match"); } //if (model.DatabaseProvider != SetupDatabaseType.Builtin && !String.IsNullOrWhiteSpace(model.DatabaseTablePrefix)) //{ // model.DatabaseTablePrefix = model.DatabaseTablePrefix.Trim(); // if (!Char.IsLetter(model.DatabaseTablePrefix[0])) // { // ModelState.AddModelError("DatabaseTablePrefix", T("The table prefix must begin with a letter").Text); // } // if (model.DatabaseTablePrefix.Any(x => !Char.IsLetterOrDigit(x))) // { // ModelState.AddModelError("DatabaseTablePrefix", T("The table prefix must contain letters or digits").Text); // } //} //if (model.Recipe == null) //{ // if (!(recipes.Select(r => r.Name).Contains(DefaultRecipe))) // { // ModelState.AddModelError("Recipe", T("No recipes were found in the Setup module").Text); // } // else // { // model.Recipe = DefaultRecipe; // } //} if (!ModelState.IsValid) { //model.Recipes = recipes; //foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) //{ // model.RecipeDescription = recipe.Description; //} model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return(IndexViewResult(model)); } try { string providerName = null; switch (model.DatabaseProvider) { //case SetupDatabaseType.Builtin: // providerName = "SqlCe"; // break; case SetupDatabaseType.SqlServer: providerName = "SqlServer"; break; //case SetupDatabaseType.MySql: // providerName = "MySql"; // break; default: throw new ApplicationException("Unknown database type: " + model.DatabaseProvider); } var setupContext = new SetupContext { SiteName = model.SiteName, AdminUsername = model.AdminUsername, AdminPassword = model.AdminPassword, DatabaseProvider = providerName, DatabaseConnectionString = model.DatabaseConnectionString, DatabaseTablePrefix = model.DatabaseTablePrefix, EnabledFeatures = null, // default list }; _setupService.Setup(setupContext); // First time installation if finally done. Tell the background views compilation // process to stop, so that it doesn't interfere with the user (asp.net compilation // uses a "single lock" mechanism for compiling views). _viewsBackgroundCompilation.Stop(); // redirect to the welcome page. //+ _shellSettings.RequestUrlPrefix return(Redirect("~/")); } catch (Exception ex) { Logger.Error(ex, "Setup failed"); _notifier.Error(string.Format("Setup failed: {0}", ex.Message)); //model.Recipes = recipes; //foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) //{ // model.RecipeDescription = recipe.Description; //} model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return(IndexViewResult(model)); } }
public Task OnUpgrade(SetupContext context) { return(Task.CompletedTask); }
public void TearDown() { TestContext.Dispose(); SetupContext.Dispose(); }
public HttpActionContext(SetupContext setupContext) { _setupContext = setupContext; }
public async Task <ActionResult> Setup(SetupApiViewModel model) { if (!IsDefaultShell()) { return(this.ChallengeOrForbid("Api")); } if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTenants)) { return(this.ChallengeOrForbid("Api")); } if (!String.IsNullOrEmpty(model.UserName) && model.UserName.Any(c => !_identityOptions.User.AllowedUserNameCharacters.Contains(c))) { ModelState.AddModelError(nameof(model.UserName), S["User name '{0}' is invalid, can only contain letters or digits.", model.UserName]); } // Only add additional error if attribute validation has passed. if (!String.IsNullOrEmpty(model.Email) && !_emailAddressValidator.Validate(model.Email)) { ModelState.AddModelError(nameof(model.Email), S["The email is invalid."]); } if (!ModelState.IsValid) { return(BadRequest()); } if (!_shellHost.TryGetSettings(model.Name, out var shellSettings)) { ModelState.AddModelError(nameof(SetupApiViewModel.Name), S["Tenant not found: '{0}'", model.Name]); } if (shellSettings.State == TenantState.Running) { return(StatusCode(201)); } if (shellSettings.State != TenantState.Uninitialized) { return(BadRequest(S["The tenant can't be setup."])); } var databaseProvider = shellSettings["DatabaseProvider"]; if (String.IsNullOrEmpty(databaseProvider)) { databaseProvider = model.DatabaseProvider; } var selectedProvider = _databaseProviders.FirstOrDefault(x => String.Equals(x.Value, databaseProvider, StringComparison.OrdinalIgnoreCase)); if (selectedProvider == null) { return(BadRequest(S["The database provider is not defined."])); } var tablePrefix = shellSettings["TablePrefix"]; if (String.IsNullOrEmpty(tablePrefix)) { tablePrefix = model.TablePrefix; } var connectionString = shellSettings["connectionString"]; if (String.IsNullOrEmpty(connectionString)) { connectionString = model.ConnectionString; } if (selectedProvider.HasConnectionString && String.IsNullOrEmpty(connectionString)) { return(BadRequest(S["The connection string is required for this database provider."])); } var recipeName = shellSettings["RecipeName"]; if (String.IsNullOrEmpty(recipeName)) { recipeName = model.RecipeName; } RecipeDescriptor recipeDescriptor = null; if (String.IsNullOrEmpty(recipeName)) { if (model.Recipe == null) { return(BadRequest(S["Either 'Recipe' or 'RecipeName' is required."])); } var tempFilename = Path.GetTempFileName(); using (var fs = System.IO.File.Create(tempFilename)) { await model.Recipe.CopyToAsync(fs); } var fileProvider = new PhysicalFileProvider(Path.GetDirectoryName(tempFilename)); recipeDescriptor = new RecipeDescriptor { FileProvider = fileProvider, BasePath = "", RecipeFileInfo = fileProvider.GetFileInfo(Path.GetFileName(tempFilename)) }; } else { var setupRecipes = await _setupService.GetSetupRecipesAsync(); recipeDescriptor = setupRecipes.FirstOrDefault(x => String.Equals(x.Name, recipeName, StringComparison.OrdinalIgnoreCase)); if (recipeDescriptor == null) { return(BadRequest(S["Recipe '{0}' not found.", recipeName])); } } var setupContext = new SetupContext { ShellSettings = shellSettings, EnabledFeatures = null, // default list, Errors = new Dictionary <string, string>(), Recipe = recipeDescriptor, Properties = new Dictionary <string, object> { { SetupConstants.SiteName, model.SiteName }, { SetupConstants.AdminUsername, model.UserName }, { SetupConstants.AdminEmail, model.Email }, { SetupConstants.AdminPassword, model.Password }, { SetupConstants.SiteTimeZone, model.SiteTimeZone }, { SetupConstants.DatabaseProvider, selectedProvider.Value }, { SetupConstants.DatabaseConnectionString, connectionString }, { SetupConstants.DatabaseTablePrefix, tablePrefix }, } }; var executionId = await _setupService.SetupAsync(setupContext); // Check if a component in the Setup failed if (setupContext.Errors.Any()) { foreach (var error in setupContext.Errors) { ModelState.AddModelError(error.Key, error.Value); } return(StatusCode(500, ModelState)); } return(Ok(executionId)); }
public async Task <ActionResult> Setup(SetupApiViewModel model) { if (!IsDefaultShell()) { return(Unauthorized()); } if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTenants)) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest()); } if (!_shellHost.TryGetSettings(model.Name, out var shellSettings)) { ModelState.AddModelError(nameof(SetupApiViewModel.Name), S["Tenant not found: '{0}'", model.Name]); } if (shellSettings.State == TenantState.Running) { return(StatusCode(201)); } if (shellSettings.State != TenantState.Uninitialized) { return(BadRequest(S["The tenant can't be setup."])); } var selectedProvider = _databaseProviders.FirstOrDefault(x => String.Equals(x.Value, model.DatabaseProvider, StringComparison.OrdinalIgnoreCase)); if (selectedProvider == null) { return(BadRequest(S["The database provider is not defined."])); } var tablePrefix = shellSettings.TablePrefix; if (String.IsNullOrEmpty(tablePrefix)) { tablePrefix = model.TablePrefix; } var connectionString = shellSettings.ConnectionString; if (String.IsNullOrEmpty(connectionString)) { connectionString = model.ConnectionString; } if (selectedProvider.HasConnectionString && String.IsNullOrEmpty(connectionString)) { return(BadRequest(S["The connection string is required for this database provider."])); } var recipeName = shellSettings.RecipeName; if (String.IsNullOrEmpty(recipeName)) { recipeName = model.RecipeName; } RecipeDescriptor recipeDescriptor = null; if (String.IsNullOrEmpty(recipeName)) { if (model.Recipe == null) { return(BadRequest(S["Either 'Recipe' or 'RecipeName' is required."])); } var tempFilename = Path.GetTempFileName(); using (var fs = System.IO.File.Create(tempFilename)) { await model.Recipe.CopyToAsync(fs); } var fileProvider = new PhysicalFileProvider(Path.GetDirectoryName(tempFilename)); recipeDescriptor = new RecipeDescriptor { FileProvider = fileProvider, BasePath = "", RecipeFileInfo = fileProvider.GetFileInfo(Path.GetFileName(tempFilename)) }; } else { var setupRecipes = await _setupService.GetSetupRecipesAsync(); recipeDescriptor = setupRecipes.FirstOrDefault(x => String.Equals(x.Name, recipeName, StringComparison.OrdinalIgnoreCase)); if (recipeDescriptor == null) { return(BadRequest(S["Recipe '{0}' not found.", recipeName])); } } var setupContext = new SetupContext { ShellSettings = shellSettings, SiteName = model.SiteName, EnabledFeatures = null, // default list, AdminUsername = model.UserName, AdminEmail = model.Email, AdminPassword = model.Password, Errors = new Dictionary <string, string>(), Recipe = recipeDescriptor, SiteTimeZone = model.SiteTimeZone, DatabaseProvider = selectedProvider.Name, DatabaseConnectionString = connectionString, DatabaseTablePrefix = tablePrefix }; var executionId = await _setupService.SetupAsync(setupContext); // Check if a component in the Setup failed if (setupContext.Errors.Any()) { foreach (var error in setupContext.Errors) { ModelState.AddModelError(error.Key, error.Value); } return(StatusCode(500, ModelState)); } return(Ok(executionId)); }
public async Task <ActionResult> IndexPOST(SetupViewModel model) { model.DatabaseProviders = _databaseProviders; model.Recipes = await _setupService.GetSetupRecipesAsync(); var selectedProvider = model.DatabaseProviders.FirstOrDefault(x => x.Value == model.DatabaseProvider); if (selectedProvider != null && selectedProvider.HasConnectionString && String.IsNullOrWhiteSpace(model.ConnectionString)) { ModelState.AddModelError(nameof(model.ConnectionString), T["The connection string is mandatory for this provider."]); } if (String.IsNullOrEmpty(model.Password)) { ModelState.AddModelError(nameof(model.Password), T["The password is required."]); } if (model.Password != model.PasswordConfirmation) { ModelState.AddModelError(nameof(model.PasswordConfirmation), T["The password confirmation doesn't match the password."]); } RecipeDescriptor selectedRecipe = null; if (String.IsNullOrEmpty(model.RecipeName) || (selectedRecipe = model.Recipes.FirstOrDefault(x => x.Name == model.RecipeName)) == null) { ModelState.AddModelError(nameof(model.RecipeName), T["Invalid recipe."]); } if (!String.IsNullOrEmpty(_shellSettings.ConnectionString)) { model.ConnectionStringPreset = true; model.ConnectionString = _shellSettings.ConnectionString; } if (!String.IsNullOrEmpty(_shellSettings.DatabaseProvider)) { model.DatabaseProviderPreset = true; model.DatabaseProvider = _shellSettings.DatabaseProvider; } if (!String.IsNullOrEmpty(_shellSettings.TablePrefix)) { model.TablePrefixPreset = true; model.TablePrefix = _shellSettings.TablePrefix; } if (!ModelState.IsValid) { return(View(model)); } var setupContext = new SetupContext { SiteName = model.SiteName, EnabledFeatures = null, // default list, AdminUsername = model.UserName, AdminEmail = model.Email, AdminPassword = model.Password, Errors = new Dictionary <string, string>(), Recipe = selectedRecipe }; if (!model.DatabaseProviderPreset) { setupContext.DatabaseProvider = model.DatabaseProvider; } if (!model.ConnectionStringPreset) { setupContext.DatabaseConnectionString = model.ConnectionString; } if (!model.TablePrefixPreset) { setupContext.DatabaseTablePrefix = model.TablePrefix; } var executionId = await _setupService.SetupAsync(setupContext); // Check if a component in the Setup failed if (setupContext.Errors.Any()) { foreach (var error in setupContext.Errors) { ModelState.AddModelError(error.Key, error.Value); } return(View(model)); } return(Redirect("~/")); }
protected override void Setup(SetupContext context) { context.Package.GetVariable("index").SetValue(0); context.Package.GetVariable("maxIterations").SetValue(5); context.Package.GetVariable("SourcePath").SetValue(Constants.CustomersFileSource); }
public async Task <ActionResult> IndexPOST(SetupViewModel model) { if (!string.IsNullOrWhiteSpace(_shellSettings["Secret"])) { if (string.IsNullOrEmpty(model.Secret) || !await IsTokenValid(model.Secret)) { _logger.LogWarning("An attempt to access '{TenantName}' without providing a valid secret was made", _shellSettings.Name); return(StatusCode(404)); } } model.DatabaseProviders = _databaseProviders; model.Recipes = await _setupService.GetSetupRecipesAsync(); var selectedProvider = model.DatabaseProviders.FirstOrDefault(x => x.Value == model.DatabaseProvider); if (!model.DatabaseConfigurationPreset) { if (selectedProvider != null && selectedProvider.HasConnectionString && String.IsNullOrWhiteSpace(model.ConnectionString)) { ModelState.AddModelError(nameof(model.ConnectionString), S["The connection string is mandatory for this provider."]); } } if (String.IsNullOrEmpty(model.Password)) { ModelState.AddModelError(nameof(model.Password), S["The password is required."]); } if (model.Password != model.PasswordConfirmation) { ModelState.AddModelError(nameof(model.PasswordConfirmation), S["The password confirmation doesn't match the password."]); } RecipeDescriptor selectedRecipe = null; if (!string.IsNullOrEmpty(_shellSettings["RecipeName"])) { selectedRecipe = model.Recipes.FirstOrDefault(x => x.Name == _shellSettings["RecipeName"]); if (selectedRecipe == null) { ModelState.AddModelError(nameof(model.RecipeName), S["Invalid recipe."]); } } else if (String.IsNullOrEmpty(model.RecipeName) || (selectedRecipe = model.Recipes.FirstOrDefault(x => x.Name == model.RecipeName)) == null) { ModelState.AddModelError(nameof(model.RecipeName), S["Invalid recipe."]); } if (!ModelState.IsValid) { CopyShellSettingsValues(model); return(View(model)); } var setupContext = new SetupContext { ShellSettings = _shellSettings, SiteName = model.SiteName, EnabledFeatures = null, // default list, AdminUsername = model.UserName, AdminEmail = model.Email, AdminPassword = model.Password, Errors = new Dictionary <string, string>(), Recipe = selectedRecipe, SiteTimeZone = model.SiteTimeZone }; if (!string.IsNullOrEmpty(_shellSettings["ConnectionString"])) { setupContext.DatabaseProvider = _shellSettings["DatabaseProvider"]; setupContext.DatabaseConnectionString = _shellSettings["ConnectionString"]; setupContext.DatabaseTablePrefix = _shellSettings["TablePrefix"]; } else { setupContext.DatabaseProvider = model.DatabaseProvider; setupContext.DatabaseConnectionString = model.ConnectionString; setupContext.DatabaseTablePrefix = model.TablePrefix; } var executionId = await _setupService.SetupAsync(setupContext); // Check if a component in the Setup failed if (setupContext.Errors.Any()) { foreach (var error in setupContext.Errors) { ModelState.AddModelError(error.Key, error.Value); } return(View(model)); } return(Redirect("~/")); }
public Task <string> Extract(Stream stream, SetupContext context) { var path = Utils.GetTempPath(); return(Task.FromResult(path)); }
protected override void Setup(SetupContext context) { File.Copy(Constants.CustomersWithErrorFileSource, Constants.CustomersFileDestination); context.Package.GetConnection("Customers Src").SetConnectionString(Constants.CustomersWithErrorFileSource); }
public Control GetVisualControl(SetupContext context) { return(new ProgressUIPanel(context)); }
public bool IsApplicationInstalled(SetupContext context) { return(File.Exists(Path.Combine(context.Paths.DefaultInstallationPath, context.Properties[NamingConstants.AppName].ToString()))); }
public ActionResult IndexPOST(SetupViewModel model) { var recipes = OrderRecipes(_setupService.Recipes()); //TODO: Couldn't get a custom ValidationAttribute to validate two properties if (!model.DatabaseOptions && string.IsNullOrEmpty(model.DatabaseConnectionString)) { ModelState.AddModelError("DatabaseConnectionString", T("A SQL connection string is required").Text); } if (!String.IsNullOrWhiteSpace(model.ConfirmPassword) && model.AdminPassword != model.ConfirmPassword) { ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").Text); } if (!model.DatabaseOptions && !String.IsNullOrWhiteSpace(model.DatabaseTablePrefix)) { model.DatabaseTablePrefix = model.DatabaseTablePrefix.Trim(); if (!Char.IsLetter(model.DatabaseTablePrefix[0])) { ModelState.AddModelError("DatabaseTablePrefix", T("The table prefix must begin with a letter").Text); } } if (model.Recipe == null) { if (!(recipes.Select(r => r.Name).Contains(DefaultRecipe))) { ModelState.AddModelError("Recipe", T("No recipes were found in the Setup module").Text); } else { model.Recipe = DefaultRecipe; } } if (!ModelState.IsValid) { model.Recipes = recipes; foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) { model.RecipeDescription = recipe.Description; } model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return(IndexViewResult(model)); } try { var setupContext = new SetupContext { SiteName = model.SiteName, AdminUsername = model.AdminUsername, AdminPassword = model.AdminPassword, DatabaseProvider = model.DatabaseOptions ? "SqlCe" : "SqlServer", DatabaseConnectionString = model.DatabaseConnectionString, DatabaseTablePrefix = model.DatabaseTablePrefix, EnabledFeatures = null, // default list Recipe = model.Recipe }; string executionId = _setupService.Setup(setupContext); // First time installation if finally done. Tell the background views compilation // process to stop, so that it doesn't interfere with the user (asp.net compilation // uses a "single lock" mechanism for compiling views). _viewsBackgroundCompilation.Stop(); // redirect to the welcome page. return(Redirect("~/")); } catch (Exception ex) { Logger.Error(ex, "Setup failed"); _notifier.Error(T("Setup failed: {0}", ex.Message)); model.Recipes = recipes; foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) { model.RecipeDescription = recipe.Description; } model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return(IndexViewResult(model)); } }
public async Task BeforeUninstall(SetupContext context) { JsEvaluator.Init(); var result = await Evaluate(); }
public Task OnUninstall(SetupContext context) { return(Task.CompletedTask); }
public async Task <ActionResult> IndexPOST(SetupViewModel model) { model.DatabaseProviders = GetDatabaseProviders(); var selectedProvider = model.DatabaseProviders.FirstOrDefault(x => x.Value == model.DatabaseProvider); if (selectedProvider != null && selectedProvider.HasConnectionString && String.IsNullOrWhiteSpace(model.ConnectionString)) { ModelState.AddModelError("ConnectionString", T["The connection string is mandatory for this provider"]); } if (String.IsNullOrEmpty(model.Password)) { ModelState.AddModelError(nameof(model.Password), T["The password is required"]); } if (model.Password != model.PasswordConfirmation) { ModelState.AddModelError(nameof(model.PasswordConfirmation), T["The password confirmation doesn't match the password."]); } if (!ModelState.IsValid) { return(IndexViewResult(model)); } var setupContext = new SetupContext { SiteName = model.SiteName, DatabaseProvider = model.DatabaseProvider, DatabaseConnectionString = model.ConnectionString, DatabaseTablePrefix = model.TablePrefix, EnabledFeatures = null, // default list, AdminUsername = model.AdminUserName, AdminEmail = model.AdminEmail, AdminPassword = model.Password, Errors = new Dictionary <string, string>() }; var executionId = await _setupService.SetupAsync(setupContext); // Check if a component in the Setup failed if (setupContext.Errors.Any()) { foreach (var error in setupContext.Errors) { ModelState.AddModelError(error.Key, error.Value); } return(IndexViewResult(model)); } var urlPrefix = ""; if (!String.IsNullOrWhiteSpace(_shellSettings.RequestUrlPrefix)) { urlPrefix = _shellSettings.RequestUrlPrefix + "/"; } return(Redirect("~/" + urlPrefix)); }