public static void AssertTypes(this AlarmView view, AlarmLevel level, AlarmCategory category, AlarmType type,
                                string typeDescription)
 {
     Assert.AreEqual(view.AlarmTypeDescription, typeDescription);
     Assert.AreEqual(view.AlarmCategoryDescription, category.GetEnumDescription());
     Assert.AreEqual(view.AlarmLevelDescription, level.GetEnumDescription());
 }
Esempio n. 2
0
        public AlarmsRunTarget(
            AlarmCategory alarmCategory,
            INotificationReporter reporter,
            IAlarmsRepository repository,
            IProject project,
            ITimeService timeService,
            INpgsqlConnectionFactory connectionFactory)
        {
            _name              = string.Format("{0} \"{1}\"", Res.Alarms, alarmCategory.Name);
            _reporter          = reporter;
            _timeService       = timeService;
            _repository        = repository;
            _project           = project;
            _connectionFactory = connectionFactory;
            if (alarmCategory.TimeToStoreDb.HasValue)
            {
                _timeToStore = new TimeSpan(alarmCategory.TimeToStoreDb.Value);
            }

            _alarmDigitalValues = new Dictionary <int, AlarmStatus>(alarmCategory.AlarmTags.Count);
            foreach (var t in alarmCategory.AlarmTags)
            {
                _alarmDigitalValues.Add(t.Id, new AlarmStatus(t.Acknowledgeable));
                _alarmPrivileges.Add(t.Id, t.Privilege);
            }

            _updateAlarmTagsDigitalValues = () => UpdateAlarmDigitalValues(GetIoDeviceGroups(alarmCategory));
        }
Esempio n. 3
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     AlarmTag = new AlarmTag {
         DigTag = new DigTag {
             Id       = RandomGenerator.GetRandomInt32(),
             IoDevice = new IoDevice {
                 Id = RandomGenerator.GetRandomInt32()
             }
         },
         Id = RandomGenerator.GetRandomInt32(),
         Acknowledgeable = Acknowledgeable
     };
     AlarmCatetory = new AlarmCategory {
         Name          = "AlarmCategory",
         TimeToStoreDb = TimeToStore
     };
     AlarmCatetory.AlarmTags.Add(AlarmTag);
     Reporter    = new Mock <INotificationReporter>();
     Repository  = new Mock <IAlarmsRepository>();
     Project     = new Mock <IProject>();
     TimeService = new Mock <ITimeService>();
     TimeService.Setup(t => t.UtcTime).Returns(DateTime.UtcNow);
     ConnectionFactory = new Mock <INpgsqlConnectionFactory>();
     Connection        = new NpgsqlConnection();
     ConnectionFactory.Setup(f => f.Create()).Returns(Connection);
     AlarmsRunTarget = new AlarmsRunTarget(
         AlarmCatetory,
         Reporter.Object,
         Repository.Object,
         Project.Object,
         TimeService.Object,
         ConnectionFactory.Object);
 }
Esempio n. 4
0
        public AlarmsRunTarget(
            AlarmCategory alarmCategory,
            INotificationReporter reporter,
            IAlarmsRepository repository,
            IProject project,
            ITimeService timeService,
            INpgsqlConnectionFactory connectionFactory)
        {
            _name = string.Format("{0} \"{1}\"", Res.Alarms, alarmCategory.Name);
            _reporter = reporter;
            _timeService = timeService;
            _repository = repository;
            _project = project;
            _connectionFactory = connectionFactory;
            if (alarmCategory.TimeToStoreDb.HasValue)
            {
                _timeToStore = new TimeSpan(alarmCategory.TimeToStoreDb.Value);
            }

            _alarmDigitalValues = new Dictionary<int, AlarmStatus>(alarmCategory.AlarmTags.Count);
            foreach (var t in alarmCategory.AlarmTags)
            {
                _alarmDigitalValues.Add(t.Id, new AlarmStatus(t.Acknowledgeable));
                _alarmPrivileges.Add(t.Id, t.Privilege);
            }

            _updateAlarmTagsDigitalValues = () => UpdateAlarmDigitalValues(GetIoDeviceGroups(alarmCategory));
        }
Esempio n. 5
0
        private static IEnumerable <Tuple <int, Tuple <int, int>[]> > GetIoDeviceGroups(
            AlarmCategory alarmCategory)
        {
            var ioDeviceGroups = alarmCategory.AlarmTags
                                 .GroupBy(a => a.DigTag.IoDevice)
                                 .Select(g => new Tuple <int, Tuple <int, int>[]>(
                                             g.Key.Id,
                                             g.Select(a => new Tuple <int, int>(a.DigTag.Id, a.Id))
                                             .ToArray()))
                                 .ToArray();

            return(ioDeviceGroups);
        }
