Пример #1
0
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                var  orchestrationContext = (DurableOrchestrationContext)value;
                Type destinationType      = this.parameterInfo.ParameterType;

                object convertedValue = null;

                if (destinationType == typeof(DurableOrchestrationContext))
                {
                    convertedValue = orchestrationContext;
                }
                else if (destinationType == typeof(string))
                {
                    convertedValue = OrchestrationContextToString(orchestrationContext);
                }

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

                var bindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

                bindingData[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(inputValueProvider, bindingData);

                return(Task.FromResult <ITriggerData>(triggerData));
            }
Пример #2
0
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                var  entityContext   = (DurableEntityContext)value;
                Type destinationType = this.parameterInfo.ParameterType;

                object convertedValue = null;

                if (destinationType == typeof(IDurableEntityContext))
                {
                    convertedValue = entityContext;
#if !FUNCTIONS_V1
                    ((IDurableEntityContext)value).FunctionBindingContext = context.FunctionContext;
#endif
                }
                else if (destinationType == typeof(string))
                {
                    convertedValue = EntityContextToString(entityContext);
                }

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

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

                var triggerData = new TriggerData(inputValueProvider, bindingData);
                return(Task.FromResult <ITriggerData>(triggerData));
            }
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                IConverterManager cm = this.parent.extensionContext.Config.ConverterManager;
                MethodInfo        getConverterMethod = cm.GetType().GetMethod(nameof(cm.GetConverter));

                getConverterMethod = getConverterMethod.MakeGenericMethod(
                    typeof(DurableActivityContext),
                    this.parameterInfo.ParameterType,
                    typeof(ActivityTriggerAttribute));

                Delegate d = (Delegate)getConverterMethod.Invoke(cm, null);
                object   convertedValue = d.DynamicInvoke(value, this.attribute, context);

                var valueProvider = new ObjectValueProvider(
                    convertedValue,
                    this.parameterInfo.ParameterType);

                DurableActivityContext activityContext = (DurableActivityContext)value;
                var bindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)
                {
                    { nameof(DurableActivityContext.InstanceId), activityContext.InstanceId }
                };

                var triggerData = new TriggerData(valueProvider, bindingData);

                return(Task.FromResult <ITriggerData>(triggerData));
            }
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                var  activityContext = (DurableActivityContext)value;
                Type destinationType = this.parameterInfo.ParameterType;

                object convertedValue;

                if (destinationType == typeof(object))
                {
                    // Straight assignment
                    convertedValue = value;
                }
                else
                {
                    // Try using the converter manager
                    IConverterManager cm = this.parent.extensionContext.Config.ConverterManager;
                    MethodInfo        getConverterMethod = cm.GetType().GetMethod(nameof(cm.GetConverter));
                    getConverterMethod = getConverterMethod.MakeGenericMethod(
                        typeof(DurableActivityContext),
                        destinationType,
                        typeof(ActivityTriggerAttribute));

                    Delegate d = (Delegate)getConverterMethod.Invoke(cm, null);
                    if (d != null)
                    {
                        convertedValue = d.DynamicInvoke(value, this.attribute, context);
                    }
                    else if (!destinationType.IsInterface)
                    {
                        MethodInfo getInputMethod = activityContext.GetType()
                                                    .GetMethod(nameof(activityContext.GetInput))
                                                    .MakeGenericMethod(destinationType);
                        convertedValue = getInputMethod.Invoke(activityContext, null);
                    }
                    else
                    {
                        throw new ArgumentException(
                                  $"Activity triggers cannot be bound to {destinationType}.",
                                  this.parameterInfo.Name);
                    }
                }

                var inputValueProvider = new ObjectValueProvider(
                    convertedValue,
                    this.parameterInfo.ParameterType);

                var bindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)
                {
                    { nameof(DurableActivityContext.InstanceId), activityContext.InstanceId },
                };

                var triggerData = new TriggerData(inputValueProvider, bindingData);

                triggerData.ReturnValueProvider = new ActivityTriggerReturnValueBinder(
                    activityContext,
                    this.parameterInfo.ParameterType);

                return(Task.FromResult <ITriggerData>(triggerData));
            }
