public async Task Setup(InstallDto input) { if (CheckDatabaseInternal()) { throw new UserFriendlyException("Setup process is already done."); } SetConnectionString(input.ConnectionString); _migrator.CreateOrMigrateForHost(SeedHelper.SeedHostDb); if (CheckDatabaseInternal()) { await SetAdminPassword(input.AdminPassword); SetUrl(input.WebSiteUrl, input.ServerUrl); await SetDefaultLanguage(input.DefaultLanguage); await SetSmtpSettings(input.SmtpSettings); await SetBillingSettings(input.BillInfo); } else { throw new UserFriendlyException("Database couldn't be created!"); } }
public ExecutionResult Update(InstallDto installOptions) { var logger = new StringLogger(); try { var files = Directory.GetFiles(installOptions.Directory, "*.nupkg"); if (files.Count() == 0) { logger.Log("No package to uninstall found, proceeding with a normal install."); } if (files.Count() >= 1) { var filename = PackageHelpers.ExtractPackageName(files.First()).Trim(); var packageInfo = new PackageInfo() { Name = filename.Substring(filename.LastIndexOf("\\") + 1), Version = PackageHelpers.ExtractPackageVersion(files.First()).Trim(), InstallationDirectory = installOptions.Directory, Configuration = installOptions.Configuration }; var packageRemover = new PackageRemover(); packageRemover.Logger = logger; var additionalParams = installOptions.AdditionalParameters; packageRemover.Remove(packageInfo, new string[] { installOptions.Directory }, additionalParams, installOptions.UninstallScript); } var packageInfo2 = new PackageInfo() { Configuration = installOptions.Configuration, InstallationDirectory = installOptions.Directory, Name = installOptions.Application, Version = installOptions.Version }; var PackageInstaller = new PackageInstaller(); PackageInstaller.Logger = logger; PackageInstaller.Install(packageInfo2, new string[] { installOptions.Repository }, installOptions.AdditionalParameters, installOptions.InstallScript, installOptions.ConfigurationFile, installOptions.ConfigurationTransform); return(new ExecutionResult() { Success = logger.Logs.All(x => !x.Error), Log = logger.Logs }); } catch (Exception e) { logger.Log(e.InnerException != null ? e.InnerException.Message : e.Message, true); return(new ExecutionResult() { Success = false, Exception = e.InnerException != null ? e.InnerException.Message : e.Message, Log = logger.Logs }); } }
public ExecutionResult Install(InstallDto installOptions) { var logger = new StringLogger(); try { var packageInfo = new PackageInfo(); packageInfo.Configuration = installOptions.Configuration; packageInfo.InstallationDirectory = installOptions.Directory; packageInfo.Name = installOptions.Application; packageInfo.Version = installOptions.Version; var PackageInstaller = new PackageInstaller(); PackageInstaller.Logger = logger; PackageInstaller.Install(packageInfo, new string[] { installOptions.Repository }, installOptions.AdditionalParameters, installOptions.InstallScript, installOptions.ConfigurationFile, installOptions.ConfigurationTransform); return(new ExecutionResult() { Success = logger.Logs.All(x => !x.Error), Log = logger.Logs }); } catch (Exception e) { logger.Log(e.InnerException != null ? e.InnerException.Message : e.Message, true); return(new ExecutionResult() { Success = false, Exception = e.InnerException != null ? e.InnerException.Message : e.Message, Log = logger.Logs }); } }
public async Task <ActionResult <InstanceDto> > Install([FromBody] InstallDto model) { ActionResult <InstanceDto> actionResult = NoContent(); try { if (!_context.Relationship.Any()) { await _dBInitializer.SeedRoleAsync(); await _dBInitializer.SeedUserAsync(model); actionResult = Ok(GetInstanceDto()); } else { actionResult = BadRequest(new { code = ApiCode.AlreadyExists, msg = "Already installed", data = GetInstanceDto() }); } } catch (Exception ex) { actionResult = this.ExceptionRequest(ApiCode.Exception, ex.Message, ex); } return(actionResult); }
public async Task <ApiResult <InstanceDto> > Install([FromBody] InstallDto model) { try { if (!_context.Relationship.Any()) { await _dBInitializer.SeedRoleAsync(); await _dBInitializer.SeedUserAsync(model); await _dBInitializer.SeedDictionary(); // await _dBInitializer.SeedI18N(); // actionResult = Ok(GetInstanceDto()); return(new ApiResult <InstanceDto>(ApiCode.Success, "Ok", GetInstanceDto())); } else { return(new ApiResult <InstanceDto>(ApiCode.AlreadyExists, "Already installed", GetInstanceDto())); } } catch (Exception ex) { return(new ApiResult <InstanceDto>(ApiCode.Exception, ex.Message, null)); } }
public ExecutionResult Install(InstallDto installOptions) { var logger = new StringLogger(); try { var packageInfo = new PackageInfo(); packageInfo.Configuration = installOptions.Configuration; packageInfo.InstallationDirectory = installOptions.Directory; packageInfo.Name = installOptions.Application; packageInfo.Version = installOptions.Version; var PackageInstaller = new PackageInstaller(); PackageInstaller.Logger = logger; PackageInstaller.Install(packageInfo, new string[] { installOptions.Repository }, installOptions.AdditionalParameters, installOptions.InstallScript, installOptions.ConfigurationFile, installOptions.ConfigurationTransform); return new ExecutionResult() { Success = true, Log = logger.Logs }; } catch (Exception e) { logger.Log(e.InnerException != null ? e.InnerException.Message : e.Message, true); return new ExecutionResult() { Success = false, Exception = e.InnerException != null ? e.InnerException.Message : e.Message, Log = logger.Logs }; } }
public async Task SeedUserAsync(InstallDto model) { var tenant = _context.Tenant.FirstOrDefault(t => t.EMail == model.TenantEMail); var customer = _context.Customer.FirstOrDefault(t => t.Email == model.CustomerEMail); if (tenant == null && customer == null) { tenant = new Tenant() { Id = Guid.NewGuid(), Name = model.TenantName, EMail = model.TenantEMail }; customer = new Customer() { Id = Guid.NewGuid(), Name = model.CustomerName, Email = model.CustomerEMail }; customer.Tenant = tenant; tenant.Customers = new List <Customer>(); tenant.Customers.Add(customer); _context.Tenant.Add(tenant); _context.Customer.Add(customer); await _context.SaveChangesAsync(); } IdentityUser user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { user = new IdentityUser { Email = model.Email, UserName = model.Email, PhoneNumber = model.PhoneNumber }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, false); await _signInManager.UserManager.AddClaimAsync(user, new Claim(ClaimTypes.Email, model.Email)); await _signInManager.UserManager.AddClaimAsync(user, new Claim(IoTSharpClaimTypes.Customer, customer.Id.ToString())); await _signInManager.UserManager.AddClaimAsync(user, new Claim(IoTSharpClaimTypes.Tenant, tenant.Id.ToString())); await _signInManager.UserManager.AddToRoleAsync(user, nameof(UserRole.Anonymous)); await _signInManager.UserManager.AddToRoleAsync(user, nameof(UserRole.NormalUser)); await _signInManager.UserManager.AddToRoleAsync(user, nameof(UserRole.CustomerAdmin)); await _signInManager.UserManager.AddToRoleAsync(user, nameof(UserRole.TenantAdmin)); await _signInManager.UserManager.AddToRoleAsync(user, nameof(UserRole.SystemAdmin)); } else { throw new Exception(string.Join(',', result.Errors.ToList().Select(ie => $"code={ie.Code},msg={ie.Description}"))); } } var rship = new Relationship { IdentityUser = _context.Users.Find(user.Id), Customer = _context.Customer.Find(customer.Id), Tenant = _context.Tenant.Find(tenant.Id) }; _context.Add(rship); await _context.SaveChangesAsync(); }
public ExecutionResult Update(InstallDto installOptions) { var logger = new StringLogger(); try { var files = Directory.GetFiles(installOptions.Directory, "*.nupkg"); if (files.Count() == 0 ) { logger.Log("No package to uninstall found, proceeding with a normal install."); } if (files.Count() >= 1) { var filename = PackageHelpers.ExtractPackageName(files.First()).Trim(); var packageInfo = new PackageInfo() { Name = filename.Substring(filename.LastIndexOf("\\") + 1), Version = PackageHelpers.ExtractPackageVersion(files.First()).Trim(), InstallationDirectory = installOptions.Directory, Configuration = installOptions.Configuration }; var packageRemover = new PackageRemover(); packageRemover.Logger = logger; var additionalParams = installOptions.AdditionalParameters; packageRemover.Remove(packageInfo, new string[] { installOptions.Directory }, additionalParams, installOptions.UninstallScript); } var packageInfo2 = new PackageInfo() { Configuration = installOptions.Configuration, InstallationDirectory = installOptions.Directory, Name = installOptions.Application, Version = installOptions.Version }; var PackageInstaller = new PackageInstaller(); PackageInstaller.Logger = logger; PackageInstaller.Install(packageInfo2, new string[] { installOptions.Repository }, installOptions.AdditionalParameters, installOptions.InstallScript, installOptions.ConfigurationFile, installOptions.ConfigurationTransform); return new ExecutionResult() { Success = true, Log = logger.Logs }; } catch (Exception e) { logger.Log(e.InnerException != null ? e.InnerException.Message : e.Message, true); return new ExecutionResult() { Success = false, Exception = e.InnerException != null ? e.InnerException.Message : e.Message, Log = logger.Logs }; } }