Ejemplo n.º 1
0
        protected Task <TResult> DurablyInvoke <TResult>(DurableAttribute durableAttribute, IInvocation invocation)
        {
            if (!invocation.Method.ReturnType.IsAssignableTo <Task>())
            {
                throw new DurableInvocationException(
                          $"Method {invocation.Method} has a return type of {invocation.Method.ReturnType} but its application of {durableAttribute.GetType().Name} requries its return type be of type {typeof(Task)}."
                          );
            }

            var baseUrl             = Context.Value.FunctionContext?.BaseUrl;
            var functionName        = durableAttribute.GetFunctionName();
            var methodSpecificaiton = this.typeSerivce.Value.GetMethodSpecification(invocation.Method);
            var instanceId          = durableAttribute.IsSingleInstance ? durableAttribute.InstanceId ?? methodSpecificaiton : null;
            var methodArguments     = invocation.Method.GetParameters().Zip(invocation.Arguments, (a, b) => (a.Name, Value: b)).ToDictionary();

            var durableContext = new DurableContext {
                OrchestrationContext = Context.Value.OrchestrationContext,
                OrchestrationClient  = Context.Value.OrchestrationClient,
                FunctionContext      = new FunctionContext {
                    BaseUrl             = baseUrl,
                    FunctionName        = functionName,
                    InstanceId          = instanceId,
                    MethodSpecification = methodSpecificaiton,
                    Instance            = invocation.InvocationTarget,
                    Arguments           = methodArguments
                }
            };

            return(Context.Value?.FunctionContext?.MethodSpecification == methodSpecificaiton ||
                   durableAttribute.ExternalOrchestratorUrlOrAppSetting.IsNullOrWhiteSpace() ?
                   this.DurablyInvokeInternally <TResult>(durableAttribute, durableContext) :
                   this.DurablyInvokeExternally <TResult>(durableAttribute, durableContext));
        }
Ejemplo n.º 2
0
 public override async Task <TResult> Invoke <TResult>(DurableContext context)
 {
     return(await context.OrchestrationContext.CallActivityAsync <TResult>(
                context.FunctionContext.FunctionName,
                context.FunctionContext
                ));
 }
Ejemplo n.º 3
0
 public override async Task <TResult> Invoke <TResult>(DurableContext context)
 {
     return(await context.OrchestrationContext.CallSubOrchestratorAsync <TResult>(
                context.FunctionContext.FunctionName,
                context.FunctionContext.InstanceId,
                context.FunctionContext
                ));
 }
Ejemplo n.º 4
0
 public override async Task <TResult> Invoke <TResult>(DurableContext context)
 {
     return(await context.OrchestrationContext.CallEntityAsync <TResult>(
                new EntityId(
                    context.FunctionContext.FunctionName,
                    context.FunctionContext.InstanceId
                    ),
                null,
                context.FunctionContext
                ));
 }
        public override Task <TResult> Invoke <TResult>(DurableContext context)
        {
            if (context.OrchestrationContext != null)
            {
                context.OrchestrationContext.StartNewOrchestration(
                    context.FunctionContext.FunctionName,
                    context.FunctionContext,
                    context.FunctionContext.InstanceId
                    );
            }
            else
            {
                context.OrchestrationClient.StartNewAsync(
                    "orchestration",
                    context.FunctionContext.InstanceId,
                    context.FunctionContext
                    );
            }

            return(Task.FromResult(default(TResult)));
        }
Ejemplo n.º 6
0
 public abstract Task <TResult> Invoke <TResult>(DurableContext context);
Ejemplo n.º 7
0
        protected async Task <TResult> DurablyInvokeExternally <TResult>(DurableAttribute durableAttribute, DurableContext durableContext)
        {
            const string eventName = "external-durable-invocation-complete";

            durableContext.FunctionContext.CallbackUrl = durableContext.OrchestrationClient.CreateHttpManagementPayload(durableContext.OrchestrationContext.InstanceId).SendEventPostUri.Replace("{eventName}", eventName);
            var url = this.configuration.GetValue <string>(durableAttribute.ExternalOrchestratorUrlOrAppSetting) ?? durableAttribute.ExternalOrchestratorUrlOrAppSetting;

            await durableContext.OrchestrationContext.CallHttpAsync(
                HttpMethod.Post,
                new Uri(url),
                durableContext.FunctionContext.ToJson()
                );

            return(await durableContext.OrchestrationContext.WaitForExternalEvent <TResult>(eventName));
        }
Ejemplo n.º 8
0
 protected async Task <TResult> DurablyInvokeInternally <TResult>(DurableAttribute durableAttribute, DurableContext durableContext)
 {
     return(await durableAttribute.Invoke <TResult>(durableContext));
 }