public PluginPermissionsManager GetPermissionsManager(string connectionString)
        {
            WorkOrderPnContextFactory contextFactory = new WorkOrderPnContextFactory();
            WorkOrderPnDbContext      context        = contextFactory.CreateDbContext(new[] { connectionString });

            return(new PluginPermissionsManager(context));
        }
示例#2
0
 public SiteAddedHandler(eFormCore.Core sdkCore, DbContextHelper dbContextHelper,
                         IWorkOrdersLocalizationService workOrdersLocalizationService)
 {
     _dbContext = dbContextHelper.GetDbContext();
     _sdkCore   = sdkCore;
     _workOrdersLocalizationService = workOrdersLocalizationService;
 }
        public void SeedDatabase(string connectionString)
        {
            // Get DbContext
            WorkOrderPnContextFactory contextFactory = new WorkOrderPnContextFactory();

            using WorkOrderPnDbContext context = contextFactory.CreateDbContext(new[] { connectionString });
            // Seed configuration
            WorkOrdersPluginSeed.SeedData(context);
        }
示例#4
0
        private void GetContext(string connectionStr)
        {
            WorkOrderPnContextFactory contextFactory = new WorkOrderPnContextFactory();

            DbContext = contextFactory.CreateDbContext(new[] { connectionStr });

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
 public WorkOrdersService(
     WorkOrderPnDbContext dbContext,
     IWorkOrdersLocalizationService workOrdersLocalizationService,
     ILogger <WorkOrdersService> logger,
     IEFormCoreService coreService,
     IUserService userService)
 {
     _dbContext = dbContext;
     _workOrdersLocalizationService = workOrdersLocalizationService;
     _logger      = logger;
     _coreService = coreService;
     _userService = userService;
 }
示例#6
0
 public WorkOrdersSettingsService(WorkOrderPnDbContext dbContext,
                                  ILogger <WorkOrdersSettingsService> logger,
                                  IWorkOrdersLocalizationService workOrdersLocalizationService,
                                  IEFormCoreService core,
                                  IPluginDbOptions <WorkOrdersBaseSettings> options,
                                  IUserService userService,
                                  IRebusService rebusService)
 {
     _dbContext = dbContext;
     _logger    = logger;
     _workOrdersLocalizationService = workOrdersLocalizationService;
     _core         = core;
     _options      = options;
     _userService  = userService;
     _rebusService = rebusService;
     _bus          = _rebusService.GetBus();
 }
        public void ConfigureDbContext(IServiceCollection services, string connectionString)
        {
            _connectionString = connectionString;
            services.AddDbContext <WorkOrderPnDbContext>(o => o.UseMySql(connectionString, new MariaDbServerVersion(
                                                                             new Version(10, 4, 0)), mySqlOptionsAction: builder =>
            {
                builder.EnableRetryOnFailure();
                builder.MigrationsAssembly(PluginAssembly().FullName);
            }));

            WorkOrderPnContextFactory contextFactory = new WorkOrderPnContextFactory();
            WorkOrderPnDbContext      context        = contextFactory.CreateDbContext(new[] { connectionString });

            context.Database.Migrate();

            // Seed database
            SeedDatabase(connectionString);
        }
示例#8
0
        public async Task Create(WorkOrderPnDbContext dbContext)
        {
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;
            Version       = 1;
            WorkflowState = Constants.WorkflowStates.Created;

            await dbContext.AddAsync(this).ConfigureAwait(false);

            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            var res = MapVersion(this);

            if (res != null)
            {
                await dbContext.AddAsync(res).ConfigureAwait(false);

                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public static void SeedData(WorkOrderPnDbContext dbContext)
        {
            WorkOrdersConfigurationSeedData seedData = new WorkOrdersConfigurationSeedData();

            PluginConfigurationValue[] configurationList = seedData.Data;
            foreach (PluginConfigurationValue configurationItem in configurationList)
            {
                if (!dbContext.PluginConfigurationValues.Any(x => x.Name == configurationItem.Name))
                {
                    PluginConfigurationValue newConfigValue = new PluginConfigurationValue()
                    {
                        Name            = configurationItem.Name,
                        Value           = configurationItem.Value,
                        CreatedAt       = DateTime.UtcNow,
                        UpdatedAt       = DateTime.UtcNow,
                        Version         = 1,
                        WorkflowState   = Constants.WorkflowStates.Created,
                        CreatedByUserId = 1
                    };
                    dbContext.PluginConfigurationValues.Add(newConfigValue);
                    dbContext.SaveChanges();
                }
            }

            // Seed plugin permissions
            IEnumerable <PluginPermission> newPermissions = WorkOrdersPermissionsSeedData.Data
                                                            .Where(p => dbContext.PluginPermissions.All(x => x.ClaimName != p.ClaimName))
                                                            .Select(p => new PluginPermission
            {
                PermissionName  = p.PermissionName,
                ClaimName       = p.ClaimName,
                CreatedAt       = DateTime.UtcNow,
                Version         = 1,
                WorkflowState   = Constants.WorkflowStates.Created,
                CreatedByUserId = 1
            });

            dbContext.PluginPermissions.AddRange(newPermissions);

            dbContext.SaveChanges();
        }
示例#10
0
        private async Task UpdateInternal(WorkOrderPnDbContext dbContext, string state = null)
        {
            if (state != null)
            {
                WorkflowState = state;
            }

            if (dbContext.ChangeTracker.HasChanges())
            {
                Version  += 1;
                UpdatedAt = DateTime.UtcNow;

                await dbContext.SaveChangesAsync();

                var res = MapVersion(this);
                if (res != null)
                {
                    await dbContext.AddAsync(res).ConfigureAwait(false);

                    await dbContext.SaveChangesAsync().ConfigureAwait(false);
                }
            }
        }
        private async void SeedWorkOrderForms(IServiceCollection serviceCollection)
        {
            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
            IPluginDbOptions <WorkOrdersBaseSettings> pluginDbOptions =
                serviceProvider.GetRequiredService <IPluginDbOptions <WorkOrdersBaseSettings> >();

            Core core = await serviceProvider.GetRequiredService <IEFormCoreService>().GetCore();

            WorkOrderPnDbContext context = serviceProvider.GetRequiredService <WorkOrderPnDbContext>();

            if (pluginDbOptions.Value.NewTaskId == 0)
            {
                int newTaskId = await SeedHelper.CreateNewTaskEform(core);

                await pluginDbOptions.UpdateDb(settings => settings.NewTaskId = newTaskId, context, 1);
            }

            if (pluginDbOptions.Value.TaskListId == 0)
            {
                int taskListId = await SeedHelper.CreateTaskListEform(core);

                await pluginDbOptions.UpdateDb(settings => settings.TaskListId = taskListId, context, 1);
            }
        }
示例#12
0
 public EFormCompletedHandler(eFormCore.Core sdkCore, DbContextHelper dbContextHelper)
 {
     _dbContext = dbContextHelper.GetDbContext();
     _sdkCore   = sdkCore;
 }
        public bool Start(string sdkConnectionString, string serviceLocation)
        {
            Console.WriteLine("ServiceWorkOrdersPlugin start called");
            try
            {
                string dbNameSection;
                string dbPrefix;
                if (sdkConnectionString.ToLower().Contains("convert zero datetime"))
                {
                    dbNameSection = Regex.Match(sdkConnectionString, @"(Database=\w*;)").Groups[0].Value;
                    dbPrefix      = Regex.Match(sdkConnectionString, @"Database=(\d*)_").Groups[1].Value;
                }
                else
                {
                    dbNameSection = Regex.Match(sdkConnectionString, @"(Initial Catalog=\w*;)").Groups[0].Value;
                    dbPrefix      = Regex.Match(sdkConnectionString, @"Initial Catalog=(\d*)_").Groups[1].Value;
                }


                string pluginDbName     = $"Initial Catalog={dbPrefix}_eform-angular-work-orders-plugin;";
                string connectionString = sdkConnectionString.Replace(dbNameSection, pluginDbName);


                if (!_coreAvailable && !_coreStatChanging)
                {
                    _serviceLocation  = serviceLocation;
                    _coreStatChanging = true;

                    if (string.IsNullOrEmpty(_serviceLocation))
                    {
                        throw new ArgumentException("serviceLocation is not allowed to be null or empty");
                    }

                    if (string.IsNullOrEmpty(connectionString))
                    {
                        throw new ArgumentException("serverConnectionString is not allowed to be null or empty");
                    }

                    WorkOrderPnContextFactory contextFactory = new WorkOrderPnContextFactory();

                    _dbContext = contextFactory.CreateDbContext(new[] { connectionString });
                    _dbContext.Database.Migrate();

                    _dbContextHelper = new DbContextHelper(connectionString);

                    _coreAvailable    = true;
                    _coreStatChanging = false;

                    StartSdkCoreSqlOnly(sdkConnectionString);

                    string temp = _dbContext.PluginConfigurationValues
                                  .SingleOrDefault(x => x.Name == "WorkOrdersBaseSettings:MaxParallelism")?.Value;
                    _maxParallelism = string.IsNullOrEmpty(temp) ? 1 : int.Parse(temp);

                    temp = _dbContext.PluginConfigurationValues
                           .SingleOrDefault(x => x.Name == "WorkOrdersBaseSettings:NumberOfWorkers")?.Value;
                    _numberOfWorkers = string.IsNullOrEmpty(temp) ? 1 : int.Parse(temp);

                    _container = new WindsorContainer();
                    _container.Register(Component.For <IWindsorContainer>().Instance(_container));
                    _container.Register(Component.For <DbContextHelper>().Instance(_dbContextHelper));
                    _container.Register(Component.For <eFormCore.Core>().Instance(_sdkCore));
                    _container.Install(
                        new RebusHandlerInstaller()
                        , new RebusInstaller(connectionString, _maxParallelism, _numberOfWorkers)
                        );

                    _bus = _container.Resolve <IBus>();
                }
                Console.WriteLine("WorkOrdersPlugin started");
                return(true);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Start failed " + ex.Message);
                throw;
            }
        }
示例#14
0
 public async Task Delete(WorkOrderPnDbContext dbContext)
 {
     await UpdateInternal(dbContext, Constants.WorkflowStates.Removed).ConfigureAwait(false);
 }
示例#15
0
 public async Task Update(WorkOrderPnDbContext dbContext)
 {
     await UpdateInternal(dbContext).ConfigureAwait(false);
 }