2using System.Collections.Generic;
3using System.Threading.Tasks;
56 get => this.childNodes;
59 this.childNodes = value;
82 public virtual Task
Parse(XmlElement Xml)
84 List<IStateMachineNode> Children =
null;
86 foreach (XmlNode N
in Xml.ChildNodes)
88 if (N is XmlElement E)
91 Children =
new List<IStateMachineNode>();
97 this.ChildNodes = Children?.ToArray();
99 return Task.CompletedTask;
112 if (!(Result is
null))
116 throw new Exception(
"Expected element: " + typeof(T).FullName);
152 List<T> Result =
null;
159 Result =
new List<T>();
165 return Result?.ToArray() ??
new T[0];
179 where ValueType :
Value
196 Dictionary<Type, bool> Types =
new Dictionary<Type, bool>();
197 int i, c = ValueTypes.Length;
199 if (c != Required.Length)
200 throw new ArgumentException(
"Array lengths must match.", nameof(Required));
202 for (i = 0; i < c; i++)
203 Types[ValueTypes[i]] = Required[i];
208 Types.Remove(Node.GetType());
211 List<IStateMachineNode> ToAdd =
null;
213 foreach (KeyValuePair<Type, bool> P
in Types)
215 Value Result = (
Value)Activator.CreateInstance(P.Key);
218 if (!
string.IsNullOrEmpty(s))
220 s = s.Substring(0, 1).ToLower() + s.Substring(1);
221 if (Xml.HasAttribute(s))
224 ToAdd =
new List<IStateMachineNode>();
226 Result.Node =
Value.ParseAttributeValue(Xml.GetAttribute(s));
230 throw new Exception(
"Required child element (or corresponding attribute) missing: " + Result.
LocalName);
234 if (!(ToAdd is
null))
236 if (this.childNodes is
null)
237 this.childNodes = ToAdd.ToArray();
240 c = this.childNodes.Length;
243 Array.Resize(ref this.childNodes, i);
244 ToAdd.CopyTo(this.childNodes, c);
263 if (Node is T Element)
279 if (!Callback(
this, State))
286 if (!Node.
ForEach(Callback, State))
300 this.stateMachine = Machine;
Abstract base class for State-Machine nodes.
bool ForEach(ForEachCallback Callback, object State)
Iterates through th node and all its child nodes.
abstract string LocalName
Local name
virtual void CheckReferences(StateMachine Machine, Token Token)
Checks references in the node.
virtual Task Parse(XmlElement Xml)
Parses the State-machine node.
IStateMachineNode[] ChildNodes
Child nodes, if available. Null if no children.
virtual string Namespace
Namespace
void ConvertValueAttributeToElement< ValueType >(XmlElement Xml, bool Required)
Converts a value attribute to parsed element. The XML definition has to be parsed before,...
abstract IStateMachineNode Create()
Creates a new node of the corresponding type.
virtual void OnChildNodesUpdated()
Method called whenever ChildNodes is updated.
virtual void IndexElement(StateMachine Machine)
Indexes the element in the state-machine.
T GetChildElement< T >()
Gets a child items of a specific type.
T GetValueElement< T >()
Gets a value element from the list of child elements.
StateMachineNode()
Abstract base class for State-Machine nodes.
T[] GetChildElements< T >()
Gets an array of child items of a specific type.
void ConvertValueAttributesToElements(XmlElement Xml, Type[] ValueTypes, bool[] Required)
Converts value attributes to parsed elements. The XML definition has to be parsed before,...
Abstract base class for nodes with a value.
Class representing a state machine.
const string StateMachineNamespace
https://paiwise.tagroot.io/Schema/StateMachines.xsd
Interface for State-Machine nodes
bool ForEach(ForEachCallback Callback, object State)
Iterates through th node and all its child nodes.
TypeNameSerialization
How the type name should be serialized.
delegate bool ForEachCallback(IStateMachineNode Node, object State)
Delegate or callback methods when iterating through nodes in a state-machine.