Пример #5
0
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                // If we are not directly passed a DurableActivityContext, we can assume we are being called directly
                // by the admin API. This is mainly used for the Azure Portal execution scenario.
                if (!(value is DurableActivityContext activityContext))
                {
                    if (!(value is string serializedInput))
                    {
                        throw new InvalidOperationException($"Cannot execute an Activity Trigger without a {nameof(DurableActivityContext)} or a {nameof(String)} that represents the serialized input.");
                    }

                    // Durable functions expects input as a JArray with one element.
                    serializedInput = $"[{serializedInput}]";

                    activityContext = new DurableActivityContext(this.durableTaskConfig, Guid.NewGuid().ToString(), serializedInput);
                }

                Type destinationType = this.parameterInfo.ParameterType;

                object convertedValue;

                if (destinationType == typeof(object))
                {
                    convertedValue = value;
                }
                else if (destinationType == typeof(IDurableActivityContext))
                {
                    convertedValue = activityContext;
                }
                else if (destinationType == typeof(JObject))
                {
                    convertedValue = ActivityContextToJObject(activityContext);
                }
                else
                {
                    convertedValue = activityContext.GetInput(destinationType);
                }

                var inputValueProvider = new ObjectValueProvider(
                    convertedValue,
                    this.parameterInfo.ParameterType);

                // Note that there could be conflicts in thiese dictionary keys, in which case
                // the order here determines which binding rule will win.
                var bindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

                bindingData[InstanceIdBindingPropertyName] = ((IDurableActivityContext)activityContext).InstanceId;
                bindingData[this.parameterInfo.Name]       = convertedValue;
                bindingData[DataBindingPropertyName]       = activityContext.GetInputAsJson();

                var triggerData = new TriggerData(inputValueProvider, bindingData);

                triggerData.ReturnValueProvider = new ActivityTriggerReturnValueBinder(
                    activityContext,
                    this.parameterInfo.ParameterType);

                return(Task.FromResult <ITriggerData>(triggerData));
            }
Пример #6
0
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                // No conversions
                var inputValueProvider = new ObjectValueProvider(value, this.TriggerValueType);

                // 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(inputValueProvider, bindingData: null);

                return(Task.FromResult <ITriggerData>(triggerData));
            }
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                var  activityContext = (DurableActivityContext)value;
                Type destinationType = this.parameterInfo.ParameterType;

                object convertedValue;

                if (destinationType == typeof(object))
                {
                    convertedValue = value;
                }
                else if (destinationType == typeof(DurableActivityContext) ||
                         destinationType == typeof(DurableActivityContextBase))
                {
                    convertedValue = activityContext;
                }
                else if (destinationType == typeof(JObject))
                {
                    convertedValue = ActivityContextToJObject(activityContext);
                }
                else
                {
                    convertedValue = activityContext.GetInput(destinationType);
                }

                var inputValueProvider = new ObjectValueProvider(
                    convertedValue,
                    this.parameterInfo.ParameterType);

                // Note that there could be conflicts in thiese dictionary keys, in which case
                // the order here determines which binding rule will win.
                var bindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

                bindingData[InstanceIdBindingPropertyName] = activityContext.InstanceId;
                bindingData[this.parameterInfo.Name]       = convertedValue;
                bindingData[DataBindingPropertyName]       = activityContext.GetInputAsJson();

                var triggerData = new TriggerData(inputValueProvider, bindingData);

                triggerData.ReturnValueProvider = new ActivityTriggerReturnValueBinder(
                    activityContext,
                    this.parameterInfo.ParameterType);

                return(Task.FromResult <ITriggerData>(triggerData));
            }
Пример #8
0
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                var  activityContext = (DurableActivityContext)value;
                Type destinationType = this.parameterInfo.ParameterType;

                object convertedValue;

                if (destinationType == typeof(object))
                {
                    // Straight assignment
                    convertedValue = value;
                }
                else
                {
                    // Try using the converter manager
#pragma warning disable CS0618 // Type or member is obsolete
                    IConverterManager cm = this.parent.extensionContext.Config.ConverterManager;
#pragma warning restore CS0618 // Type or member is obsolete
                    MethodInfo getConverterMethod = cm.GetType().GetMethod(nameof(cm.GetConverter));
                    getConverterMethod = getConverterMethod.MakeGenericMethod(
                        typeof(DurableActivityContext),
                        destinationType,
                        typeof(ActivityTriggerAttribute));

                    Delegate d = (Delegate)getConverterMethod.Invoke(cm, null);
                    if (d != null)
                    {
                        convertedValue = d.DynamicInvoke(value, this.attribute, context);
                    }
                    else if (!destinationType.IsInterface)
                    {
                        MethodInfo getInputMethod = activityContext.GetType()
                                                    .GetMethod(nameof(activityContext.GetInput))
                                                    .MakeGenericMethod(destinationType);
                        convertedValue = getInputMethod.Invoke(activityContext, null);
                    }
                    else
                    {
                        throw new ArgumentException(
                                  $"Activity triggers cannot be bound to {destinationType}.",
                                  this.parameterInfo.Name);
                    }
                }

                var inputValueProvider = new ObjectValueProvider(
                    convertedValue,
                    this.parameterInfo.ParameterType);

                // Note that there could be conflicts in thiese dictionary keys, in which case
                // the order here determines which binding rule will win.
                var bindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
                bindingData[InstanceIdBindingPropertyName] = activityContext.InstanceId;
                bindingData[this.parameterInfo.Name]       = convertedValue;
                bindingData[DataBindingPropertyName]       = activityContext.GetInputAsJson();

                var triggerData = new TriggerData(inputValueProvider, bindingData);
                triggerData.ReturnValueProvider = new ActivityTriggerReturnValueBinder(
                    activityContext,
                    this.parameterInfo.ParameterType);

                return(Task.FromResult <ITriggerData>(triggerData));
            }