Exemplo n.º 1
0
        public Worker()
        {
            cameraList = new List <OpenALPRmilestoneCameraName>();
            CameraMapper.LoadCameraList(cameraList);
            lastMappingUpdateTime = CameraMapper.GetLastWriteTime();

            openALPRList = new List <KeyValuePair <string, string> >();
            OpenALPRLNameHelper.LoadCameraNameList(openALPRList);

            dicBlack = new Dictionary <string, string>();
            AlertListHelper.LoadAlertList(dicBlack);
            lastAlertUpdateTime = AlertListHelper.GetLastWriteTime();
        }
Exemplo n.º 2
0
        private void SendAlarm_New(OpenALPRData plateInfo, string milestoneCameraName, FQID bookmarkFQID)//, string plateFromAlertList, string descFromAlertList)
        {
            FQID fqid = MilestoneServer.GetCameraByName(milestoneCameraName);

            DateTime temp = AlertListHelper.GetLastWriteTime();

            if (temp != lastAlertUpdateTime)
            {
                AlertListHelper.LoadAlertList(dicBlack);
                lastAlertUpdateTime = temp;
                Program.Log.Info("Reload Alert list");
            }

            string plateFromAlertList = plateInfo.Best_plate_number;

            bool existsInAlertList = dicBlack.ContainsKey(plateInfo.Best_plate_number);

            if (!existsInAlertList)
            {
                Program.Log.Info($"{plateFromAlertList} not listed in the alert list.");
                Program.Log.Info($"looking if any candidates listed in the alert list");

                if (plateInfo.Candidates.Count > 0)
                {
                    plateFromAlertList = plateInfo.Candidates.FirstOrDefault().Plate;
                    Program.Log.Info($"Candidate {plateFromAlertList} listed in the alert list");
                }
                else
                {
                    Program.Log.Info($"No any candidates plate number listed in the alert list");
                }
            }
            else
            {
                Program.Log.Info($"{plateFromAlertList} found in the alert list");
            }

            if (existsInAlertList)
            {
                string descFromAlertList = dicBlack[plateFromAlertList];

                Program.Log.Info($"Sending an alert for {plateInfo.Best_plate_number}");

                if (fqid == null)
                {
                    fqid = MilestoneServer.GetCameraByName(milestoneCameraName);
                }

                string cameraName = MilestoneServer.GetCameraName(fqid.ObjectId);

                EventSource eventSource = new EventSource()
                {
                    FQID = fqid,
                    Name = cameraName,
                    //Description = "",
                    //ExtensionData =
                };

                EventHeader eventHeader = new EventHeader()
                {
                    //The unique ID of the event.
                    ID = Guid.NewGuid(),

                    //The class of the event, e.g. "Analytics", "Generic", "User-defined".
                    Class = "Analytics",

                    //The type - a sub-classification - of the event, if applicable.
                    Type = null,

                    //The time of the event.
                    Timestamp = Epoch2LocalDateTime(plateInfo.Epoch_start).AddSeconds(-EpochStartSecondsBefore),

                    //The event message. This is the field that will be matched with the AlarmDefinition message when sending this event to the Event Server.
                    Message = "OpenALPR Alarm",

                    //The event name.
                    Name = plateInfo.Best_plate_number,

                    //The source of the event. This can represent e.g. a camera, a microphone, a user-defined event, etc.
                    Source = eventSource,

                    //The priority of the event.
                    Priority = 2,

                    //The priority name of the event.
                    PriorityName = "Medium",

                    //optional
                    //The message id of the event. The message id coorsponds to the ID part returned in ItemManager.GetKnownEventTypes.
                    MessageId = Guid.Empty,

                    //A custom tag set by the user to filter the events.
                    CustomTag = plateFromAlertList,// the value we got from the config file

                    //The expire time of the event. The event will be deleted from the event database when the time is reached. When creating events a value of DateTime.MinValue (default value) indicates that the default event expire time should be used.
                    ExpireTimestamp = DateTime.Now.AddDays(EventExpireAfterDays),

                    //ExtensionData = System.Runtime .Serialization.
                    //The version of this document schema.
                    Version = null
                };

                Alarm alarm = new Alarm()
                {
                    //The EventHeader, containing information common for all Milestone events.
                    EventHeader = eventHeader,

                    //The current state name.
                    StateName = "In progress",

                    //The current state of the alarm. 0: Any 1: New 4: In progress 9: On hold 11: Closed.
                    State = 4,

                    //The user to which the alarm is currently assigned. Can be seen in the Smart Client dropdown
                    AssignedTo = null,//Environment.UserName,

                    // Other fields could be filled out, e.g. objectList

                    //The current category of the alarm. This should be created first on the Client Management under Alarms then Alaem Data Settings
                    //Category = 0,

                    //The current category name.
                    //CategoryName = null,//"Critical",

                    //The count value, if the alarm is a counting alarm. Default: 0 (no count).
                    Count = 0,

                    //The description of the alarm.
                    Description = descFromAlertList,

                    //The end time of the alarm, if it takes plate over a period of time.
                    EndTime = Epoch2LocalDateTime(plateInfo.Epoch_start).AddSeconds(-EpochStartSecondsBefore),

                    //  ExtensionData =

                    //The location of the alarm (this will typically be the same as the camera's location).
                    //Location = null,

                    //The ObjectList, containing information about the detected object(s) in the scene. //new AnalyticsObjectList()
                    //ObjectList = null,

                    // The ReferenceList, containing any number of references to other entities in the system, e.g. alarms or cameras, by FQID.
                    ReferenceList = new ReferenceList {
                        new Reference {
                            FQID = bookmarkFQID
                        }
                    },                                                                            // save bookmark id

                    //The RuleList, containing information contains information about the rule(s), which triggered the alarm.
                    //RuleList = null,//new RuleList(),

                    //The SnapshotList, containing any number of images related to the alarm. If the Source is a camera, it is not neccesary to attach a snapshot from that camera at the time of the alarm.
                    //SnapshotList = null,// new SnapshotList(),

                    //The start time of the alarm, if it takes plate over a period of time.
                    StartTime = Epoch2LocalDateTime(plateInfo.Epoch_start).AddSeconds(-EpochStartSecondsBefore),

                    //The Vendor, containing information about the analytics vendor including any custom data.
                    Vendor = new Vendor {
                        CustomData = plateInfo.ToString()
                    }                                                         // save json data
                };

                // Send the Alarm directly to the EventServer, to store in the Alarm database. No rule is being activated.
                try
                {
                    using (Impersonation impersonation = new Impersonation(BuiltinUser.NetworkService))
                        EnvironmentManager.Instance.SendMessage(new Message(MessageId.Server.NewAlarmCommand)
                        {
                            Data = alarm
                        });
                }
                catch (Exception ex)
                {
                    Program.Log.Error(null, ex);
                }
            }
        }
