we are working on a project with photo intrusion detector, every time the intrusion detector is triggered, we receive a photo in our plugin. After that we trigger an event on the event server including a photo, you can see the code.
In other situations we trigger an alarm including the photo. From the Xprotect client user interface we check the events and for each event with photo we can see the photo without problems but the same operation with alarms is not possible.
we need to link photo to alarm but it doesn’t work we have done our best using the sdk. Could you help us?
private void SendInfoToMilestone(InterProcessMessage msg)
{
string messageId = EventTranslator.GetEventName(msg.Event);
string customTag = $"{msg.Event}; {msg.SourceType}: ";
//Obtenemos el item
Item item = Configuration.Instance.GetItemConfiguration(AjaxCommonDefinitions.PluginId, msg.ItemKind, msg.ItemId);
switch (msg.SourceType)
{
case SourceTypes.Hub:
customTag += $"'{[item.Name](https://item.Name)}'";
break;
case SourceTypes.Group:
case SourceTypes.Device:
case SourceTypes.Output:
Item parentItem = item.GetParent();
if (parentItem != null)
{
customTag += $"'{[parentItem.Name](https://parentItem.Name)}'";
}
customTag += $"'{[item.Name](https://item.Name)}'";
break;
default:
Logger.LogError(LogSources.AjaxEvents, $"Events for this type of source are not implemented yet: '{msg.SourceType}'.");
break;
}
if (item != null)
{
SnapshotList snapshots = new SnapshotList();
if (msg.OtherData.ContainsKey("Images"))
{
object imagesObject = msg.OtherData\["Images"\];
if (imagesObject != null)
{
List<byte\[\]> images = (List<byte\[\]>)imagesObject;
foreach (var image in images)
{
snapshots.Add(new Snapshot()
{
TimeOffset = 0,
//Width = 640,
//Height = 480,
HasOverlay = false,
FQID = item.FQID,
SizeInBytes = (uint)image.Length,
Image = image,
});
}
}
}
//UpdateStatusFromEvent(item, msg);
SendMessageToMilestone(item, messageId, customTag, null, snapshots);
//TRIGGER ALARMS
if (msg.SourceType != SourceTypes.Device)
return;
if (messageId != AjaxEvents.DeviceAlarmStart.ToString())
return;
bool.TryParse(item.GetProperty(AjaxSettingsKey.DeviceTriggerAlarms), out bool triggerAlarms);
if (triggerAlarms)
{
List<Item> associatedCameraItemList = new List<Item>();
string zoneAssociatedCamerasGuids = item.GetProperty(AjaxSettingsKey.DeviceAssociatedCamerasGuids);
if (!string.IsNullOrWhiteSpace(zoneAssociatedCamerasGuids))
associatedCameraItemList = AjaxUtils.GetAssociatedCameras(zoneAssociatedCamerasGuids);
SendAlarmToMilestone(item, associatedCameraItemList, messageId.ToString(), customTag, snapshots);
}
}
}
private void SendAlarmToMilestone(Item zoneItem, List associatedCameraItemList, string message, string customTag, SnapshotList snapshotList)
{
string ALARM_HEADER_TYPE = “alarm type”;
EventSource eventSource = new EventSource()
{
FQID = zoneItem.FQID,
Name = [zoneItem.Name](https://zoneItem.Name)
};
EventHeader eventHeader = new EventHeader()
{
ID = Guid.NewGuid(),
Type = ALARM\_HEADER\_TYPE,
Timestamp = DateTime.Now,
Message = message,
Source = eventSource,
CustomTag = customTag,
};
ReferenceList referenceList = new ReferenceList();
referenceList.AddRange(associatedCameraItemList.Select(e => new Reference() { FQID = e?.FQID }));
Alarm alarm = new Alarm()
{
EventHeader = eventHeader,
ReferenceList = referenceList,
SnapshotList = snapshotList,
};
// Send the Alarm directly to the EventServer, to store in the Alarm database. No event which could trigger a rule is being activated.
EnvironmentManager.Instance.SendMessage(new VideoOS.Platform.Messaging.Message(MessageId.Server.NewAlarmCommand) { Data = alarm });
}
private void SendMessageToMilestone(Item item, string messageId, string customTag, string description, SnapshotList snapshotList)
{
if (!AjaxLicenseManager.Instance.LicenciaActiva)
{
Logger.LogError(LogSources.MilestonePlugin\_Background, "Events will not be triggered. License is not active.");
return;
}
if (item != null)
{
EventSource eventSource = new EventSource()
{
FQID = item.FQID,
Name = string.IsNullOrEmpty(description) ? [item.Name](https://item.Name) : description,
};
EventHeader eventHeader = new EventHeader()
{
ID = Guid.NewGuid(),
Type = EVENT\_HEADER\_TYPE,
Timestamp = DateTime.Now,
Message = messageId,
Source = eventSource,
CustomTag = customTag,
};
AnalyticsEvent analyticsEvent = new AnalyticsEvent()
{
EventHeader = eventHeader,
SnapshotList = snapshotList,
};
Message msg = new Message(MessageId.Server.NewEventCommand)
{
Data = analyticsEvent,
};
[if](javascript:void(0); “if”) DEBUG
Logger.LogDebug(LogSources.AjaxEvents, $"Sending Event to Milestone: {messageId} from {[eventSource.Name](https://eventSource.Name)} ({customTag})");
[#endif](javascript:void(0); “#endif”)
EnvironmentManager.Instance.SendMessage(msg);
[if](javascript:void(0); “if”) DEBUG
Logger.LogDebug(LogSources.AjaxEvents, $"Event sent to Milestone: {messageId} from {[eventSource.Name](https://eventSource.Name)} ({customTag})");
[#endif](javascript:void(0); “#endif”)
}
else
{
Logger.LogInfo(LogSources.AjaxEvents,
$"Event {messageId} will not be sent to Milestone, because the related item does not exist.");
}
}
