| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections.Generic;
- using System.Security.Principal;
- using System.Threading.Tasks;
- using BO.AppServer.Metadata.Dto;
- using BO.AppServer.Metadata.Enums;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Quadarax.Foundation.Core.Business;
- using Quadarax.Foundation.Core.Data.Interface.Entity.Dto;
- namespace BO.AppServer.Business.Services
- {
- public class ConfigurationService : AbstractService
- {
- private IServiceProvider _serviceProvider;
- public Configuration.Configuration Configuration { get; }
- public ConfigurationService(IOptions<Configuration.Configuration> config,
- IServiceProvider serviceProvider,
- IPrincipal currentPrincipal,
- ILoggerFactory logger) : base(currentPrincipal, logger)
- {
- if (config == null)
- throw new ArgumentNullException(nameof(config));
- Configuration = config.Value;
- _serviceProvider = serviceProvider;
- }
- public async Task<ResultPlain> Install()
- {
- using (var scope = _serviceProvider.CreateScope())
- {
- var srvUsers = scope.ServiceProvider.GetRequiredService<UserService>();
-
- await srvUsers.EnsureRolesAsync();
-
- await EnsureUser(srvUsers, Configuration.System.AccountSystem.Name,
- Configuration.System.AccountSystem.Password,
- Configuration.System.AccountSystem.Email,
- Configuration.System.AccountSystem.CultureLcid, new[]
- {
- RoleEnum.System,
- });
- await EnsureUser(srvUsers, Configuration.System.AccountConsole.Name,
- Configuration.System.AccountConsole.Password,
- Configuration.System.AccountConsole.Email,
- Configuration.System.AccountConsole.CultureLcid, new[]
- {
- RoleEnum.System,
- RoleEnum.Console,
- RoleEnum.SuperAdmin
- });
- await EnsureUser(srvUsers, Configuration.System.AccountAdmin.Name,
- Configuration.System.AccountAdmin.Password,
- Configuration.System.AccountAdmin.Email,
- Configuration.System.AccountAdmin.CultureLcid, new[]
- {
- RoleEnum.User,
- RoleEnum.SuperAdmin
- });
- }
- return new ResultPlain();
- }
- public async Task<ResultPlain> InstallDev()
- {
- using (var scope = _serviceProvider.CreateScope())
- {
- var srvCatalogues = scope.ServiceProvider.GetRequiredService<CatalogueService>();
- var srvUsers = scope.ServiceProvider.GetRequiredService<UserService>();
- var srvWorkspaces = scope.ServiceProvider.GetRequiredService<WorkspaceService>();
- var task0 = srvCatalogues.CreateBillingPlanAsync(new BillingPlanCDto()
- {
- Name = "Unlimited",
- Code = "UNLIMITED",
- Description = "This plan is only for testing purpose",
- PstinitialCredits = 1000,
- PstcreditsPerItem = 1,
- Pstwatermark = true,
- Pstquality = 1,
- PstprocessProfile = "PRC01",
- Psttest = true,
- Price = 1,
- Currency = "EUR",
- IsCustom = false,
- IsHidden = false,
- IsEnabled = true
- }, true);
- var task1 = srvCatalogues.CreateMimeTypeAsync(new MimeTypeCDto()
- {
- Mimetype1 = "text/plain",
- Description = "Plain text file",
- Extensions = "txt",
- IsEnabled = true
- }, true);
- var task2 = srvCatalogues.CreateMimeTypeAsync(new MimeTypeCDto()
- {
- Mimetype1 = "text/plain",
- Description = "Plain text file",
- Extensions = "txt",
- IsEnabled = true
- }, true);
- var task3 = EnsureUser(srvUsers, "test", "password", "test@bo.com", 1029,
- new[] { RoleEnum.User, RoleEnum.Admin });
- Task.WhenAll(task0, task1, task2, task3)
- .ContinueWith(async (t) => await srvWorkspaces.CreateWorkspaceAsync(new WorkspaceCDto()
- {
- Name = "TestWorkspace",
- Apipassword = "test",
- BillingPlanCode = "UNLIMITED",
- AssignedUserName = "test"
- })).Wait();
- }
- return new ResultPlain();
- }
- protected async Task EnsureUser(UserService srvUsers, string userName, string userPassword, string userEmail, int prefferedLCID,
- RoleEnum[] roles)
- {
- if (!(srvUsers.ExistsUserByNameAsync(userName).Result.Value))
- await srvUsers.CreateUserAsync(userName,
- userPassword,
- userEmail,
- prefferedLCID, roles);
- else
- await srvUsers.EnusreUserRolesAsync(userName, roles);
- }
- }
- }
|