Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IAlarm
- {
- string MilestoneCameraId { get; set; }
- string AnalyticEventName { get; set; }
- string Description { get; set; }
- }
- public class BaseAlarm : IAlarm
- {
- public string MilestoneCameraId { get; set; }
- public string AnalyticEventName { get; set; }
- public string Description { get; set; }
- public BaseAlarm(string milestoneCameraId, string analyticEventName, string description)
- {
- MilestoneCameraId = milestoneCameraId;
- AnalyticEventName = analyticEventName;
- Description = description;
- }
- }
- public class SendAlarm
- {
- public List<Item> LstItems;
- Item _selectedItem;
- public SendAlarm()
- {
- LoadCams();
- }
- public void LoadCams()
- {
- List<Item> lstItemsAll = Configuration.Instance.GetItemsBySearch("", 50, 5, out _);
- LstItems = new List<Item>();
- foreach (Item itm in lstItemsAll)
- {
- //pouze vstupy
- if ((itm.FQID.Kind == Kind.InputEvent || itm.FQID.Kind == Kind.Output) && itm.HasChildren == HasChildren.No)
- LstItems.Add(itm);
- }
- }
- public List<Item> GetCams()
- {
- return LstItems;
- }
- private Item SearchItem(string milestoneId)
- {
- foreach (Item itm in LstItems)
- {
- if (itm.Name.Contains(milestoneId))
- {
- return itm;
- }
- }
- return null;
- }
- private bool IsItemSelected(IAlarm alarm)
- {
- _selectedItem = SearchItem(alarm.MilestoneCameraId);
- if (_selectedItem == null)
- {
- //kamera v Milestone dle IP nenalezena, zkusim obnovit seznam kamer
- LoadCams();
- //znovu prohledam dle IP
- _selectedItem = SearchItem(alarm.MilestoneCameraId);
- if (_selectedItem == null)
- {
- LogError("Nenalezena kamera pro udalost " + alarm.AnalyticEventName + " dle IP " + alarm.MilestoneCameraId + " v seznamu kamer v Milestone!");
- return false;
- }
- }
- return true;
- }
- private EventSource CreateEventSource()
- {
- return new EventSource()
- {
- // Send empty - it is possible to send without an eventsource, but the intended design is that there should be a source
- // the FQID is primamry used to match up the ObjectId with the a camera.
- FQID = _selectedItem.FQID,
- // If FQID is null, then the Name can be an IP address, and the event server will make a lookup to find the camera
- Name = _selectedItem.Name
- };
- }
- private EventHeader CreateEventHeader(IAlarm alarm)
- {
- return new EventHeader
- {
- ID = Guid.NewGuid(),
- Type = "LoRaEvent",
- Timestamp = DateTime.Now,
- Message = alarm.AnalyticEventName,
- Source = CreateEventSource(),
- CustomTag = "TagFromLoraServer"
- };
- }
- private AnalyticsEvent CreateAnalyticEvent(IAlarm alarm)
- {
- AnalyticsEvent tmp = new AnalyticsEvent
- {
- EventHeader = CreateEventHeader(alarm),
- Location = "Event on cam 1",
- Description = alarm.Type == EAlarmType.Battery ? ((IBatteryAlarm)alarm).Value : alarm.Description,
- Vendor = new Vendor
- {
- Name = alarm.Type.ToString()
- }
- };
- return tmp;
- }
- public bool SendAlarm(IAlarm alarm)
- {
- try
- {
- if (!IsItemSelected(alarm))
- return false;
- //if (chkIncludeOverlay.Checked)
- //{
- // analyticEvent.ObjectList = new AnalyticsObjectList
- // {
- // GetRectangle()
- // };
- //}
- EnvironmentManager.Instance.SendMessage(
- new VideoOS.Platform.Messaging.Message(MessageId.Server.NewEventCommand)
- { Data = CreateAnalyticEvent(alarm) });
- return true;
- }
- catch (Exception e)
- {
- LogError("Milestone.sendAlarm()" + e.Message);
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement