public Task BindAsync()

in src/WebJobs.Extensions.DurableTask/Bindings/OrchestrationTriggerAttributeBindingProvider.cs [128:186]


            public Task<ITriggerData> BindAsync(object? value, ValueBindingContext context)
            {
                if (value is DurableOrchestrationContext orchestrationContext)
                {
                    Type destinationType = this.parameterInfo.ParameterType;

                    object? convertedValue = null;
                    if (destinationType == typeof(IDurableOrchestrationContext))
                    {
                        convertedValue = orchestrationContext;
                    }
                    else if (this.config.TypedCodeProvider.IsInitialized &&
                        destinationType.Name == TypedCodeProvider.ITypedDurableOrchestrationContext)
                    {
                        convertedValue = this.config.TypedCodeProvider.InstantiateTypedDurableOrchestrationContext(orchestrationContext);
                    }
                    else if (destinationType == typeof(string))
                    {
                        convertedValue = this.OrchestrationContextToString(orchestrationContext);
                    }

                    var contextValueProvider = new ObjectValueProvider(
                        convertedValue ?? value,
                        this.parameterInfo.ParameterType);

                    var bindingData = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
                    {
                        [this.parameterInfo.Name!] = convertedValue,
                    };

                    // We don't specify any return value binding because we process the return value
                    // earlier in the pipeline via the InvokeHandler extensibility.
                    var triggerData = new TriggerData(contextValueProvider, bindingData);
                    return Task.FromResult<ITriggerData>(triggerData);
                }
                else if (value is RemoteOrchestratorContext remoteContext)
                {
                    // Generate a byte array which is the serialized protobuf payload
                    // https://developers.google.com/protocol-buffers/docs/csharptutorial#parsing_and_serialization
                    var orchestratorRequest = new Microsoft.DurableTask.Protobuf.OrchestratorRequest()
                    {
                        InstanceId = remoteContext.InstanceId,
                        PastEvents = { remoteContext.PastEvents.Select(ProtobufUtils.ToHistoryEventProto) },
                        NewEvents = { remoteContext.NewEvents.Select(ProtobufUtils.ToHistoryEventProto) },
                        EntityParameters = remoteContext.EntityParameters.ToProtobuf(),
                    };

                    // We convert the binary payload into a base64 string because that seems to be the most commonly supported
                    // format for Azure Functions language workers. Attempts to send unencoded byte[] payloads were unsuccessful.
                    string encodedRequest = ProtobufUtils.Base64Encode(orchestratorRequest);
                    var contextValueProvider = new ObjectValueProvider(encodedRequest, typeof(string));
                    var triggerData = new TriggerData(contextValueProvider, EmptyBindingData);
                    return Task.FromResult<ITriggerData>(triggerData);
                }
                else
                {
                    throw new ArgumentException($"Don't know how to bind to {value?.GetType().Name ?? "null"}.", nameof(value));
                }
            }