mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
100 lines
3.9 KiB
C#
100 lines
3.9 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.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 ParseValueTemplate : 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/// <summary>\n/// Parses a string or untyped value to the provided data type. Wh" +
|
|
"en the input is a string, it will be treated as JSON.\n/// </summary>\ninternal se" +
|
|
"aled 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 VariableType targetType = ");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(this.GetVariableType()));
|
|
this.Write(";");
|
|
|
|
if (this.Model.Value.IsVariableReference && this.Model.Value.VariableReference.SegmentCount == 2)
|
|
{
|
|
this.Write("\n object? parsedValue = await context.ConvertValueAsync(targetType, key: \"" +
|
|
"");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Value.VariableReference.VariableName));
|
|
this.Write("\", scopeName: \"");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Value.VariableReference.NamespaceAlias));
|
|
this.Write("\", cancellationToken).ConfigureAwait(false);");
|
|
|
|
}
|
|
else if (this.Model.Value.IsVariableReference)
|
|
{
|
|
this.Write("\n object? parsedValue = await context.ConvertValueAsync(targetType, ");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(this.Model.Value.VariableReference.ToString())));
|
|
this.Write(", cancellationToken).ConfigureAwait(false);");
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n object? parsedValue = await context.ConvertValueAsync(targetType, ");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(this.Model.Value.ExpressionText)));
|
|
this.Write(", cancellationToken).ConfigureAwait(false);");
|
|
|
|
}
|
|
AssignVariable(this.Variable, "parsedValue");
|
|
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 ");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|