Class Expressions
- Namespace
- DuetControlServer.Codes.Meta
- Assembly
- DuetControlServer.dll
Functionality for meta G-code expressions
public sealed class Expressions
- Inheritance
-
Expressions
- Inherited Members
Constructors
Expressions(Filter, ObjectModel, LinkInterface)
Functionality for meta G-code expressions
public Expressions(Filter filter, ObjectModel model, LinkInterface linkInterface)
Parameters
filterFilterObject model filter
modelObjectModelObject model
linkInterfaceLinkInterfaceLink interface
Properties
CustomFunctions
Dictionary of custom meta G-code functions vs. async resolvers
public Dictionary<string, Expressions.CustomAsyncFunctionResolver> CustomFunctions { get; }
Property Value
Methods
ContainsSbcFields(Code)
Checks if the given code contains any SBC object model fields
public bool ContainsSbcFields(Code code)
Parameters
codeCodeCode to check
Returns
- bool
Whether the code contains any SBC object model fields
Exceptions
- CodeParserException
Failed to parse expression
ContainsSbcFields(string)
Checks if the given expression string contains any SBC object model fields
public bool ContainsSbcFields(string expression)
Parameters
expressionstringExpression to check
Returns
- bool
Whether the expressions contains any SBC object model fields
Exceptions
- CodeParserException
Failed to parse expression
EvaluateAsync(Code, bool, CancellationToken)
Evaluate a conditional code
public Task<string?> EvaluateAsync(Code code, bool evaluateAll, CancellationToken cancellationToken = default)
Parameters
codeCodeCode holding expressions
evaluateAllboolWhether all or only SBC fields are supposed to be evaluated
cancellationTokenCancellationTokenOptional cancellation token
Returns
EvaluateExpressionAsync(Code, string, bool, bool, CancellationToken)
Evaluate expression(s)
public Task<string> EvaluateExpressionAsync(Code code, string expression, bool onlySbcFields, bool encodeResult, CancellationToken cancellationToken = default)
Parameters
codeCodeCode holding the expression(s)
expressionstringExpression(s) to replace
onlySbcFieldsboolWhether to replace only SBC fields
encodeResultboolWhether the final result shall be encoded
cancellationTokenCancellationTokenOptional cancellation token
Returns
Exceptions
- CodeParserException
Failed to parse expression(s)
- OperationCanceledException
Code was cancelled
EvaluateExpressionRaw(Code, string, bool, CancellationToken)
Evaluate expression(s) and return the raw evaluation result (if applicable)
public Task<object?> EvaluateExpressionRaw(Code code, string expression, bool onlySbcFields, CancellationToken cancellationToken = default)
Parameters
codeCodeCode holding the expression(s)
expressionstringExpression(s) to replace
onlySbcFieldsboolWhether to replace only SBC fields
cancellationTokenCancellationTokenOptional cancellation token
Returns
Exceptions
- CodeParserException
Failed to parse expression(s)
- OperationCanceledException
Code was cancelled
ExtractFieldPaths(string)
Extracts all object model field paths referenced in the given expression string. The returned paths use dot-notation (e.g. "heat.heaters", "state.status"). Both SBC and non-SBC OM fields are included so that any change to a referenced field triggers re-evaluation of the expression.
public IReadOnlySet<string> ExtractFieldPaths(string expression)
Parameters
expressionstringExpression to analyse
Returns
- IReadOnlySet<string>
Set of field paths referenced in the expression
IsSbcExpression(string, bool)
Checks if the given expression without indices is a SBC object model field
public bool IsSbcExpression(string expression, bool isFunction)
Parameters
expressionstringExpression without indices to check
isFunctionboolExpression is followed by an opening brace, check only if it is a custom function
Returns
- bool
Whether the given expression is a SBC object model field