Macro de configuración de CCURE para eventos personalizados

Configuración de incidentes de Genetec Mission Control™ para control de acceso CCURE 9000

Product
Mission Control
Content type
Mejores prácticas
Language
Español
Last updated
2024-05-10

Las macros son entidades que se usan para agregar funciones personalizadas a Security Center, como la asignación de eventos personalizados de Control de Acceso CCURE 9000 a eventos a toma de acción de Security Center.

Code
using Genetec.Sdk;
using Genetec.Sdk.Entities;
using Genetec.Sdk.Enumerations;
using Genetec.Sdk.Queries;
using Genetec.Sdk.Scripting;
using Genetec.Sdk.Scripting.Interfaces.Attributes;
using Genetec.Plugins.CCure.Requests;
using Genetec.Sdk.Entities.CustomEvents;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml;

[MacroParameters()]
public sealed class myMacro : UserMacro
{
	public Guid CCURERole { get; set; }
	public Guid LogRecipient { get; set; }
	public string AreaPrefix { get; set; }
	public string EventSuffix { get; set; }
	public int CustomEventNo { get; set; }
	public bool ShouldEventsTriggerAlarm { get; set; }
	/// <summary>
	/// Entry point of the macro. Provide an implementation of this method.
	/// </summary>
	public override void Execute()
	{

		var systemConfig = Sdk.GetEntity(SdkGuids.SystemConfiguration) as SystemConfiguration;
		var customEventService = systemConfig.CustomEventService;
		var customEvents = customEventService.CustomEvents;
		var filteredCustomEvents = new List<CustomEvent>();

		var areasPrefixes = AreaPrefix.Split(';');

		foreach (var customEvent in customEvents)
		{
			if (areasPrefixes.Any(a => customEvent.Name.Contains(a)) && customEvent.Name.Contains(EventSuffix))
				filteredCustomEvents.Add(customEvent);
		}

		//Sdk.ActionManager.SendMessage(LogRecipient, string.Join(",", filteredCustomEvents.Select(e => e.Name)), 60);

		// Replace with your CCure role Guid

		var getRequest = Sdk.RequestManager.SendRequest<EventConfigurationsRequest, EventConfigurationsResponse>(CCURERole, new EventConfigurationsRequest());
		var config = getRequest.EventConfigurations;

		foreach (var xfConfig in config)
		{
			if (filteredCustomEvents.Select(e => e.Id).Contains(xfConfig.CustomEventId))
			{
				xfConfig.CustomEventId = CustomEventNo;
				xfConfig.HiddenFromUI = false;
				xfConfig.RaiseEvent = true;
				xfConfig.TriggerAlarm = ShouldEventsTriggerAlarm;
			}
		}

		Sdk.RequestManager.SendRequest<SaveEventConfigRequest, VoidResponse>(CCURERole, new SaveEventConfigRequest(config));
	}

	/// <summary>
	/// Called when the macro needs to clean up. 
	/// </summary>
	protected override void CleanUp()
	{
		// Release objects created by the Execute method, unhook events, and so on.
	}
}

namespace Genetec.Plugins.CCure.Requests
{
	// Request to Get the configuration
	[DataContract(Namespace = "")]
	internal class EventConfigurationsRequest
	{ }

	// Response of the Get Request
	[DataContract(Namespace = "")]
	internal class EventConfigurationsResponse
	{
		[DataMember]
		public List<XfEventConfiguration> EventConfigurations { get; private set; }

		public EventConfigurationsResponse(List<XfEventConfiguration> eventConfigurations)
		{
			EventConfigurations = eventConfigurations;
		}
	}

	// Request to save configuration
	[DataContract(Namespace = "")]
	internal class SaveEventConfigRequest
	{
		[DataMember]
		public List<XfEventConfiguration> Configurations { get; private set; }

		public SaveEventConfigRequest(List<XfEventConfiguration> configurations)
		{
			Configurations = configurations;
		}
	}

	[DataContract(Namespace = "")]
	public class VoidResponse
	{
		public static readonly VoidResponse Instance = new VoidResponse();

		private VoidResponse()
		{ }
	}

	// Configuration, meaning mapping between XfEvents and CustomEvents
	[DataContract(Namespace = "")]
	public class XfEventConfiguration
	{
		[DataMember]
		public Guid AlarmId { get; set; }

		[DataMember]
		public int CustomEventId { get; set; }

		[DataMember]
		public bool HiddenFromUI { get; set; }

		[DataMember]
		public string Name { get; set; }

		[DataMember]
		public bool RaiseEvent { get; set; }

		[DataMember]
		public bool RequireAck { get; set; }

		[DataMember]
		public bool TriggerAlarm { get; set; }

		[DataMember]
		public Guid XfEventCustomEntityId { get; set; }

		[DataMember]
		public List<string> Tags { get; set; }

		public XfEventConfiguration() { }
	}
}