3using System.Threading.Tasks;
22 private Name variableName;
52 public string Name {
get;
set; }
72 public override async Task
Parse(XmlElement Xml)
76 await base.Parse(Xml);
78 if (
string.IsNullOrEmpty(this.
Name))
79 this.ConvertValueAttributeToElement<Name>(Xml,
true);
81 this.ConvertValueAttributeToElement<HeaderValue>(Xml,
true);
82 this.ConvertValueAttributeToElement<OnlyIfChanged>(Xml,
false);
90 base.OnChildNodesUpdated();
92 if (
string.IsNullOrEmpty(this.
Name))
93 this.variableName = this.GetValueElement<Name>();
95 this.value = this.GetValueElement<HeaderValue>();
96 this.onlyIfChanged = this.GetValueElement<OnlyIfChanged>();
109 if (this.onlyIfChanged is
null)
111 else if (await this.onlyIfChanged.
Evaluate(Arguments) is
bool b)
114 throw new Exception(
"OnlyIfChanged must be a boolean value.");
118 if (
string.IsNullOrEmpty(
Name))
120 if (this.variableName is
null)
121 throw new Exception(
"Variable name not defined.");
124 if (
string.IsNullOrEmpty(
Name))
125 throw new Exception(
"Variable name not defined.");
130 !((
Value is
null) ^ (Current.ValueObject is
null)) &&
131 (
Value?.Equals(Current.ValueObject) ??
true))
141 Timestamp = DateTime.UtcNow,
146 ArchiveRequired = Arguments.Machine.ArchiveRequired
151 if (IsSample(
Value, out
double Sample))
170 Type T =
Value?.GetType() ?? typeof(
object);
178 if (Label.Length > 10)
181 Label =
"Note" + NoteIndex.ToString();
184 else if (
Value is
string s)
189 Label =
"Note" + NoteIndex.ToString();
192 Label = s.Replace(
'"',
'\'');
196 StringBuilder sb =
new StringBuilder();
198 sb.AppendLine(
"@startjson");
200 sb.Append(
"@endjson");
203 Label =
"Note" + NoteIndex.ToString();
212 private static bool IsSample(
object Value, out
double Sample)
219 else if (
Value is
double d)
224 else if (
Value is decimal dec)
226 Sample = (double)dec;
229 else if (
Value is
float fl)
234 else if (
Value is sbyte i8)
239 else if (
Value is
short i16)
244 else if (
Value is
int i32)
249 else if (
Value is
long i64)
254 else if (
Value is
byte ui8)
259 else if (
Value is ushort ui16)
264 else if (
Value is uint ui32)
269 else if (
Value is ulong ui64)
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
ProfilerThread GetThread(string Name, ProfilerThreadType Type)
Gets a profiler thread. If none is available, a new is created.
int AddNote(object Note)
Adds a note to the profile.
Class that keeps track of events and timing for one thread.
void NewSample(double Sample)
A new sample value has been recored
Profiler Profiler
Profiler reference.
void Idle()
Thread goes idle.
void NewState(string State)
Thread changes state.
Class managing a script expression.
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
PhysicalQuantity ToPhysicalQuantity()
Converts underlying object to a physical quantity.
double Magnitude
Magnitude
Contains information about a variable.
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Abstract base class for State-Machine action nodes.
Defines the name of a variable.
Limits an action to only cases where a value has changed.
Persists a variable in the state-machine.
override IStateMachineNode Create()
Creates a new node of the corresponding type.
override string LocalName
Local name
HeaderValue Value
New value.
PersistVariable()
Persists a variable in the state-machine.
Name VariableName
Variable name.
override void OnChildNodesUpdated()
Method called whenever ChildNodes is updated.
override async Task Execute(EvaluationArguments Arguments)
Evaluates the action node
override async Task Parse(XmlElement Xml)
Parses the State-machine node.
OnlyIfChanged OnlyIfChanged
Only persist values if they have changed.
Contains information required for evaluating script in a state-machine.
StateMachine Machine
Reference to state-machine definition.
void UpdateVariable(string Name, object Value)
Updates a variable.
Profiler Profiler
State-Machine profiler.
Variables Variables
Current set of variables.
Task< object > Evaluate(EvaluationArguments Arguments)
Evaluates the value node.
Variable definition in a State-Machine
CaseInsensitiveString StateMachineId
ID of State Machine.
Duration? ArchiveOptional
Duration after which token expires, and the required archiving time, the token can optionally be arch...
DateTime Expires
When state-machine expires
Class representing a sample of a state machine variable over time.
Interface for objects that can be represented as a physical quantity.
Interface for State-Machine nodes
delegate string ToString(IElement Element)
Delegate for callback methods that convert an element value to a string.
ProfilerThreadType
Type of profiler thread.