C# 持久功能:如何将参数传递给编排器?

C# 持久功能:如何将参数传递给编排器?,c#,azure-durable-functions,C#,Azure Durable Functions,我是Azure持久函数的新手,一直在遵循书中的示例代码,我被卡住了,因为我的Orchestrator中的.GetInput函数返回null。我的Blob触发器将文件名作为调用中的参数传递给我的Orchestrator。我认为它调用了错误的重载函数,但不确定如何调用正确的函数 await starter.StartNewAsync("CSVImport_Orchestrator", name); [FunctionName(“CSVImport_Orchestrator”)

我是Azure持久函数的新手,一直在遵循书中的示例代码,我被卡住了,因为我的Orchestrator中的.GetInput函数返回null。我的Blob触发器将文件名作为调用中的参数传递给我的Orchestrator。我认为它调用了错误的重载函数,但不确定如何调用正确的函数

await starter.StartNewAsync("CSVImport_Orchestrator", name); 
[FunctionName(“CSVImport_Orchestrator”)]
公共静态异步任务RunOrchestrator([OrchestrationTrigger]IDurableCorchestrationContext)
{
变量输出=新列表();
字符串CSVFileName=context.GetInput();//您正在调用where第二个,
string
参数表示实例ID,而不是输入参数。还有一个where第二个参数表示数据。您正在传递一个
string
,因此重载解析会看到两个潜在的候选。然后它会首选非泛型参数,因为它是精确的匹配,从而“丢失”数据

如果输入数据确实需要
字符串
,则需要显式指定泛型参数,以强制编译器选择正确的重载:

wait starter.StartAsync(“CSVImport_Orchestrator”,名称);
现在,文档还声明输入应该是JSON可序列化对象。从技术上讲,字符串是
字符串,但我不确定它如何与orchestrator的序列化程序配合使用。您可以传递一个包含数据的类。这样做的好处是可以正确推断泛型参数:

公共类数据{
公共字符串名称{get;set;}
} 
//召唤
wait starter.StartAsync(“CSVImport_Orchestrator”,新数据{Name=Name});
//使用
var csvFileName=context.GetInput()?.Name;

相反,我喜欢你的类想法。你能解释一下“公共记录数据(字符串名称)”吗?(它没有编译。)这是一个名为records的c#9特性。这一行声明了一个具有单个公共属性“Name”的类.但在我回复您时,我意识到azure函数无法在net5上运行,即使您使用最新的编译器,它也不支持新功能。我已将示例更新为使用完整的类。很抱歉,使用您的类想法奏效了!非常感谢!
        [FunctionName("CSVImport_Orchestrator")]
        public static async Task<List<string>> RunOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var outputs = new List<string>();
            string CSVFileName = context.GetInput<string>(); //<<== returns null???
            {
                List<Employee> employees = await context.CallActivityAsync<List<Employee>>("ReadCSV_AT", CSVFileName);
            }
            return outputs;
        }

        [FunctionName("CSVImportBlobTrigger")]
        public static async  void Run([BlobTrigger("import-obiee-report/{name}", Connection = "StorageConnection")]Stream myBlob, string name, [DurableClient]IDurableOrchestrationClient starter, ILogger log)
        {
            string instanceId = await starter.StartNewAsync("CSVImport_Orchestrator", name); 
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        }