Beispiel #1
0
        public async Task Update(OuterInnerResourcePnDbContext dbContext)
        {
            ResourceTimeRegistration resourceTimeRegistration = dbContext.ResourceTimeRegistrations.FirstOrDefault(x => x.Id == Id);

            if (resourceTimeRegistration == null)
            {
                throw new NullReferenceException($"Could not find area with id: {Id}");
            }

            resourceTimeRegistration.InnerResourceId = InnerResourceId;
            resourceTimeRegistration.OuterResourceId = OuterResourceId;
            resourceTimeRegistration.DoneAt          = DoneAt;
            resourceTimeRegistration.SDKCaseId       = SDKCaseId;
            resourceTimeRegistration.SDKFieldValueId = SDKFieldValueId;
            resourceTimeRegistration.TimeInSeconds   = TimeInSeconds;
            resourceTimeRegistration.TimeInMinutes   = TimeInMinutes;
            resourceTimeRegistration.TimeInHours     = TimeInHours;
            resourceTimeRegistration.SDKSiteId       = SDKSiteId;

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

                dbContext.ResourceTimeRegistrationVersions.Add(MapVersions(resourceTimeRegistration));
                dbContext.SaveChanges();
            }
        }
Beispiel #2
0
 public ResourceTimeRegistrationService(OuterInnerResourcePnDbContext dbContext,
                                        IEFormCoreService coreService)
 {
     _dbContext          = dbContext;
     _coreService        = coreService;
     _deviceUserNames    = new List <KeyValuePair <int, string> >();
     _outerResourceNames = new List <KeyValuePair <int, string> >();
     _innerResourceNames = new List <KeyValuePair <int, string> >();
 }
        //public RentableItemsPnDbAnySql db;

        public void GetContext(string connectionStr)
        {
            OuterInnerResourcePnContextFactory contextFactory = new OuterInnerResourcePnContextFactory();

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

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
 public OuterResourceService(OuterInnerResourcePnDbContext dbContext,
                             IOuterInnerResourceLocalizationService localizationService,
                             ILogger <OuterResourceService> logger,
                             IRebusService rebusService)
 {
     _dbContext           = dbContext;
     _localizationService = localizationService;
     _logger = logger;
     _bus    = rebusService.GetBus();
 }
Beispiel #5
0
        public async Task Create(OuterInnerResourcePnDbContext dbContext)
        {
            CreatedAt     = DateTime.Now;
            UpdatedAt     = DateTime.Now;
            Version       = 1;
            WorkflowState = eForm.Infrastructure.Constants.Constants.WorkflowStates.Created;

            dbContext.OuterInnerResources.Add(this);
            dbContext.SaveChanges();

            dbContext.OuterInnerResourceVersions.Add(MapVersions(this));
            dbContext.SaveChanges();
        }
Beispiel #6
0
 public OuterInnerResourceReportService(ILogger <OuterInnerResourceReportService> logger,
                                        OuterInnerResourcePnDbContext dbContext,
                                        IEFormCoreService coreHelper,
                                        IOuterInnerResourceLocalizationService outerInnerResourceLocalizationService,
                                        IPluginDbOptions <OuterInnerResourceSettings> options,
                                        IExcelService excelService)
 {
     _logger     = logger;
     _dbContext  = dbContext;
     _coreHelper = coreHelper;
     _outerInnerResourceLocalizationService = outerInnerResourceLocalizationService;
     _excelService = excelService;
     _options      = options;
 }
 public OuterInnerResourceSettingsService(
     ILogger <OuterInnerResourceSettingsService> logger,
     OuterInnerResourcePnDbContext dbContext,
     IOuterInnerResourceLocalizationService outerInnerResourceLocalizationService,
     IPluginDbOptions <OuterInnerResourceSettings> options,
     IRebusService rebusService,
     IUserService userService)
 {
     _logger    = logger;
     _dbContext = dbContext;
     _outerInnerResourceLocalizationService = outerInnerResourceLocalizationService;
     _options     = options;
     _bus         = rebusService.GetBus();
     _userService = userService;
 }
Beispiel #8
0
        public async Task Delete(OuterInnerResourcePnDbContext dbContext)
        {
            OuterInnerResource outerInnerResource = dbContext.OuterInnerResources.FirstOrDefault(x => x.Id == Id);

            if (outerInnerResource == null)
            {
                throw new NullReferenceException($"Could not find machineArea with id: {Id}");
            }

            outerInnerResource.WorkflowState = eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed;

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

                dbContext.OuterInnerResourceVersions.Add(MapVersions(outerInnerResource));
                dbContext.SaveChanges();
            }
        }
Beispiel #9
0
        public async Task Delete(OuterInnerResourcePnDbContext dbContext)
        {
            ResourceTimeRegistration resourceTimeRegistration = dbContext.ResourceTimeRegistrations.FirstOrDefault(x => x.Id == Id);

            if (resourceTimeRegistration == null)
            {
                throw new NullReferenceException($"Could not find area with id: {Id}");
            }

            resourceTimeRegistration.WorkflowState = eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed;

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

                dbContext.ResourceTimeRegistrationVersions.Add(MapVersions(resourceTimeRegistration));
                dbContext.SaveChanges();
            }
        }
Beispiel #10
0
        public async Task Update(OuterInnerResourcePnDbContext dbContext)
        {
            InnerResource innerResource = dbContext.InnerResources.FirstOrDefault(x => x.Id == Id);

            if (innerResource == null)
            {
                throw new NullReferenceException($"Could not find Machine with id: {Id}");
            }

            innerResource.Name       = Name;
            innerResource.ExternalId = ExternalId;

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

                dbContext.InnerResourceVersions.Add(MapVersions(innerResource));
                dbContext.SaveChanges();
            }
        }
