コード例 #1
0
            private static bool HandleEndOperation(IAsyncResult result)
            {
                ControlOperationInvoker.ControlOperationAsyncResult asyncState = (ControlOperationInvoker.ControlOperationAsyncResult)result.AsyncState;
                if (asyncState.invoker.isControlOperation)
                {
                    switch (asyncState.invoker.operationName)
                    {
                    case "Suspend":
                    case "TransactedSuspend":
                        asyncState.workflowServiceInstance.EndSuspend(result);
                        goto Label_01E6;

                    case "Unsuspend":
                    case "TransactedUnsuspend":
                        asyncState.workflowServiceInstance.EndUnsuspend(result);
                        goto Label_01E6;

                    case "Terminate":
                    case "TransactedTerminate":
                        asyncState.workflowServiceInstance.EndTerminate(result);
                        goto Label_01E6;

                    case "Run":
                    case "TransactedRun":
                        asyncState.workflowServiceInstance.EndRun(result);
                        goto Label_01E6;

                    case "Cancel":
                    case "TransactedCancel":
                        asyncState.workflowServiceInstance.EndCancel(result);
                        goto Label_01E6;

                    case "Abandon":
                        asyncState.workflowServiceInstance.EndAbandon(result);
                        goto Label_01E6;
                    }
                    throw Fx.AssertAndThrow("Unreachable code");
                }
                if (asyncState.getInstanceContext.WorkflowCreationContext != null)
                {
                    asyncState.returnValue = asyncState.EndRunAndGetResponse(result, out asyncState.outputs);
                }
                else
                {
                    try
                    {
                        asyncState.returnValue = asyncState.invoker.OnEndServiceOperation(asyncState.workflowServiceInstance, out asyncState.outputs, result);
                    }
                    catch (FaultException)
                    {
                        throw;
                    }
                    catch (Exception exception)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        if (!asyncState.ShouldAbandonReceiveContext())
                        {
                            throw;
                        }
                        return(asyncState.AbandonReceiveContext(exception));
                    }
                }
Label_01E6:
                return(true);
            }
コード例 #2
0
            private static bool HandleEndGetInstance(IAsyncResult result)
            {
                ControlOperationInvoker.ControlOperationAsyncResult asyncState = (ControlOperationInvoker.ControlOperationAsyncResult)result.AsyncState;
                bool shouldAbandon = true;

                try
                {
                    try
                    {
                        asyncState.workflowServiceInstance = asyncState.invoker.instanceManager.EndGetInstance(result);
                        shouldAbandon = false;
                    }
                    catch (InstanceLockedException exception)
                    {
                        RedirectionException exception2;
                        if (asyncState.TryCreateRedirectionException(exception, out exception2))
                        {
                            throw System.ServiceModel.Activities.FxTrace.Exception.AsError(exception2);
                        }
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(CreateFaultException(exception));
                    }
                    catch (OperationCanceledException exception3)
                    {
                        asyncState.BufferReceiveHelper(ref shouldAbandon, true);
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new RetryException(null, exception3));
                    }
                    catch (InstancePersistenceException exception4)
                    {
                        asyncState.BufferReceiveHelper(ref shouldAbandon, false);
                        if (exception4 is InstanceKeyNotReadyException)
                        {
                            asyncState.invoker.host.RaiseUnknownMessageReceived(asyncState.operationContext.IncomingMessage);
                        }
                        asyncState.invoker.host.FaultServiceHostIfNecessary(exception4);
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(CreateFaultException(exception4));
                    }
                }
                catch (Exception exception5)
                {
                    if (Fx.IsFatal(exception5))
                    {
                        throw;
                    }
                    if (!shouldAbandon || !asyncState.ShouldAbandonReceiveContext())
                    {
                        throw;
                    }
                    return(asyncState.AbandonReceiveContext(exception5));
                }
                if (!asyncState.instanceKey.IsValid && (asyncState.instanceId == Guid.Empty))
                {
                    ContextMessageProperty contextMessageProperty = null;
                    if (!ContextMessageProperty.TryGet(asyncState.operationContext.OutgoingMessageProperties, out contextMessageProperty))
                    {
                        contextMessageProperty = new ContextMessageProperty();
                        contextMessageProperty.Context.Add("instanceId", Guid.NewGuid().ToString());
                        contextMessageProperty.AddOrReplaceInMessageProperties(asyncState.operationContext.OutgoingMessageProperties);
                    }
                    else
                    {
                        contextMessageProperty.Context["instanceId"] = Guid.NewGuid().ToString();
                    }
                }
                return(asyncState.PerformOperation());
            }