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)); }
public override async Task <TResult> Invoke <TResult>(DurableContext context) { return(await context.OrchestrationContext.CallActivityAsync <TResult>( context.FunctionContext.FunctionName, context.FunctionContext )); }
public override async Task <TResult> Invoke <TResult>(DurableContext context) { return(await context.OrchestrationContext.CallSubOrchestratorAsync <TResult>( context.FunctionContext.FunctionName, context.FunctionContext.InstanceId, context.FunctionContext )); }
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))); }
public abstract Task <TResult> Invoke <TResult>(DurableContext context);
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)); }
protected async Task <TResult> DurablyInvokeInternally <TResult>(DurableAttribute durableAttribute, DurableContext durableContext) { return(await durableAttribute.Invoke <TResult>(durableContext)); }