3using System.Threading.Tasks;
24 private Name variableName;
64 public string Name {
get;
set; }
84 public override async Task
Parse(XmlElement Xml)
89 await base.Parse(Xml);
91 if (
string.IsNullOrEmpty(this.
Name))
92 this.ConvertValueAttributeToElement<Name>(Xml,
true);
94 this.ConvertValueAttributeToElement<HeaderValue>(Xml,
true);
95 this.ConvertValueAttributeToElement<OnlyIfChanged>(Xml,
false);
103 base.OnChildNodesUpdated();
105 if (
string.IsNullOrEmpty(this.
Name))
106 this.variableName = this.GetValueElement<Name>();
108 this.value = this.GetValueElement<HeaderValue>();
109 this.onlyIfChanged = this.GetValueElement<OnlyIfChanged>();
119 if (this.suppressSample?.IsEmpty ??
true)
136 if (this.onlyIfChanged is
null)
138 else if (await this.onlyIfChanged.
Evaluate(Arguments) is
bool b)
147 if (
string.IsNullOrEmpty(
Name))
149 if (this.variableName is
null)
153 if (
string.IsNullOrEmpty(
Name))
161 !((
Value is
null) ^ (Current?.ValueObject is
null)) &&
162 (
Value?.Equals(Current?.ValueObject) ??
true))
174 Timestamp = DateTime.UtcNow,
179 ArchiveRequired = Arguments.Machine.ArchiveRequired
184 if (IsSample(
Value, out
double Sample))
188 if (IsSample(Current?.ValueObject, out
double Prev))
216 Type T =
Value?.GetType() ?? typeof(
object);
224 if (Label.Length > 10)
227 Label =
"Note" + NoteIndex.ToString();
230 else if (
Value is
string s)
235 Label =
"Note" + NoteIndex.ToString();
238 Label = s.Replace(
'"',
'\'');
242 StringBuilder sb =
new StringBuilder();
244 sb.AppendLine(
"@startjson");
246 sb.Append(
"@endjson");
249 Label =
"Note" + NoteIndex.ToString();
259 private static bool IsSample(
object Value, out
double Sample)
266 else if (
Value is
double d)
271 else if (
Value is decimal dec)
273 Sample = (double)dec;
276 else if (
Value is
float fl)
281 else if (
Value is sbyte i8)
286 else if (
Value is
short i16)
291 else if (
Value is
int i32)
296 else if (
Value is
long i64)
301 else if (
Value is
byte ui8)
306 else if (
Value is ushort ui16)
311 else if (
Value is uint ui32)
316 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 ToExpressionString(object Value)
Converts an object 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.
Exception related to state machine.
Abstract base class for State-Machine action nodes.
Defines an expiry timestamp.
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.
async Task< bool > GetSuppressSample(EvaluationArguments Arguments)
Gets a Boolean value indicating if samples should be suppressed for the event.
string SuppressSampleDefinition
Suppress Sample Definition
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.
async Task< T > Evaluate(Variables Variables)
Evaluates the attribute
string Definition
Attribute definition
Scriptable Boolean attribute.
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.