mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
173 lines
5.3 KiB
C#
173 lines
5.3 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.ObjectModel;
|
|
using Microsoft.Agents.ObjectModel;
|
|
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 ConditionGroupTemplate : 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/// <summary>\n/// Conditional branching similar to an if / elseif / elseif / els" +
|
|
"e chain.\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 " +
|
|
" {");
|
|
|
|
for (int index = 0; index < this.Model.Conditions.Length; ++index)
|
|
{
|
|
ConditionItem conditionItem = this.Model.Conditions[index];
|
|
if (conditionItem.Condition is null)
|
|
{
|
|
continue; // Skip if no condition is defined
|
|
}
|
|
|
|
EvaluateBoolExpression(conditionItem.Condition, $"condition{index}");
|
|
this.Write("\n if (condition");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(index));
|
|
this.Write(")\n {\n return \"");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(ConditionGroupExecutor.Steps.Item(this.Model, conditionItem)));
|
|
this.Write("\";\n }\n ");
|
|
|
|
}
|
|
|
|
this.Write("\n return \"");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(ConditionGroupExecutor.Steps.Else(this.Model)));
|
|
this.Write("\";\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);");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|