public Result <Func <IFormattedValue, Task <ushort[]> > > GetFormatBackUshortsFunc( CodeFormatterExpression codeExpression, DeviceContext deviceContext, bool isLocal, IFormattedValueOwner formattedValueOwner) { try { if (_formatBackCache.TryGetValue(codeExpression.CodeStringFormatBack, out var cachedFunc)) { Task <ushort[]> FunFromCacheWithContext(IFormattedValue input) => cachedFunc(input, new RuleExecutionContext(deviceContext, isLocal).SetVariable(VariableNames.CURRENT_VALUE_OWNER, formattedValueOwner)); return(Result <Func <IFormattedValue, Task <ushort[]> > > .Create(FunFromCacheWithContext, true)); } var nodes = Evaluator.Initialize(codeExpression.CodeStringFormatBack, _lexemManager); Func <IFormattedValue, Task <ushort[]> > fun = (input) => Evaluator.ExecuteFormatBack(input, new RuleExecutionContext(deviceContext, isLocal).SetVariable(VariableNames.CURRENT_VALUE_OWNER, formattedValueOwner), nodes); _formatBackCache.TryAdd(codeExpression.CodeStringFormatBack, (input, context) => Evaluator.ExecuteFormatBack(input, context, nodes)); return(Result <Func <IFormattedValue, Task <ushort[]> > > .Create(fun, true)); } catch (Exception e) { return(Result <Func <IFormattedValue, Task <ushort[]> > > .CreateWithException(e)); } }
public BuiltExpressionFormatContext(DeviceContext deviceContext, ushort[] deviceValue, bool isLocal, IFormattedValueOwner formattedValueOwner) { DeviceContext = deviceContext; DeviceValue = deviceValue; IsLocal = isLocal; FormattedValueOwner = formattedValueOwner; }
public FormattingContext(IFormattedValueOwner valueOwner, DeviceContext deviceContext, bool isLocal) { ValueOwner = valueOwner; DeviceContext = deviceContext; IsLocal = isLocal; }