Esempio n. 1
0
        private void Log_Event(Severity severity, string type, string msg, string moduleID = "", string details = "")
        {
            var module = modules.FirstOrDefault(m => m.ID == moduleID);

            var ae = new AlarmOrEvent()
            {
                ModuleID       = moduleID,
                ModuleName     = module != null ? module.Name : "",
                Time           = Timestamp.Now,
                ReturnToNormal = false,
                IsSystem       = true,
                Severity       = severity,
                Type           = type,
                Message        = msg,
                Details        = details,
            };

            reqHandler.OnAlarmOrEvent(ae);

            switch (severity)
            {
            case Severity.Info:
                logger.Info(msg);
                break;

            case Severity.Warning:
                logger.Warn(msg);
                break;

            case Severity.Alarm:
                logger.Error(msg);
                break;
            }
        }
Esempio n. 2
0
        internal void Notify_AlarmOrEvent(ModuleState module, AlarmOrEventInfo e)
        {
            var ae = new AlarmOrEvent()
            {
                ModuleID        = module.ID,
                ModuleName      = module.Name,
                Time            = e.Time,
                IsSystem        = false,
                Severity        = e.Severity,
                Type            = e.Type,
                Message         = e.Message,
                Details         = e.Details,
                AffectedObjects = e.AffectedObjects,
                Initiator       = e.Initiator
            };

            reqHandler.OnAlarmOrEvent(ae);

            string msg = e.Message;

            switch (e.Severity)
            {
            case Severity.Info:
                module.logger.Info(msg);
                break;

            case Severity.Warning:
                module.logger.Warn(msg);
                break;

            case Severity.Alarm:
                module.logger.Error(msg);
                break;
            }
        }
Esempio n. 3
0
            protected void DispatchEvent(JObject theEvent)
            {
                string eventName = (string)theEvent["event"];

                switch (eventName)
                {
                case "OnVariableValueChanged": {
                    JArray          jVariables = (JArray)theEvent["variables"];
                    VariableValue[] variables  = StdJson.ObjectFromJToken <VariableValue[]>(jVariables);
                    listener.OnVariableValueChanged(variables);
                }
                break;

                case "OnVariableHistoryChanged": {
                    JArray          jChanges  = (JArray)theEvent["changes"];
                    HistoryChange[] variables = StdJson.ObjectFromJToken <HistoryChange[]>(jChanges);
                    listener.OnVariableHistoryChanged(variables);
                }
                break;

                case "OnConfigChanged": {
                    JArray      jChanges = (JArray)theEvent["changedObjects"];
                    ObjectRef[] changes  = StdJson.ObjectFromJToken <ObjectRef[]>(jChanges);
                    listener.OnConfigChanged(changes);
                }
                break;

                case "OnAlarmOrEvent": {
                    AlarmOrEvent alarmOrEvent = StdJson.ObjectFromJToken <AlarmOrEvent>(theEvent["alarmOrEvent"]);
                    listener.OnAlarmOrEvent(alarmOrEvent);
                }
                break;

                default:
                    Console.Error.WriteLine("Unknown event: " + eventName);
                    break;
                }
            }
Esempio n. 4
0
        internal void Notify_AlarmOrEvent(ModuleState module, AlarmOrEventInfo e)
        {
            Origin?initiator = e.Initiator;

            if (initiator.HasValue)
            {
                Origin origin = initiator.Value;
                string id     = origin.ID;
                if (origin.Type == OriginType.User)
                {
                    User user = userManagement.Users.FirstOrDefault(u => u.ID == id);
                    if (user != null)
                    {
                        origin.Name = user.Name;
                    }
                    else if (origin.Name == null)
                    {
                        origin.Name = "";
                    }
                }
                else if (origin.Type == OriginType.Module)
                {
                    var theModule = modules.FirstOrDefault(m => m.ID == id);
                    if (theModule != null)
                    {
                        origin.Name = theModule.Name;
                    }
                    else if (origin.Name == null)
                    {
                        origin.Name = "";
                    }
                }
                initiator = origin;
            }

            var ae = new AlarmOrEvent()
            {
                ModuleID        = module.ID,
                ModuleName      = module.Name,
                Time            = e.Time,
                IsSystem        = false,
                Severity        = e.Severity,
                ReturnToNormal  = e.ReturnToNormal,
                Type            = e.Type,
                Message         = e.Message,
                Details         = e.Details,
                AffectedObjects = e.AffectedObjects,
                Initiator       = initiator
            };

            reqHandler.OnAlarmOrEvent(ae);

            bool logInfo = module.UpdateWarningAlarmState(e);

            string msg = e.Message;

            switch (e.Severity)
            {
            case Severity.Info:
                if (logInfo)
                {
                    module.logger.Info(msg);
                }
                break;

            case Severity.Warning:
                module.logger.Warn(msg);
                break;

            case Severity.Alarm:
                module.logger.Error(msg);
                break;
            }
        }