Exemple #1
0
        public AlarmsRunTarget(
            alarm_categories 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.time_to_store.HasValue)
            {
                _timeToStore = new TimeSpan(alarmCategory.time_to_store.Value);
            }

            _alarmDigitalValues = new Dictionary<int, AlarmStatus>(alarmCategory.alarm_tags.Count);
            foreach (var t in alarmCategory.alarm_tags)
            {
                _alarmDigitalValues.Add(t.id, new AlarmStatus(t.acknowledgeable));
                _alarmPrivileges.Add(t.id, t.privilege);
            }

            _updateAlarmTagsDigitalValues = () => UpdateAlarmDigitalValues(GetIoDeviceGroups(alarmCategory));
        }
 public IAlarmsRunTarget Create(string connectionString, IProject project, alarm_categories 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);
 }
 protected override void EstablishContext()
 {
     base.EstablishContext();
     AlarmTag = new alarm_tags
                    {
                        dig_tags = new dig_tags
                                       {
                                           id = RandomGenerator.GetRandomInt32(),
                                           io_devices = new io_devices
                                                            {
                                                                id = RandomGenerator.GetRandomInt32()
                                                            }
                                       },
                        id = RandomGenerator.GetRandomInt32(),
                        acknowledgeable = Acknowledgeable
                    };
     AlarmCatetory = new alarm_categories
                         {
                             name = "AlarmCategory",
                             time_to_store = TimeToStore
                         };
     AlarmCatetory.alarm_tags.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);
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the alarm_categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToalarm_categories(alarm_categories alarm_categories)
 {
     base.AddObject("alarm_categories", alarm_categories);
 }
 /// <summary>
 /// Create a new alarm_categories object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="name">Initial value of the name property.</param>
 public static alarm_categories Createalarm_categories(global::System.Int32 id, global::System.String name)
 {
     alarm_categories alarm_categories = new alarm_categories();
     alarm_categories.id = id;
     alarm_categories.name = name;
     return alarm_categories;
 }
Exemple #6
0
 private static IEnumerable<Tuple<int, Tuple<int, int>[]>> GetIoDeviceGroups(alarm_categories alarmCategory)
 {
     var ioDeviceGroups = alarmCategory.alarm_tags
         .GroupBy(a => a.dig_tags.io_devices)
         .Select(g => new Tuple<int, Tuple<int, int>[]>(
             g.Key.id,
             g.Select(a => new Tuple<int, int>(a.dig_tags.id, a.id))
             .ToArray()))
         .ToArray();
     return ioDeviceGroups;
 }
Exemple #7
0
            protected override void EstablishContext()
            {
                base.EstablishContext();
                AlarmCategory = new alarm_categories
                                    {
                                        name = "AlarmCategory",
                                        id = RandomGenerator.GetRandomInt32()
                                    };
                Categories = new EnumerableQuery<alarm_categories>(new[] { AlarmCategory });
                Context.Setup(context => context.Get<alarm_categories>()).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);
            }