private void UpdateAlarm(ConditionState node, SimAlarmStateBackend alarm, string eventId = null) { ISystemContext context = _nodeManager.SystemContext; // remove old event. if (node.EventId.Value != null) { _events.Remove(Utils.ToHexString(node.EventId.Value)); } node.EventId.Value = eventId != null?Encoding.UTF8.GetBytes(eventId) : Guid.NewGuid().ToByteArray(); node.Time.Value = DateTime.UtcNow; node.ReceiveTime.Value = node.Time.Value; // save the event for later lookup. _events[Utils.ToHexString(node.EventId.Value)] = node; // determine the retain state. node.Retain.Value = true; if (alarm != null) { node.Time.Value = alarm.Time; node.Message.Value = new LocalizedText(alarm.Reason); node.SetComment(context, alarm.Comment, alarm.UserName); node.SetSeverity(context, alarm.Severity); node.EnabledState.TransitionTime.Value = alarm.EnableTime; node.SetEnableState(context, (alarm.State & SimConditionStatesEnum.Enabled) != 0); if (node is AlarmConditionState) { AlarmConditionState nodeAlarm = (AlarmConditionState)node; nodeAlarm.SetAcknowledgedState(context, (alarm.State & SimConditionStatesEnum.Acknowledged) != 0); nodeAlarm.SetConfirmedState(context, (alarm.State & SimConditionStatesEnum.Confirmed) != 0); nodeAlarm.SetActiveState(context, (alarm.State & SimConditionStatesEnum.Active) != 0); nodeAlarm.SetSuppressedState(context, (alarm.State & SimConditionStatesEnum.Suppressed) != 0); nodeAlarm.ActiveState.TransitionTime.Value = alarm.ActiveTime; // not interested in inactive alarms if (!nodeAlarm.ActiveState.Id.Value) { nodeAlarm.Retain.Value = false; } } } // check for deleted items. if ((alarm.State & SimConditionStatesEnum.Deleted) != 0) { node.Retain.Value = false; } // not interested in disabled alarms. if (!node.EnabledState.Id.Value) { node.Retain.Value = false; } }
public override void SetValue(string message = "") { ConditionState alarm = GetAlarm(); if (ShouldEvent() || message.Length > 0) { CreateBranch(); int newSeverity = GetSeverity(); alarm.SetSeverity(SystemContext, (EventSeverity)newSeverity); if (message.Length == 0) { message = "Alarm Event Value = " + m_trigger.Value.ToString(); } alarm.Message.Value = new LocalizedText("en", message); ReportEvent(); } }