74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using C4IT.XML;
|
|
using F4SD.ActionConnector.Enumerations;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using System.Xml;
|
|
using static C4IT.Logging.cLogManager;
|
|
|
|
namespace F4SD.ActionConnector.Models
|
|
{
|
|
public class ExternalCommunicationConfiguration
|
|
{
|
|
private const string FileNameConfig = "F4SD-ExternalCommunication-Configuration.xml";
|
|
private const string FileNameConfigSchema = "F4SD-ExternalCommunication-Configuration.xsd";
|
|
public const string ConfigRootElement = "F4SD-ExternalCommunication-Configuration";
|
|
|
|
public IDictionary<TriggerEvent, Trigger> Triggers { get; } = new Dictionary<TriggerEvent, Trigger>();
|
|
|
|
|
|
private const string TriggersNodeName = "Triggers";
|
|
private const string TriggerNodeName = "Trigger";
|
|
|
|
public void Initiate(XmlElement rootElement, cXmlParser parser)
|
|
{
|
|
var CM = MethodBase.GetCurrentMethod();
|
|
LogMethodBegin(CM);
|
|
try
|
|
{
|
|
var triggersNode = rootElement.SelectSingleNode(TriggersNodeName);
|
|
parser.EnterElement(TriggersNodeName);
|
|
|
|
var triggerNodes = triggersNode.SelectNodes(TriggerNodeName);
|
|
|
|
if (triggerNodes is null || triggerNodes.Count == 0)
|
|
return;
|
|
|
|
parser.EnterElement(TriggerNodeName);
|
|
|
|
foreach (XmlElement triggerNodeElement in triggerNodes)
|
|
{
|
|
try
|
|
{
|
|
Trigger trigger = new Trigger(triggerNodeElement, parser);
|
|
|
|
if (trigger is null || !trigger.IsValid || Triggers.ContainsKey(trigger.Event))
|
|
continue;
|
|
|
|
Triggers.Add(trigger.Event, trigger);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogException(ex);
|
|
}
|
|
finally
|
|
{
|
|
parser.SelectElementNext();
|
|
}
|
|
}
|
|
|
|
parser.LeaveElement(TriggerNodeName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogException(ex);
|
|
}
|
|
finally
|
|
{
|
|
parser.LeaveElement(TriggersNodeName);
|
|
LogMethodEnd(CM);
|
|
}
|
|
}
|
|
}
|
|
}
|