// ------------------------------------------------------------------------------ // // 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. // // ------------------------------------------------------------------------------ namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen { using Microsoft.Agents.ObjectModel; using System; /// /// Class to produce the template output /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] internal partial class SetMultipleVariablesTemplate : ActionTemplate { /// /// Create the template output /// public override string TransformText() { this.Write("\n"); this.Write("\n"); this.Write("\n"); this.Write("\n"); this.Write("\n"); this.Write("\n/// \n/// Assigns an evaluated expression, other variable, or literal va" + "lue to one or more variables.\n/// \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 // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + " {"); int index = 0; foreach (var assignment in this.Model.Assignments) { // Separate assigments with a blank line for readability if (index > 0) { this.Write("\n "); } ++index; EvaluateValueExpression(assignment.Value, $"evaluatedValue{index}"); AssignVariable(assignment.Variable, $"evaluatedValue{index}"); } this.Write("\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 EvaluateValueExpression(ValueExpression expression, string targetVariable) => EvaluateValueExpression(expression, targetVariable); void EvaluateValueExpression(ValueExpression expression, string targetVariable) { if (expression is null) { this.Write("\n "); this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); this.Write("? "); this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); this.Write(" = null;"); } else if (expression.IsLiteral) { this.Write("\n "); this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); 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())); this.Write("? "); this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); this.Write(" = await context.ReadStateAsync<"); this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); 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())); this.Write("? "); this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); this.Write(" = await context.EvaluateValueAsync<"); this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); 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())); this.Write("? "); this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); this.Write(" = await context.EvaluateValueAsync<"); this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); this.Write(">("); this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); this.Write(").ConfigureAwait(false);"); } } } }