using C4IT.XML; using F4SD.ActionConnector.Enumerations; using System; using System.Collections.Generic; using System.Text; using System.Xml; using static C4IT.Logging.cLogManager; namespace F4SD.ActionConnector.Models { public class Trigger { public TriggerEvent Event { get; set; } public IDictionary Actions { get; } = new Dictionary(); public bool IsValid { get; private set; } private const string ActionsNodeName = "Actions"; private const string ActionNodeName = "Action"; internal Trigger(XmlElement xNode, cXmlParser parser) { try { Event = cXmlParser.GetEnumFromAttribute(xNode, "event", TriggerEvent.Unknown); XmlNode actionsNode = xNode.SelectSingleNode(ActionsNodeName); if (actionsNode is null || !(actionsNode is XmlElement actionsNodeElement)) return; ParseActionsNode(actionsNodeElement, parser); IsValid = true; ; } catch (Exception ex) { LogException(ex); } } private void ParseActionsNode(XmlElement actionsNode, cXmlParser parser) { try { parser.EnterElement(ActionsNodeName); var actionNodes = actionsNode.SelectNodes(ActionNodeName); if (actionNodes is null || actionNodes.Count == 0) return; parser.EnterElement(ActionNodeName); foreach (XmlElement actionNode in actionNodes) { try { ActionType type = cXmlParser.GetEnumFromAttribute(actionNode, "Type", ActionType.Unknown); ActionDefinitionBase actionDefinition = null; switch (type) { case ActionType.QuickAction: actionDefinition = new QuickActionDefinition(actionNode, parser); break; case ActionType.HttpCall: break; case ActionType.Unknown: case ActionType.Webhook: default: break; } if (actionDefinition?.Id != null && !Actions.ContainsKey(actionDefinition.Id)) Actions.Add(actionDefinition.Id, actionDefinition); } catch (Exception ex) { LogException(ex); } finally { parser.SelectElementNext(); } } parser.LeaveElement(ActionNodeName); } catch (Exception ex) { LogException(ex); } finally { parser.LeaveElement(ActionsNodeName); } } } }