Esempio n. 6
0
        public string GetBindingVarInfo()
        {
            if (AlarmCategory.ToUpper().Contains("TRAP"))
            {
                string stSQL;
                stSQL = string.Format("select BindingVarInfo('{0}', {1}, {2}, {3}) from dual",
                                      AlarmInfo, (int)EquipId, (int)AlarmIANA, AlarmNumObj);

                CResultAErreur result = CExecuteurRequeteSpv.ExecuteScalar(0, stSQL);
                return(result.Data.ToString());
            }

            return("");
        }
Esempio n. 7
0
 public IAlarmsRunTarget Create(string connectionString, IProject project, AlarmCategory alarmCategory, ITimeService timeService)
 {
     var npgsqlConnectionFactory = new NpgsqlConnectionFactory(connectionString);
     var alarmsRepository = new AlarmsRepository(alarmCategory.Id);
     using (var connection = npgsqlConnectionFactory.Create())
     {
         alarmsRepository.EnsureTable(connection);
     }
     return new AlarmsRunTarget(
         alarmCategory,
         new NotificationReporter(timeService) {LifeTime = TimeSpan.FromTicks(0)},
         alarmsRepository,
         project,
         timeService,
         npgsqlConnectionFactory);
 }
Esempio n. 8
0
            protected override void EstablishContext()
            {
                base.EstablishContext();
                AlarmCategory = new AlarmCategory
                {
                    Name = "AlarmCategory",
                    Id   = RandomGenerator.GetRandomInt32()
                };
                Categories = new EnumerableQuery <AlarmCategory>(new[] { AlarmCategory });
                Context.Setup(context => context.Get <AlarmCategory>()).Returns(Categories);

                RunTarget = new Mock <IAlarmsRunTarget>();
                AlarmsRunTargetFactory.Setup(f => f.Create(DataDbConStr, ProjectRunner, AlarmCategory, TimeService.Object))
                .Returns(RunTarget.Object);
                CyclicRunner = new Mock <ICyclicRunner>();
                CyclicRunnerFactory.Setup(f => f.Create(RunTarget.Object)).Returns(CyclicRunner.Object);
            }
Esempio n. 9
0
        public IAlarmsRunTarget Create(string connectionString, IProject project, AlarmCategory alarmCategory, ITimeService timeService)
        {
            var npgsqlConnectionFactory = new NpgsqlConnectionFactory(connectionString);
            var alarmsRepository        = new AlarmsRepository(alarmCategory.Id);

            using (var connection = npgsqlConnectionFactory.Create())
            {
                alarmsRepository.EnsureTable(connection);
            }
            return(new AlarmsRunTarget(
                       alarmCategory,
                       new NotificationReporter(timeService)
            {
                LifeTime = TimeSpan.FromTicks(0)
            },
                       alarmsRepository,
                       project,
                       timeService,
                       npgsqlConnectionFactory));
        }
Esempio n. 10
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     AlarmTag = new AlarmTag
                    {
                        DigTag = new DigTag
                                       {
                                           Id = RandomGenerator.GetRandomInt32(),
                                           IoDevice = new PHmiModel.Entities.IoDevice
                                                            {
                                                                Id = RandomGenerator.GetRandomInt32()
                                                            }
                                       },
                        Id = RandomGenerator.GetRandomInt32(),
                        Acknowledgeable = Acknowledgeable
                    };
     AlarmCatetory = new AlarmCategory
                         {
                             Name = "AlarmCategory",
                             TimeToStoreDb = TimeToStore
                         };
     AlarmCatetory.AlarmTags.Add(AlarmTag);
     Reporter = new Mock<INotificationReporter>();
     Repository = new Mock<IAlarmsRepository>();
     Project = new Mock<IProject>();
     TimeService = new Mock<ITimeService>();
     TimeService.Setup(t => t.UtcTime).Returns(DateTime.UtcNow);
     ConnectionFactory = new Mock<INpgsqlConnectionFactory>();
     Connection = new NpgsqlConnection();
     ConnectionFactory.Setup(f => f.Create()).Returns(Connection);
     AlarmsRunTarget = new AlarmsRunTarget(
         AlarmCatetory,
         Reporter.Object,
         Repository.Object,
         Project.Object,
         TimeService.Object,
         ConnectionFactory.Object);
 }
