Ejemplo n.º 1
0
 public RemapAlarmResult[] RemapAlarms(RemapAlarmsParameter[] parameters)
 {
     if (NotValid())
         return null;
     var results = new RemapAlarmResult[parameters.Length];
     for (var i = 0; i < parameters.Length; i++)
     {
         var result = new RemapAlarmResult();
         var parameter = parameters[i];
         results[i] = result;
         IAlarmsRunTarget runTarget;
         if (!_project.AlarmsRunTargets.TryGetValue(parameter.CategoryId, out runTarget))
             continue;
         AcknowledgeAlarms(parameter, runTarget);
         ReadAlarmStatus(parameter, result, runTarget);
         ReadCurrentAlarms(parameter, result, runTarget);
         ReadHistoryAlarms(parameter, result, runTarget);
         result.Notifications = GetNotifications(runTarget.Reporter.Notifications);
     }
     return results;
 }
Ejemplo n.º 2
0
        private ParametersInfo GetParameters()
        {
            var r = new ParametersInfo();
            var commonAcknowledgeParameters = _commonCategory.AlarmsToAcknowledge();
            var commonCurrentQueries = _commonCategory.QueriesForCurrent();
            r.CommonCurrentInfo.AddRange(commonCurrentQueries.Select(q =>
                new Tuple<Action<Alarm[]>, CriteriaType, int>(q.Item4, q.Item1, q.Item3)));
            var commonHistoryQueries = _commonCategory.QueriesForHistory();
            r.CommonHistoryInfo.AddRange(commonHistoryQueries.Select(q =>
                new Tuple<Action<Alarm[]>, CriteriaType, int>(q.Item4, q.Item1, q.Item3)));
            var commonStatusIsRead = _commonCategory.IsRead();

            foreach (var c in _categories.Values)
            {
                var parameter = new RemapAlarmsParameter
                    {
                        CategoryId = c.Id
                    };
                var addToParameters = false;

                parameter.AcknowledgeParameters = GetAcknowledgeParameters(c, commonAcknowledgeParameters);
                if (parameter.AcknowledgeParameters.Any())
                {
                    addToParameters = true;
                }

                if (c.IsRead() || commonStatusIsRead)
                {
                    parameter.GetStatus = true;
                    addToParameters = true;
                }

                var currentQueries = c.QueriesForCurrent();
                var currentCallbacks = currentQueries.Select(q => q.Item4).ToArray();
                parameter.CurrentParameters = commonCurrentQueries.Concat(currentQueries)
                    .Select(q => new Tuple<CriteriaType, AlarmSampleId, int>(q.Item1, q.Item2, q.Item3))
                    .ToArray();
                if (parameter.CurrentParameters.Any())
                {
                    addToParameters = true;
                }

                var historyQueries = c.QueriesForHistory();
                var historyCallbacks = historyQueries.Select(q => q.Item4).ToArray();
                parameter.HistoryParameters = commonHistoryQueries.Concat(historyQueries)
                    .Select(q => new Tuple<CriteriaType, AlarmSampleId, int>(q.Item1, q.Item2, q.Item3))
                    .ToArray();
                if (parameter.HistoryParameters.Any())
                {
                    addToParameters = true;
                }

                if (addToParameters)
                {
                    r.Parameters.Add(new Tuple<RemapAlarmsParameter, Action<Alarm[]>[], Action<Alarm[]>[]>(
                        parameter, currentCallbacks, historyCallbacks));
                }
            }
            return r;
        }
Ejemplo n.º 3
0
 private static void ReadHistoryAlarms(RemapAlarmsParameter parameter, RemapAlarmResult result, IAlarmsRunTarget runTarget)
 {
     var currentAlarms = new Alarm[parameter.HistoryParameters.Length][];
     for (var i = 0; i < parameter.HistoryParameters.Length; i++)
     {
         var curPar = parameter.HistoryParameters[i];
         currentAlarms[i] = runTarget.GetHistoryAlarms(curPar.Item1, curPar.Item2, curPar.Item3);
     }
     result.History = currentAlarms;
 }
Ejemplo n.º 4
0
 private static void ReadAlarmStatus(RemapAlarmsParameter parameter, RemapAlarmResult result, IAlarmsRunTarget runTarget)
 {
     if (!parameter.GetStatus)
         return;
     var status = runTarget.GetHasActiveAndUnacknowledged();
     result.HasActive = status.Item1;
     result.HasUnacknowledged = status.Item2;
 }
Ejemplo n.º 5
0
 private static void AcknowledgeAlarms(RemapAlarmsParameter parameter, IAlarmsRunTarget runTarget)
 {
     foreach (var p in parameter.AcknowledgeParameters)
     {
         runTarget.Acknowledge(p.Item1, p.Item2);
     }
 }
Ejemplo n.º 6
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     Parameter = new RemapAlarmsParameter
         {
             AcknowledgeParameters = new Tuple<AlarmSampleId[], Identity>[0],
             GetStatus = true,
             CategoryId = Id,
             CurrentParameters = new []
                 {
                     new Tuple<CriteriaType, AlarmSampleId, int>(
                         CriteriaType.DownFromInfinity, new AlarmSampleId(
                             DateTime.Now, RandomGenerator.GetRandomInt32()), RandomGenerator.GetRandomInt32())
                 },
             HistoryParameters = new[]
                 {
                     new Tuple<CriteriaType, AlarmSampleId, int>(
                         CriteriaType.DownFromInfinity, new AlarmSampleId(
                             DateTime.Now, RandomGenerator.GetRandomInt32()), RandomGenerator.GetRandomInt32())
                 },
         };
     AlarmsRunTarget.Setup(t => t.GetHasActiveAndUnacknowledged()).Returns(new Tuple<bool, bool>(true, false)).Verifiable();
     var curPar = Parameter.CurrentParameters.Single();
     Current = new Alarm[0];
     AlarmsRunTarget.Setup(t => t.GetCurrentAlarms(curPar.Item1, curPar.Item2, curPar.Item3)).Returns(Current).Verifiable();
     var histPar = Parameter.HistoryParameters.Single();
     History = new Alarm[0];
     AlarmsRunTarget.Setup(t => t.GetHistoryAlarms(histPar.Item1, histPar.Item2, histPar.Item3)).Returns(History).Verifiable();
     Notification = new Notification(DateTime.Now, "Message", "Short", "Long");
     AlarmsRunTarget.Setup(t => t.Reporter.Notifications).Returns(
         new ReadOnlyObservableCollection<Notification>(new ObservableCollection<Notification>
             {
                 Notification
             })).Verifiable();
     Result = Service.RemapAlarms(new [] {Parameter}).Single();
 }
Ejemplo n.º 7
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     Parameter = new RemapAlarmsParameter
     {
         AcknowledgeParameters = new Tuple<AlarmSampleId[], Identity>[0],
         GetStatus = false,
         CategoryId = Id,
         CurrentParameters = new Tuple<CriteriaType, AlarmSampleId, int>[0],
         HistoryParameters = new Tuple<CriteriaType, AlarmSampleId, int>[0]
     };
     Notification = new Notification(DateTime.Now, "Message", "Short", "Long");
     AlarmsRunTarget.Setup(t => t.Reporter.Notifications).Returns(
         new ReadOnlyObservableCollection<Notification>(new ObservableCollection<Notification>
             {
                 Notification
             })).Verifiable();
     Result = Service.RemapAlarms(new[] { Parameter }).Single();
 }