Table of Contents

Class Expressions

Namespace
DuetControlServer.Codes.Meta
Assembly
DuetControlServer.dll

Functionality for meta G-code expressions

public sealed class Expressions
Inheritance
Expressions
Inherited Members

Constructors

Functionality for meta G-code expressions

public Expressions(Filter filter, ObjectModel model, LinkInterface linkInterface)

Parameters

filter Filter

Object model filter

model ObjectModel

Object model

linkInterface LinkInterface

Link interface

Properties

CustomFunctions

Dictionary of custom meta G-code functions vs. async resolvers

public Dictionary<string, Expressions.CustomAsyncFunctionResolver> CustomFunctions { get; }

Property Value

Dictionary<string, Expressions.CustomAsyncFunctionResolver>

Methods

ContainsSbcFields(Code)

Checks if the given code contains any SBC object model fields

public bool ContainsSbcFields(Code code)

Parameters

code Code

Code 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

expression string

Expression 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

code Code

Code holding expressions

evaluateAll bool

Whether all or only SBC fields are supposed to be evaluated

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<string>

Evaluation result or null

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

code Code

Code holding the expression(s)

expression string

Expression(s) to replace

onlySbcFields bool

Whether to replace only SBC fields

encodeResult bool

Whether the final result shall be encoded

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<string>

Replaced expression(s)

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

code Code

Code holding the expression(s)

expression string

Expression(s) to replace

onlySbcFields bool

Whether to replace only SBC fields

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<object>

Replaced expression(s)

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

expression string

Expression 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

expression string

Expression without indices to check

isFunction bool

Expression 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