Esempio n. 11
0
            protected override void EstablishContext()
            {
                base.EstablishContext();
                AlarmCategory = new AlarmCategory
                                    {
                                        Name = "AlarmCategory",
                                        Id = RandomGenerator.GetRandomInt32()
                                    };
                Categories = new EnumerableQuery<AlarmCategory>(new[] { AlarmCategory });
                Context.Setup(context => context.Get<AlarmCategory>()).Returns(Categories);

                RunTarget = new Mock<IAlarmsRunTarget>();
                AlarmsRunTargetFactory.Setup(f => f.Create(DataDbConStr, ProjectRunner, AlarmCategory, TimeService.Object))
                    .Returns(RunTarget.Object);
                CyclicRunner = new Mock<ICyclicRunner>();
                CyclicRunnerFactory.Setup(f => f.Create(RunTarget.Object)).Returns(CyclicRunner.Object);
            }
Esempio n. 12
0
 private void AcknowledgeCommandExecuted(object obj)
 {
     AlarmCategory.Acknowledge(Paginator.Items.Where(a => !a.AcknowledgeTime.HasValue).ToArray());
 }
Esempio n. 13
0
 private void AcknowledgeSelectedCommandExecuted(object obj)
 {
     AlarmCategory.Acknowledge(SelectedAlarms.Where(a => !a.AcknowledgeTime.HasValue).ToArray());
 }
Esempio n. 14
0
        /// <summary>
        /// db initialization
        /// </summary>
        private async Task InnitDB(CancellationToken cancellationToken)
        {
            var context = new AlarmContext(FileName);

            var storedCategories = await context.AlarmCategories.ToListAsync(cancellationToken).ConfigureAwait(false);

            var storedInfos = await context.AlarmsInfo.ToListAsync(cancellationToken).ConfigureAwait(false);

            foreach (var cfg in Configs)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                //синхронизируем категорию в 2 хранилища
                var storedCategory = storedCategories.FirstOrDefault(e =>
                                                                     e.Name == cfg.AlarmInfo.Category.Name &&
                                                                     e.Style == cfg.AlarmInfo.Category.Style
                                                                     );

                if (storedCategory == default)
                {
                    storedCategory = new AlarmCategory
                    {
                        Name  = cfg.AlarmInfo.Category.Name,
                        Style = cfg.AlarmInfo.Category.Style,
                    };
                    context.AlarmCategories.Add(storedCategory);
                    storedCategories.Add(storedCategory);
                }

                cfg.AlarmInfo.Category = storedCategory;

                if (!localCategories.Contains(storedCategory))
                {
                    localCategories.Add(storedCategory);
                }

                //синхронизируем алармИнфо
                var storedAlarmInfo = storedInfos.FirstOrDefault(e =>
                                                                 e.Category == cfg.AlarmInfo.Category &&
                                                                 e.FacilityAccessName == cfg.AlarmInfo.FacilityAccessName &&
                                                                 e.DeviceName == cfg.AlarmInfo.DeviceName &&
                                                                 e.Name == cfg.AlarmInfo.Name &&
                                                                 e.Description == cfg.AlarmInfo.Description &&
                                                                 e.Condition == cfg.AlarmInfo.Condition &&
                                                                 e.TemplateTxt == cfg.AlarmInfo.TemplateTxt);

                if (storedAlarmInfo == default)
                {
                    storedAlarmInfo = new AlarmInfo
                    {
                        Category           = cfg.AlarmInfo.Category,
                        FacilityAccessName = cfg.AlarmInfo.FacilityAccessName,
                        DeviceName         = cfg.AlarmInfo.DeviceName,
                        Name        = cfg.AlarmInfo.Name,
                        Description = cfg.AlarmInfo.Description,
                        Condition   = cfg.AlarmInfo.Condition,
                        TemplateTxt = cfg.AlarmInfo.TemplateTxt,
                    };

                    context.AlarmsInfo.Add(storedAlarmInfo);
                    storedInfos.Add(storedAlarmInfo);
                }

                cfg.AlarmInfo = storedAlarmInfo;
            }

            await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            context.Dispose();
        }
Esempio n. 15
0
 private static IEnumerable<Tuple<int, Tuple<int, int>[]>> GetIoDeviceGroups(AlarmCategory alarmCategory)
 {
     var ioDeviceGroups = alarmCategory.AlarmTags
         .GroupBy(a => a.DigTag.IoDevice)
         .Select(g => new Tuple<int, Tuple<int, int>[]>(
             g.Key.Id,
             g.Select(a => new Tuple<int, int>(a.DigTag.Id, a.Id))
             .ToArray()))
         .ToArray();
     return ioDeviceGroups;
 }
Esempio n. 16
0
        public static string GetAlarmCategoryDescription(this AlarmCategory category)
        {
            var tuple = AlarmCategoryDescriptionList.FirstOrDefault(x => x.Item1 == category);

            return((tuple != null) ? tuple.Item2 : "服务质量告警");
        }