mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
906 lines
22 KiB
C#
906 lines
22 KiB
C#
// ------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This code was generated by a tool.
|
|
// Runtime Version: 18.0.0.0
|
|
//
|
|
// Changes to this file may cause incorrect behavior and will be lost if
|
|
// the code is regenerated.
|
|
// </auto-generated>
|
|
// ------------------------------------------------------------------------------
|
|
namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen
|
|
{
|
|
using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.ObjectModel;
|
|
using Microsoft.Bot.ObjectModel;
|
|
using Microsoft.Extensions.AI;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
|
|
/// <summary>
|
|
/// Class to produce the template output
|
|
/// </summary>
|
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")]
|
|
internal partial class QuestionTemplate : ActionTemplate
|
|
{
|
|
/// <summary>
|
|
/// Create the template output
|
|
/// </summary>
|
|
public override string TransformText()
|
|
{
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n/// <summary>\n/// Request input.\n/// </summary>\ninternal sealed class ");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(this.Name));
|
|
this.Write("Executor(FormulaSession session) : ActionExecutor(id: \"");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(this.Id));
|
|
this.Write("\", session)\n{\n // <inheritdoc />\n protected override async ValueTask<object" +
|
|
"?> ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " +
|
|
" {\n return default;\n }\n}");
|
|
return this.GenerationEnvironment.ToString();
|
|
}
|
|
|
|
void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false)
|
|
{
|
|
if (targetVariable is not null)
|
|
{
|
|
this.Write("\n await context.QueueStateUpdateAsync(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable)));
|
|
|
|
this.Write("\", value: ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable));
|
|
|
|
this.Write(", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable)));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
if (!tightFormat)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateBoolExpression(BoolExpression expression, string targetVariable, bool defaultValue = false)
|
|
{
|
|
if (expression is null)
|
|
{
|
|
this.Write("\n bool ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatBoolValue(defaultValue)));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsLiteral)
|
|
{
|
|
this.Write("\n bool ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatBoolValue(expression.LiteralValue)));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2)
|
|
{
|
|
this.Write("\n bool ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.ReadStateAsync<bool>(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName));
|
|
|
|
this.Write("\", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference)
|
|
{
|
|
this.Write("\n bool ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<bool>>(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString())));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n bool ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<bool>(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText)));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateEnumExpression<TWrapper, TValue>(
|
|
EnumExpression<TWrapper> expression,
|
|
string targetVariable,
|
|
IDictionary<TWrapper, string> resultMap,
|
|
string defaultValue = null,
|
|
bool qualifyResult = false,
|
|
bool isNullable = false)
|
|
where TWrapper : EnumWrapper
|
|
{
|
|
string resultType = $"{GetTypeAlias<TValue>()}{(isNullable ? "?" : "")}";
|
|
if (expression is null)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatValue<TValue>(defaultValue)));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsLiteral)
|
|
{
|
|
resultMap.TryGetValue(expression.LiteralValue, out string resultValue);
|
|
if (qualifyResult)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write(".");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultValue));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatValue<TValue>(resultValue)));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
}
|
|
else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.ReadStateAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write(">(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName));
|
|
|
|
this.Write("\", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write("? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString())));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultType));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText)));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateIntExpression(IntExpression expression, string targetVariable, bool isNullable = false)
|
|
{
|
|
string typeName = isNullable ? "int?" : "int";
|
|
if (expression is null)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(isNullable ? "null" : "0"));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsLiteral)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.LiteralValue));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.ReadStateAsync<int>(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName));
|
|
|
|
this.Write("\", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write("? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString())));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText)));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateListExpression<TElement>(ValueExpression expression, string targetVariable)
|
|
{
|
|
string typeName = GetTypeAlias<TElement>();
|
|
if (expression is null)
|
|
{
|
|
this.Write("\n IList<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = null;");
|
|
|
|
|
|
}
|
|
else if (expression.IsLiteral)
|
|
{
|
|
this.Write("\n IList<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue)));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2)
|
|
{
|
|
this.Write("\n IList<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.ReadListAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TElement>()));
|
|
|
|
this.Write(">(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName));
|
|
|
|
this.Write("\", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference)
|
|
{
|
|
this.Write("\n IList<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write("> = await context.EvaluateListAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString())));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n IList<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateListAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText)));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateRecordExpression<TValue>(ObjectExpression<RecordDataValue> expression, string targetVariable)
|
|
{
|
|
string resultTypeName = $"Dictionary<string, {GetTypeAlias<TValue>()}?>?";
|
|
if (expression is null)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = null;");
|
|
|
|
|
|
}
|
|
else if (expression.IsLiteral)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" =\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue)));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.ReadStateAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName));
|
|
|
|
this.Write(">(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName));
|
|
|
|
this.Write("\", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName));
|
|
|
|
this.Write("? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateExpressionAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString())));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateExpressionAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText)));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateStringExpression(StringExpression expression, string targetVariable, bool isNullable = false)
|
|
{
|
|
string typeName = isNullable ? "string?" : "string";
|
|
if (expression is null)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(isNullable ? "null" : "string.Empty"));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsLiteral)
|
|
{
|
|
if (expression.LiteralValue.Contains("\n"))
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = \n \"\"\"\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.LiteralValue));
|
|
|
|
this.Write("\n \"\"\";");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.LiteralValue)));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
}
|
|
else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.ReadStateAsync<string>(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName));
|
|
|
|
this.Write("\", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<string>(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString())));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(typeName));
|
|
|
|
this.Write(" ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<string>(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText)));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateValueExpression(ValueExpression expression, string targetVariable) =>
|
|
EvaluateValueExpression<object>(expression, targetVariable);
|
|
|
|
void EvaluateValueExpression<TValue>(ValueExpression expression, string targetVariable)
|
|
{
|
|
if (expression is null)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write("? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = null;");
|
|
|
|
|
|
}
|
|
else if (expression.IsLiteral)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write("? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue)));
|
|
|
|
this.Write(";");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write("? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.ReadStateAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write(">(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName));
|
|
|
|
this.Write("\", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else if (expression.IsVariableReference)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write("? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString())));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write("? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable));
|
|
|
|
this.Write(" = await context.EvaluateValueAsync<");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias<TValue>()));
|
|
|
|
this.Write(">(");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText)));
|
|
|
|
this.Write(").ConfigureAwait(false);");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateMessageTemplate(TemplateLine templateLine, string variableName)
|
|
{
|
|
if (templateLine is not null)
|
|
{
|
|
this.Write("\n string ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
|
|
|
|
this.Write(" =\n await context.FormatTemplateAsync(\n \"\"\"");
|
|
|
|
|
|
FormatMessageTemplate(templateLine);
|
|
this.Write("\n \"\"\");");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n string? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
|
|
|
|
this.Write(" = null;");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
void FormatMessageTemplate(TemplateLine line)
|
|
{
|
|
foreach (string text in line.ToTemplateString().ByLine())
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(text));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|