protected override void PostExecute(NativeActivityContext context, UnhandledExceptionAction unhandledExceptionAction) { Exception propagatedException = PropagatedException.Get(context); ReceiveRequestSendResponseScopeExecutionProperty executionProperty = context.GetReceiveRequestSendResponseScopeExecutionProperty(); // Due to this activity will handle the fault, the Finally activity in the TryCatch will be executed also, // we have to prevent canceling the operation and the stored previous response in the extension. executionProperty.Faulted = true; switch (unhandledExceptionAction) { default: case UnhandledExceptionAction.Abort: // This will implicitly also call OnUnhandledException. context.Abort(propagatedException); break; case UnhandledExceptionAction.Cancel: // Don't wait for completion, that is critical only for the persistence to happen before the taskCompletionSource of the request is completed. context.ScheduleActivity(cancelWorkflow); break; case UnhandledExceptionAction.Terminate: // Don't wait for completion, that is critical only for the persistence to happen before the taskCompletionSource of the request is completed. context.ScheduleAction(terminateWorkflow, propagatedException); break; } }
protected override void Execute(NativeActivityContext context) { ReceiveRequestSendResponseScopeExecutionProperty executionProperty = context.GetReceiveRequestSendResponseScopeExecutionProperty(); if (!executionProperty.Faulted && !executionProperty.IsInitializedAndCompleted) { // The taskCompletionSource from an incoming request is not completed (we don't have it or we have but not completed). if (!executionProperty.IsInitializedButNotCompleted) { // We don't have taskCompletionSource from an incoming request. if (executionProperty.Idempotent && context.GetPreviousResponseParameterExtension().TrySetResponseCanceled(executionProperty.OperationName)) { context.ScheduleActivity(persist); } } else { // We have taskCompletionSource from an incoming request, after setting the response in the extension we cancel the taskCompletionSource also. if (executionProperty.Idempotent && context.GetPreviousResponseParameterExtension().TrySetResponseCanceled(executionProperty.OperationName)) { context.ScheduleActivity(persist, PersistCompletionCallback); } else { executionProperty.TrySetTaskCompletionSourceCanceled(); } } } }
private void PersistCompletionCallback(NativeActivityContext context, ActivityInstance completedInstance) { if (completedInstance.State == ActivityInstanceState.Closed) { SetTaskCompletionSourceResult(context.GetReceiveRequestSendResponseScopeExecutionProperty <object>(), context); } }
private void BodyCompletionCallback(NativeActivityContext context, ActivityInstance completedInstance) { if (completedInstance.State == ActivityInstanceState.Canceled) { context.GetReceiveRequestSendResponseScopeExecutionProperty().TrySetTaskCompletionSourceCanceled(); } }
private void BookmarkResumptionCallback(NativeActivityContext context, Bookmark bookmark, object value) { ReceiveRequestExtensions.GetOperationParameters(value, out var taskCompletionSource, out Func <Task> requestResultTaskFunc); // Initializes the execution property held by the scope. SendResponse or the scope will use it (the scope for propagating any exception). context.GetReceiveRequestSendResponseScopeExecutionProperty().Initialize(taskCompletionSource); // Schedules the receiving delegate. context.ScheduleAction(this.requestResultEvaluator, requestResultTaskFunc, this.EvaluatorCompletionCallback); }
// We must persist before sending the response if we are idempotent, but this will cause double persist if the workflow goes idle after the response is sent. // TODO: can we do anything against this??? protected override void Execute(NativeActivityContext context) { var executionProperty = context.GetReceiveRequestSendResponseScopeExecutionProperty <object>(); executionProperty.AssertIsInitialized(); if (this.Idempotent) { context.GetPreviousResponseParameterExtension().SetResponseParameter( executionProperty.OperationName, typeof(void), null); context.ScheduleActivity(this.persist, this.PersistCompletionCallback); } else { SetTaskCompletionSourceResult(executionProperty, context); } }
protected override void Execute(NativeActivityContext context) { context.GetReceiveRequestSendResponseScopeExecutionProperty().Initialize(this.OperationName); context.CreateBookmark(this.OperationName, this.BookmarkResumptionCallback); }
private void PersistCompletionCallback(NativeActivityContext context, ActivityInstance completedInstance) => context.GetReceiveRequestSendResponseScopeExecutionProperty().TrySetTaskCompletionSourceCanceled();
private void BodyCompletionCallback(NativeActivityContext context, ActivityInstance completedInstance) { if (completedInstance.State == ActivityInstanceState.Canceled) context.GetReceiveRequestSendResponseScopeExecutionProperty().TrySetTaskCompletionSourceCanceled(); }