Beispiel #11
0
        public async Task Update(OuterInnerResourcePnDbContext dbContext)
        {
            OuterInnerResource outerInnerResource = dbContext.OuterInnerResources.FirstOrDefault(x => x.Id == Id);

            if (outerInnerResource == null)
            {
                throw new NullReferenceException($"Could not find machineArea with id: {Id}");
            }

            outerInnerResource.OuterResourceId = OuterResourceId;
            outerInnerResource.InnerResourceId = InnerResourceId;

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

                dbContext.OuterInnerResourceVersions.Add(MapVersions(outerInnerResource));
                dbContext.SaveChanges();
            }
        }
        public static void SeedData(OuterInnerResourcePnDbContext dbContext)
        {
            var seedData = new OuterInnerResourceConfigurationSeedData();
            var configurationList = seedData.Data;
            foreach (var configurationItem in configurationList)
            {
                if (!dbContext.PluginConfigurationValues.Any(x=>x.Name == configurationItem.Name))
                {
                    var newConfigValue = new PluginConfigurationValue()
                    {
                        Name = configurationItem.Name,
                        Value = configurationItem.Value,
                        CreatedAt = DateTime.UtcNow,
                        Version = 1,
                        WorkflowState = Constants.WorkflowStates.Created,
                        CreatedByUserId = 1
                    };
                    dbContext.PluginConfigurationValues.Add(newConfigValue);
                    dbContext.SaveChanges();
                }
            }

            // Seed plugin permissions
            var newPermissions = OuterInnerResourcePermissionsSeedData.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();
        }
 public eFormCompletedHandler(eFormCore.Core sdkCore, DbContextHelper dbContextHelper)
 {
     _dbContext = dbContextHelper.GetDbContext();
     _sdkCore   = sdkCore;
 }
Beispiel #14
0
 public OuterInnerResourceDeleteHandler(Core core, DbContextHelper dbContextHelper)
 {
     _core      = core;
     _dbContext = dbContextHelper.GetDbContext();
 }
 public OuterInnerResourceUpdateHandler(Core core, DbContextHelper dbContextHelper, IBus bus)
 {
     _core      = core;
     _dbContext = dbContextHelper.GetDbContext();
     _bus       = bus;
 }
        public bool Start(string sdkConnectionString, string serviceLocation)
        {
            Console.WriteLine("ServiceOuterInnerResourcePlugin start called");
            try
            {
                var dbNameSection = Regex.Match(sdkConnectionString, @"(Database=\w*;)").Groups[0].Value;
                var dbPrefix      = Regex.Match(sdkConnectionString, @"Database=(\d*)_").Groups[1].Value;

                string pluginDbName     = $"Database={dbPrefix}_eform-angular-outer-inner-resource-plugin;";
                string connectionString = sdkConnectionString.Replace(dbNameSection, pluginDbName);
                string rabbitmqHost     = connectionString.Contains("frontend") ? $"frontend-{dbPrefix}-rabbitmq" :"localhost";

                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");
                    }

                    //OuterInnerResourcePnContextFactory contextFactory = new OuterInnerResourcePnContextFactory();
                    _dbContextHelper = new DbContextHelper(connectionString);

                    _dbContext = _dbContextHelper.GetDbContext();//.CreateDbContext(new[] { connectionString });

                    //_dbContextHelper = new DbContextHelper(connectionString);
                    _dbContext.Database.Migrate();

                    _coreAvailable    = true;
                    _coreStatChanging = false;

                    startSdkCoreSqlOnly(sdkConnectionString);

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

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

                    _container = new WindsorContainer();
                    //_container.Register(Component.For<OuterInnerResourcePnDbContext>().Instance(_dbContext));
                    _container.Register(Component.For <eFormCore.Core>().Instance(_sdkCore));
                    _container.Register(Component.For <DbContextHelper>().Instance(_dbContextHelper));
                    _container.Install(
                        new RebusHandlerInstaller()
                        , new RebusInstaller(connectionString, _maxParallelism, _numberOfWorkers, "admin", "password", rabbitmqHost)
                        );

                    _bus = _container.Resolve <IBus>();

                    temp = _dbContext.PluginConfigurationValues
                           .SingleOrDefault(x => x.Name == "OuterInnerResourceSettings:ShouldCheckAllCases")?.Value;

                    Console.WriteLine("[DBG] ServiceOuterInnerResourcePlugin.Start: ShouldCheckAllCases set to: " + temp);

                    if (temp.ToLower() == "true")
                    {
                        temp = _dbContext.PluginConfigurationValues
                               .SingleOrDefault(x => x.Name == "OuterInnerResourceSettings:SdkeFormId")?.Value;

                        Console.WriteLine("[DBG] ServiceOuterInnerResourcePlugin.Start: SdkeFormId set to: " + temp);
                        _bus.SendLocal(new CheckAllCases(int.Parse(temp)));
                    }
                }
                Console.WriteLine("ServiceOuterInnerResourcePlugin started");
                return(true);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("[ERR] ServiceOuterInnerResourcePlugin.Start: Start failed " + ex.Message);
                throw ex;
            }
        }
 public CheckAllCasesHandler(eFormCore.Core sdkCore, DbContextHelper dbContextHelper, IBus bus)
 {
     _dbContext = dbContextHelper.GetDbContext();
     _sdkCore   = sdkCore;
     _bus       = bus;
 }