public async Task Update(EformMonitoringPnDbContext dbContext)
        {
            var rule = await dbContext.Rules
                       .FirstOrDefaultAsync(x => x.Id == Id).ConfigureAwait(false);

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

            rule.CheckListId  = CheckListId;
            rule.Subject      = Subject;
            rule.Text         = Text;
            rule.AttachReport = AttachReport;
            rule.RuleType     = RuleType;
            rule.Data         = Data;
            rule.DataItemId   = DataItemId;

            rule.WorkflowState   = WorkflowState;
            rule.UpdatedAt       = UpdatedAt;
            rule.UpdatedByUserId = UpdatedByUserId;
            rule.AttachLink      = AttachLink;
            rule.IncludeValue    = IncludeValue;

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

                await dbContext.RuleVersions.AddAsync(MapVersion(rule)).ConfigureAwait(false);

                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public async Task Create(EformMonitoringPnDbContext dbContext)
        {
            NotificationRule rule = new NotificationRule
            {
                CheckListId     = CheckListId,
                AttachReport    = AttachReport,
                Subject         = Subject,
                Text            = Text,
                Data            = Data,
                DataItemId      = DataItemId,
                RuleType        = RuleType,
                CreatedAt       = DateTime.UtcNow,
                UpdatedAt       = DateTime.UtcNow,
                Version         = 1,
                WorkflowState   = Constants.WorkflowStates.Created,
                UpdatedByUserId = UpdatedByUserId,
                CreatedByUserId = CreatedByUserId,
                AttachLink      = AttachLink,
                IncludeValue    = IncludeValue
            };

            await dbContext.Rules.AddAsync(rule).ConfigureAwait(false);

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

            await dbContext.RuleVersions.AddAsync(MapVersion(rule)).ConfigureAwait(false);

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

            Id = rule.Id;
        }
        private void GetContext(string connectionStr)
        {
            EformMonitoringPnDbContextFactory contextFactory = new EformMonitoringPnDbContextFactory();

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

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
 public RulesService(
     EformMonitoringPnDbContext dbContext,
     IMonitoringLocalizationService localizationService,
     IHttpContextAccessor httpContextAccessor,
     ILogger <RulesService> logger)
 {
     _dbContext           = dbContext;
     _localizationService = localizationService;
     _httpContextAccessor = httpContextAccessor;
     _logger = logger;
 }
 public MonitoringPnSettingsService(ILogger <MonitoringPnSettingsService> logger,
                                    IMonitoringLocalizationService monitoringLocalizationService,
                                    EformMonitoringPnDbContext dbContext,
                                    IPluginDbOptions <MonitoringBaseSettings> options,
                                    IHttpContextAccessor httpContextAccessor)
 {
     _logger                        = logger;
     _dbContext                     = dbContext;
     _options                       = options;
     _httpContextAccessor           = httpContextAccessor;
     _monitoringLocalizationService = monitoringLocalizationService;
 }
Exemple #6
0
        public async Task Delete(EformMonitoringPnDbContext dbContext)
        {
            var deviceUser = await dbContext.DeviceUsers
                             .FirstOrDefaultAsync(x => x.Id == Id);

            if (deviceUser == null)
            {
                throw new NullReferenceException($"Could not find device user in notification rule with id: {Id}");
            }

            deviceUser.WorkflowState = Constants.WorkflowStates.Removed;
            deviceUser.UpdatedAt     = DateTime.UtcNow;
            deviceUser.Version      += 1;

            dbContext.DeviceUsers.Update(deviceUser);
            await dbContext.SaveChangesAsync().ConfigureAwait(false);
        }
        public async Task Delete(EformMonitoringPnDbContext dbContext)
        {
            var recipient = await dbContext.Recipients
                            .FirstOrDefaultAsync(x => x.Id == Id).ConfigureAwait(false);

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

            recipient.WorkflowState = Constants.WorkflowStates.Removed;
            recipient.UpdatedAt     = DateTime.UtcNow;
            recipient.Version      += 1;

            dbContext.Recipients.Update(recipient);
            await dbContext.SaveChangesAsync().ConfigureAwait(false);
        }
Exemple #8
0
        public async Task Create(EformMonitoringPnDbContext dbContext)
        {
            var deviceUser = new DeviceUser
            {
                CreatedAt          = DateTime.UtcNow,
                UpdatedAt          = DateTime.UtcNow,
                Version            = 1,
                WorkflowState      = Constants.WorkflowStates.Created,
                UpdatedByUserId    = UpdatedByUserId,
                CreatedByUserId    = CreatedByUserId,
                NotificationRuleId = NotificationRuleId,
                DeviceUserId       = DeviceUserId,
            };

            await dbContext.DeviceUsers.AddAsync(deviceUser).ConfigureAwait(false);

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

            Id = deviceUser.Id;
        }
        public async Task Create(EformMonitoringPnDbContext dbContext)
        {
            var recipient = new Recipient
            {
                CreatedAt          = DateTime.UtcNow,
                UpdatedAt          = DateTime.UtcNow,
                Version            = 1,
                WorkflowState      = Constants.WorkflowStates.Created,
                UpdatedByUserId    = UpdatedByUserId,
                CreatedByUserId    = CreatedByUserId,
                NotificationRuleId = NotificationRuleId,
                Email = Email,
            };

            await dbContext.Recipients.AddAsync(recipient).ConfigureAwait(false);

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

            Id = recipient.Id;
        }
        public static void SeedData(EformMonitoringPnDbContext dbContext)
        {
            var configurationSeedData = new MonitoringConfigurationSeedData();

            foreach (var configurationItem in configurationSeedData.Data)
            {
                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 = MonitoringPermissionsSeedData.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 async Task Delete(EformMonitoringPnDbContext dbContext)
        {
            var rule = await dbContext.Rules
                       .FirstOrDefaultAsync(x => x.Id == Id).ConfigureAwait(false);

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

            rule.WorkflowState = Constants.WorkflowStates.Removed;

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

                await dbContext.RuleVersions.AddAsync(MapVersion(rule)).ConfigureAwait(false);

                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
 public EFormCompletedHandler(eFormCore.Core sdkCore, EformMonitoringPnDbContext dbContext)
 {
     _dbContext = dbContext;
     _sdkCore   = sdkCore;
 }
        public bool Start(string sdkConnectionString, string serviceLocation)
        {
            Console.WriteLine("ServiceMonitoringPlugin 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;
                }


                var pluginDbName     = $"Initial Catalog={dbPrefix}_eform-angular-monitoring-plugin;";
                var 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");
                    }

                    EformMonitoringPnDbContextFactory contextFactory = new EformMonitoringPnDbContextFactory();

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

                    _coreAvailable    = true;
                    _coreStatChanging = false;

                    StartSdkCoreSqlOnly(sdkConnectionString);

                    _container = new WindsorContainer();
                    _container.Register(Component.For <IWindsorContainer>().Instance(_container));
                    _container.Register(Component.For <EformMonitoringPnDbContext>().Instance(_dbContext));
                    _container.Register(Component.For <eFormCore.Core>().Instance(_sdkCore));
                    _container.Install(
                        new RebusHandlerInstaller()
                        , new RebusInstaller(connectionString, MaxParallelism, NumberOfWorkers)
                        );

                    _bus = _container.Resolve <IBus>();
                }
                Console.WriteLine("ServiceMonitoringPlugin started");
                return(true);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Start failed " + ex.Message);
                throw;
            }
        }