3using System.Threading.Tasks;
58 get => this.childNodes;
61 this.childNodes = value;
84 public virtual async Task
Parse(XmlElement Xml)
86 List<IStateMachineNode> Children =
null;
88 foreach (XmlNode N
in Xml.ChildNodes)
90 if (N is XmlElement E)
92 Children ??=
new List<IStateMachineNode>();
97 this.ChildNodes = Children?.ToArray();
110 if (!(Result is
null))
148 return Array.Empty<T>();
150 List<T> Result =
null;
156 Result ??=
new List<T>();
161 return Result?.ToArray() ?? Array.Empty<T>();
175 where ValueType :
Value
192 Dictionary<Type, bool>
Types =
new Dictionary<Type, bool>();
193 int i, c = ValueTypes.Length;
195 if (c != Required.Length)
196 throw new ArgumentException(
"Array lengths must match.", nameof(Required));
198 for (i = 0; i < c; i++)
199 Types[ValueTypes[i]] = Required[i];
204 Types.Remove(Node.GetType());
207 List<IStateMachineNode> ToAdd =
null;
209 foreach (KeyValuePair<Type, bool> P
in Types)
211 Value Result = (
Value)Runtime.Inventory.Types.Instantiate(P.Key);
214 if (!
string.IsNullOrEmpty(s))
216 s = s[..1].ToLower() + s[1..];
217 if (Xml.HasAttribute(s))
219 Result.Node =
Value.ParseAttributeValue(Xml.GetAttribute(s));
221 ToAdd ??=
new List<IStateMachineNode>();
229 if (!(ToAdd is
null))
231 if (this.childNodes is
null)
232 this.childNodes = ToAdd.ToArray();
235 c = this.childNodes.Length;
238 Array.Resize(ref this.childNodes, i);
239 ToAdd.CopyTo(this.childNodes, c);
258 if (Node is T Element)
274 if (!Callback(
this, State))
281 if (!Node.
ForEach(Callback, State))
295 this.stateMachine = Machine;
Static class that dynamically manages types and interfaces available in the runtime environment.
Exception related to state 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.
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.
virtual async Task Parse(XmlElement Xml)
Parses the State-machine node.
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.