Files
C4IT-F4SD-Client/F4SD-ActionConnector/Models/Trigger.cs
Meik 0b52999b1d feat: expand cockpit integrations and support workflows
Add Phoenix remote desktop, action connector, documentation engine, and gamification support. Refactor support-case processing and search/action UI, and update installer assets and dependencies.
2026-07-13 11:16:53 +02:00

102 lines
3.3 KiB
C#

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
{
internal class Trigger
{
public TriggerEvent Event { get; set; }
public IDictionary<string, ActionDefinitionBase> Actions { get; } = new Dictionary<string, ActionDefinitionBase>();
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, "action", 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);
}
}
}
}