Example #1
0
        private void AddOrReplaceAlarms(IEnumerable <Alarm> curPlcAlarms, out List <Alarm> addedAlarms, out List <Alarm> changedAlarms)
        {
            var addedAlarmsTmp   = new List <Alarm>();
            var changedAlarmsTmp = new List <Alarm>();

            foreach (IGrouping <short, Alarm> alarmsBySource in curPlcAlarms.GroupBy(a => a.SourceControllerId))
            {
                // controller ID=0 doesn't exist --> so we don't have to search the controller tree
                if (alarmsBySource.Key != 0)
                {
                    IGrouping <short, Alarm> source = alarmsBySource;
                    RootController.VisitAndAbortOnSuccess(c => c.ChildsCollection, c => c.Id == source.Key, c =>
                    {
                        foreach (var alarm in source)
                        {
                            if (alarm.Id != INVALID_ALARMID)
                            {
                                if (c.TryAddAlarm(alarm))
                                {
                                    addedAlarmsTmp.Add(alarm);
                                }
                                else if (c.TryReplaceAlarm(alarm))
                                {
                                    changedAlarmsTmp.Add(alarm);
                                }
                            }
                        }
                    });
                }
            }

            addedAlarms   = new List <Alarm>(addedAlarmsTmp);
            changedAlarms = new List <Alarm>(changedAlarmsTmp);
        }
Example #2
0
        /// <summary>
        /// Gets the controller with the specified <paramref name="id"/>.
        /// </summary>
        /// <param name="id">The id of the desired controller.</param>
        /// <returns>A <see cref="Controller"/> instance.</returns>
        public Controller TryGetController(int id)
        {
            Controller controller = null;

            RootController.VisitAndAbortOnSuccess(c => c.ChildsCollection, c => c.Id == id, c => controller = c);
            return(controller);
        }
Example #3
0
        /// <summary>
        /// Gets all overall information tags of this controller tree.
        /// </summary>
        /// <returns>An <see cref="IReadOnlyCollection{T}"/> of <see cref="Tag"/> instances.</returns>
        public IReadOnlyCollection <Tag> GetOverallInformationTags()
        {
            var overallInformationTags = new List <Tag>();

            RootController.VisitAllNodes(
                c => c.ChildsCollection,
                c => overallInformationTags.AddRange(c.GetOverallInformationTags()));
            return(overallInformationTags.ToReadOnly());
        }
Example #4
0
        /// <summary>
        /// Updates the alarms in any controller. Compares the alarms of all controllers with
        /// <paramref name="currentPlcAlarms"/>. Removes alarms from controllers that doesn't exist
        /// in the <paramref name="currentPlcAlarms"/> anymore.
        /// Add alarms from <paramref name="currentPlcAlarms"/> to controllers that not already were added.
        /// </summary>
        /// <param name="currentPlcAlarms">The current pending alarms from PLC.</param>
        public void UpdateAlarms(IEnumerable <Alarm> currentPlcAlarms)
        {
            List <Alarm> currentAlarmsList = currentPlcAlarms.ToList();
            List <Alarm> removedAlarms, addedAlarms, changedAlarms;

            lock (_lockObject)
            {
                // iterate through all controllers and get the alarms
                var curControllersByAlarmId = new Dictionary <uint, List <IController> >();
                var collectAlarmsById       = new Action <Controller>(c =>
                {
                    foreach (var alarm in c.Alarms)
                    {
                        if (!curControllersByAlarmId.ContainsKey(alarm.Id))
                        {
                            var ctrlList = new List <IController> {
                                c
                            };
                            curControllersByAlarmId.Add(alarm.Id, ctrlList);
                        }
                        else
                        {
                            curControllersByAlarmId[alarm.Id].Add(c);
                        }
                    }
                });

                RootController.VisitAllNodes(c => c.ChildsCollection, collectAlarmsById);

                // remove alarms
                removedAlarms = RemoveAlarms(currentAlarmsList, curControllersByAlarmId);

                // add or replace alarms
                AddOrReplaceAlarms(currentAlarmsList, out addedAlarms, out changedAlarms);
            }

            // raise event
            if (addedAlarms.Count > 0)
            {
                AlarmsAdded(addedAlarms);
            }

            // raise event
            if (removedAlarms.Count > 0)
            {
                AlarmsRemoved(removedAlarms);
            }

            // raise event
            if (changedAlarms.Count > 0)
            {
                AlarmsChanged(changedAlarms);
            }
        }
Example #5
0
        /// <summary>
        /// Gets all <see cref="IAlarm"/> instances assigned to controller in this tree.
        /// </summary>
        /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="IAlarm"/> implementations.</returns>
        public IEnumerable <IAlarm> GetAllAlarms()
        {
            var alarms = new List <IAlarm>();

            lock (_lockObject)
            {
                RootController.VisitAllNodes(c => c.ChildsCollection, c => alarms.AddRange(c.Alarms));
            }

            return(alarms);
        }
Example #6
0
        /// <summary>
        /// Gets all controller instances in this tree as a collection.
        /// </summary>
        /// <returns>An <see cref="IReadOnlyCollection{T}"/> of <see cref="IController"/> instances.</returns>
        public IReadOnlyCollection <IController> GetAllControllers()
        {
            if (RootController == null)
            {
                return(new IController[0]);
            }
            ICollection <IController> controllersToReturn = new List <IController>();

            RootController.VisitAllNodes(c => c.ChildsCollection, controllersToReturn.Add);
            return(controllersToReturn.ToReadOnly());
        }
Example #7
0
 public SetAll2AutoModeCommand(RootController controller)
 {
     _controller = controller;
 }
Example #8
0
 /// <summary>
 /// Sends the reset alarms command to PLC.
 /// </summary>
 public void AcknowledgeAlarms()
 {
     RootController.ResetModuleAlarms();
 }