Exemplo n.º 3
0
        private void SendAlarm(PlateInfo plateInfo, string milestoneCameraName, FQID bookmarkFQID)//, string plateFromAlertList, string descFromAlertList)
        {
            FQID fqid = MilestoneServer.GetCameraByName(milestoneCameraName);

            DateTime temp = AlertListHelper.GetLastWriteTime();

            if (temp != lastAlertUpdateTime)
            {
                AlertListHelper.LoadAlertList(dicBlack);
                lastAlertUpdateTime = temp;
                Program.Log.Info("Reload Alert list");
            }

            string plateFromAlertList = plateInfo.BestPlateNumber;

            bool existsInAlertList = dicBlack.ContainsKey(plateInfo.BestPlateNumber);

            if (!existsInAlertList)
            {
                Program.Log.Info($"{plateFromAlertList} not listed in the alert list.");
                Program.Log.Info($"looking if any candidates listed in the alert list");

                existsInAlertList = plateInfo.CandidatesPlate.Split(',').Any(p => dicBlack.ContainsKey(p));
                if (existsInAlertList)
                {
                    plateFromAlertList = plateInfo.CandidatesPlate.Split(',').FirstOrDefault(p => dicBlack.ContainsKey(p));
                    Program.Log.Info($"Candidate {plateFromAlertList} listed in the alert list");
                }
                else
                {
                    Program.Log.Info($"No any candidates plate number listed in the alert list");
                }
            }
            else
            {
                Program.Log.Info($"{plateFromAlertList} found in the alert list");
            }

            if (existsInAlertList)
            {
                string descFromAlertList = dicBlack[plateFromAlertList];

                Program.Log.Info($"Sending an alert for {plateInfo.BestPlateNumber}");

                string cameraName = MilestoneServer.GetCameraName(fqid.ObjectId);

                EventSource eventSource = new EventSource()
                {
                    FQID = fqid,
                    Name = cameraName
                };

                EventHeader eventHeader = new EventHeader()
                {
                    ID              = Guid.NewGuid(),
                    Class           = "Analytics",
                    Type            = null,
                    Timestamp       = plateInfo.EpochStart,
                    Message         = "OpenALPR Alarm",
                    Name            = plateInfo.BestPlateNumber,
                    Source          = eventSource,
                    Priority        = 2,
                    PriorityName    = "Medium",
                    MessageId       = Guid.Empty,
                    CustomTag       = plateFromAlertList,// the value we got from the config file
                    ExpireTimestamp = DateTime.Now.AddDays(EventExpireAfterDays),
                    Version         = null
                };


                AnalyticsEvent analyticsEvent = new AnalyticsEvent();
                analyticsEvent.EventHeader = eventHeader;
                analyticsEvent.Location    = cameraName;
                analyticsEvent.Description = "OpenALPR Alarm Event";
                analyticsEvent.Vendor      = new Vendor {
                    CustomData = plateInfo.ToString()
                };
                //analyticsEvent.Vendor.Name = "OpenAlpr";


                EnvironmentManager.Instance.SendMessage(
                    new VideoOS.Platform.Messaging.Message(MessageId.Server.NewEventCommand)
                {
                    Data = analyticsEvent
                });

                Alarm alarm = new Alarm()
                {
                    EventHeader   = eventHeader,
                    StateName     = "In progress",
                    State         = 4,
                    AssignedTo    = null,
                    Count         = 0,
                    Description   = descFromAlertList,
                    EndTime       = plateInfo.EpochStart.AddSeconds(EpochEndSecondsAfter),
                    ReferenceList = new ReferenceList {
                        new Reference {
                            FQID = bookmarkFQID
                        }
                    },
                    StartTime = plateInfo.EpochStart.AddSeconds(-EpochStartSecondsBefore),
                    Vendor    = new Vendor {
                        CustomData = plateInfo.ToString()
                    }
                };

                try
                {
                    using (Impersonation impersonation = new Impersonation(BuiltinUser.NetworkService))
                        EnvironmentManager.Instance.SendMessage(new Message(MessageId.Server.NewAlarmCommand)
                        {
                            Data = alarm
                        });
                }
                catch (Exception ex)
                {
                    Program.Log.Error(null, ex);
                }
            }
        }