Пример #1
0
        public static object EndProcessRequest(IAsyncResult result, out object[] outputs)
        {
            WorkflowOperationContext thisPtr = AsyncResult.End <WorkflowOperationContext>(result);

            outputs = thisPtr.outputs;
            return(thisPtr.operationReturnValue);
        }
Пример #2
0
        static void Finally(AsyncResult result, Exception completionException)
        {
            WorkflowOperationContext thisPtr = (WorkflowOperationContext)result;

            thisPtr.EmitTransferFromInstanceId();

            if (completionException != null)
            {
                if (completionException is FaultException)
                {
                    thisPtr.TrackMethodFaulted();
                }
                else
                {
                    thisPtr.TrackMethodFailed();
                }
            }
            else
            {
                thisPtr.TrackMethodCompleted(thisPtr.operationReturnValue);
            }
            thisPtr.ProcessFinalizationTraces();
            // will be a no-op if we were never added to the instance
            thisPtr.workflowInstance.ReleaseContext(thisPtr);
            thisPtr.RemovePendingOperation();
        }
 private ReceiveContextAsyncResult(WorkflowOperationContext context, ReceiveContext receiveContext, AsyncCallback callback, object state) : base(callback, state)
 {
     this.context        = context;
     this.receiveContext = receiveContext;
     if (this.ProcessReceiveContext())
     {
         base.Complete(true);
     }
 }
        private static bool HandleEndResumeBookmark(IAsyncResult result)
        {
            WorkflowOperationContext asyncState = (WorkflowOperationContext)result.AsyncState;
            bool flag  = false;
            bool flag2 = true;

            try
            {
                if (asyncState.workflowInstance.EndResumeProtocolBookmark(result) != BookmarkResumptionResult.Success)
                {
                    asyncState.OperationContext.Host.RaiseUnknownMessageReceived(asyncState.OperationContext.IncomingMessage);
                    if ((asyncState.workflowInstance.BufferedReceiveManager != null) && asyncState.workflowInstance.BufferedReceiveManager.BufferReceive(asyncState.OperationContext, asyncState.receiveContext, asyncState.bookmark.Name, BufferedReceiveState.WaitingOnBookmark, false))
                    {
                        if (System.ServiceModel.Activities.TD.BufferOutOfOrderMessageNoBookmarkIsEnabled())
                        {
                            System.ServiceModel.Activities.TD.BufferOutOfOrderMessageNoBookmark(asyncState.workflowInstance.Id.ToString(), asyncState.bookmark.Name);
                        }
                        flag2 = false;
                    }
                    throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new FaultException(OperationExecutionFault.CreateOperationNotAvailableFault(asyncState.workflowInstance.Id, asyncState.bookmark.Name)));
                }
                lock (asyncState.thisLock)
                {
                    if (asyncState.CurrentState == State.ResultReceived)
                    {
                        asyncState.CurrentState = State.Completed;
                        if (asyncState.pendingException != null)
                        {
                            throw System.ServiceModel.Activities.FxTrace.Exception.AsError(asyncState.pendingException);
                        }
                        flag = true;
                    }
                    else
                    {
                        asyncState.CurrentState = State.WaitForResult;
                        flag = false;
                    }
                    if (flag)
                    {
                        flag = asyncState.ProcessReceiveContext();
                    }
                    flag2 = false;
                }
            }
            finally
            {
                if (flag2)
                {
                    BufferedReceiveManager.AbandonReceiveContext(asyncState.receiveContext);
                }
                asyncState.RemovePendingOperation();
            }
            return(flag);
        }
 protected internal virtual Bookmark OnResolveBookmark(WorkflowOperationContext context, out BookmarkScope bookmarkScope, out object value)
 {
     CorrelationMessageProperty property;
     if (CorrelationMessageProperty.TryGet(context.OperationContext.IncomingMessageProperties, out property))
     {
         bookmarkScope = new BookmarkScope(property.CorrelationKey.Value);
     }
     else
     {
         bookmarkScope = BookmarkScope.Default;
     }
     value = context;
     return this.bookmark;
 }
        private void OnMessage(NativeActivityContext executionContext, Bookmark bookmark, object state)
        {
            WorkflowOperationContext context = state as WorkflowOperationContext;

            if (context == null)
            {
                throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.WorkflowMustBeHosted));
            }
            CorrelationResponseContext responseContext = new CorrelationResponseContext {
                WorkflowOperationContext = context
            };
            ReceiveMessageInstanceData instance = new ReceiveMessageInstanceData(responseContext);

            this.SetupTransaction(executionContext, instance);
        }
                protected internal override Bookmark OnResolveBookmark(WorkflowOperationContext context, out BookmarkScope bookmarkScope, out object value)
                {
                    CorrelationMessageProperty property;

                    if (CorrelationMessageProperty.TryGet(context.OperationContext.IncomingMessageProperties, out property))
                    {
                        bookmarkScope = new BookmarkScope(property.CorrelationKey.Value);
                    }
                    else
                    {
                        bookmarkScope = null;
                    }
                    WorkflowHostingResponseContext responseContext = new WorkflowHostingResponseContext(context);
                    Bookmark bookmark = this.hostingEndpoint.OnResolveBookmark(context.Inputs, context.OperationContext, responseContext, out value);

                    if (bookmark == null)
                    {
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(WorkflowHostingEndpoint.CreateDispatchFaultException());
                    }
                    return(bookmark);
                }
        private void SetupTransaction(NativeActivityContext executionContext, ReceiveMessageInstanceData instance)
        {
            WorkflowOperationContext workflowOperationContext = instance.CorrelationResponseContext.WorkflowOperationContext;

            if (workflowOperationContext.CurrentTransaction != null)
            {
                RuntimeTransactionHandle handle = null;
                handle = executionContext.Properties.Find(runtimeTransactionHandlePropertyName) as RuntimeTransactionHandle;
                if (handle == null)
                {
                    throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.ReceiveNotWithinATransactedReceiveScope));
                }
                TransactedReceiveData data = executionContext.Properties.Find(TransactedReceiveData.TransactedReceiveDataExecutionPropertyName) as TransactedReceiveData;
                if ((data != null) && this.AdditionalData.IsFirstReceiveOfTransactedReceiveScopeTree)
                {
                    data.InitiatingTransaction = workflowOperationContext.OperationContext.TransactionFacet.Current;
                }
                Transaction currentTransaction = handle.GetCurrentTransaction(executionContext);
                if (currentTransaction != null)
                {
                    if (!currentTransaction.Equals(workflowOperationContext.CurrentTransaction))
                    {
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.FlowedTransactionDifferentFromAmbient));
                    }
                    this.ServerScheduleOnReceivedMessage(executionContext, instance);
                }
                else
                {
                    ReceiveMessageState state = new ReceiveMessageState {
                        CurrentTransaction = workflowOperationContext.CurrentTransaction.Clone(),
                        Instance           = instance
                    };
                    handle.RequireTransactionContext(executionContext, new Action <NativeActivityTransactionContext, object>(this.RequireContextCallback), state);
                }
            }
            else
            {
                this.ServerScheduleOnReceivedMessage(executionContext, instance);
            }
        }
Пример #9
0
        static bool HandleEndWaitForPendingOperations(IAsyncResult result)
        {
            WorkflowOperationContext thisPtr = (WorkflowOperationContext)result.AsyncState;

            thisPtr.pendingAsyncResult = result;

            bool success = false;

            try
            {
                thisPtr.workflowInstance.EndWaitForPendingOperations(result);
                bool retval = thisPtr.OnResumeBookmark();
                success = true;
                return(retval);
            }
            finally
            {
                if (!success)
                {
                    thisPtr.RemovePendingOperation();
                }
            }
        }
        private static void Finally(AsyncResult result, Exception completionException)
        {
            WorkflowOperationContext context = (WorkflowOperationContext)result;

            context.EmitTransferFromInstanceId();
            if (completionException != null)
            {
                if (completionException is FaultException)
                {
                    context.TrackMethodFaulted();
                }
                else
                {
                    context.TrackMethodFailed();
                }
            }
            else
            {
                context.TrackMethodCompleted(context.operationReturnValue);
            }
            context.ProcessFinalizationTraces();
            context.workflowInstance.ReleaseContext(context);
            context.RemovePendingOperation();
        }
Пример #11
0
                protected internal override Bookmark OnResolveBookmark(WorkflowOperationContext context, out BookmarkScope bookmarkScope, out object value)
                {
                    CorrelationMessageProperty correlationMessageProperty;

                    if (CorrelationMessageProperty.TryGet(context.OperationContext.IncomingMessageProperties, out correlationMessageProperty))
                    {
                        bookmarkScope = new BookmarkScope(correlationMessageProperty.CorrelationKey.Value);
                    }
                    else
                    {
                        bookmarkScope = null;
                    }

                    WorkflowHostingResponseContext responseContext = new WorkflowHostingResponseContext(context);

                    Fx.Assert(context.ServiceEndpoint is WorkflowHostingEndpoint, "serviceEnpoint must be of WorkflowHostingEndpoint type!");
                    Bookmark bookmark = ((WorkflowHostingEndpoint)context.ServiceEndpoint).OnResolveBookmark(context.Inputs, context.OperationContext, responseContext, out value);

                    if (bookmark == null)
                    {
                        throw FxTrace.Exception.AsError(CreateDispatchFaultException());
                    }
                    return(bookmark);
                }
        private static bool HandleEndWaitForPendingOperations(IAsyncResult result)
        {
            bool flag3;
            WorkflowOperationContext asyncState = (WorkflowOperationContext)result.AsyncState;

            asyncState.pendingAsyncResult = result;
            bool flag = false;

            try
            {
                asyncState.workflowInstance.EndWaitForPendingOperations(result);
                bool flag2 = asyncState.OnResumeBookmark();
                flag  = true;
                flag3 = flag2;
            }
            finally
            {
                if (!flag)
                {
                    asyncState.RemovePendingOperation();
                }
            }
            return(flag3);
        }
                protected internal override Bookmark OnResolveBookmark(WorkflowOperationContext context, out BookmarkScope bookmarkScope, out object value)
                {
                    CorrelationMessageProperty correlationMessageProperty;
                    if (CorrelationMessageProperty.TryGet(context.OperationContext.IncomingMessageProperties, out correlationMessageProperty))
                    {
                        bookmarkScope = new BookmarkScope(correlationMessageProperty.CorrelationKey.Value);
                    }
                    else
                    {
                        bookmarkScope = null;
                    }

                    WorkflowHostingResponseContext responseContext = new WorkflowHostingResponseContext(context);
                    Fx.Assert(context.ServiceEndpoint is WorkflowHostingEndpoint, "serviceEnpoint must be of WorkflowHostingEndpoint type!");
                    Bookmark bookmark = ((WorkflowHostingEndpoint)context.ServiceEndpoint).OnResolveBookmark(context.Inputs, context.OperationContext, responseContext, out value);
                    if (bookmark == null)
                    {
                        throw FxTrace.Exception.AsError(CreateDispatchFaultException());
                    }
                    return bookmark;
                }
 public void ReleaseContext(WorkflowOperationContext context)
 {
     lock (this.thisLock)
     {
         this.pendingRequests.Remove(context);
     }
 }
 protected internal override Bookmark OnResolveBookmark(WorkflowOperationContext context, out BookmarkScope bookmarkScope, out object value)
 {
     CorrelationMessageProperty property;
     if (CorrelationMessageProperty.TryGet(context.OperationContext.IncomingMessageProperties, out property))
     {
         bookmarkScope = new BookmarkScope(property.CorrelationKey.Value);
     }
     else
     {
         bookmarkScope = null;
     }
     WorkflowHostingResponseContext responseContext = new WorkflowHostingResponseContext(context);
     Bookmark bookmark = this.hostingEndpoint.OnResolveBookmark(context.Inputs, context.OperationContext, responseContext, out value);
     if (bookmark == null)
     {
         throw System.ServiceModel.Activities.FxTrace.Exception.AsError(WorkflowHostingEndpoint.CreateDispatchFaultException());
     }
     return bookmark;
 }
 public static IAsyncResult BeginProcessReceiveContext(WorkflowOperationContext context, ReceiveContext receiveContext, AsyncCallback callback, object state)
 {
     return new ReceiveContextAsyncResult(context, receiveContext, callback, state);
 }
            ReceiveContextAsyncResult(WorkflowOperationContext context, ReceiveContext receiveContext, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.context = context;
                this.receiveContext = receiveContext;

                if (ProcessReceiveContext())
                {
                    base.Complete(true);
                }
            }
 internal WorkflowHostingResponseContext(WorkflowOperationContext context)
 {
     this.context = context;
 }
Пример #19
0
 public static IAsyncResult BeginProcessReceiveContext(WorkflowOperationContext context, ReceiveContext receiveContext, AsyncCallback callback, object state)
 {
     return(new ReceiveContextAsyncResult(context, receiveContext, callback, state));
 }
 // Used by BookmarkResumption Endpoint
 internal WorkflowHostingResponseContext(WorkflowOperationContext context)
 {
     this.context = context;
 }
Пример #21
0
        static bool HandleEndResumeBookmark(IAsyncResult result)
        {
            WorkflowOperationContext thisPtr = (WorkflowOperationContext)result.AsyncState;

            bool completed     = false;
            bool shouldAbandon = true;

            try
            {
                BookmarkResumptionResult resumptionResult = thisPtr.workflowInstance.EndResumeProtocolBookmark(result);
                if (resumptionResult != BookmarkResumptionResult.Success)
                {
                    // Raise UnkownMessageReceivedEvent when we fail to resume bookmark
                    thisPtr.OperationContext.Host.RaiseUnknownMessageReceived(thisPtr.OperationContext.IncomingMessage);

                    // Only delay-retry this operation once (and only if retries are supported). Future calls will ensure the bookmark is set.
                    if (thisPtr.workflowInstance.BufferedReceiveManager != null)
                    {
                        bool bufferSuccess = thisPtr.workflowInstance.BufferedReceiveManager.BufferReceive(
                            thisPtr.OperationContext, thisPtr.receiveContext, thisPtr.bookmark.Name, BufferedReceiveState.WaitingOnBookmark, false);
                        if (bufferSuccess)
                        {
                            if (TD.BufferOutOfOrderMessageNoBookmarkIsEnabled())
                            {
                                TD.BufferOutOfOrderMessageNoBookmark(thisPtr.eventTraceActivity, thisPtr.workflowInstance.Id.ToString(), thisPtr.bookmark.Name);
                            }

                            shouldAbandon = false;
                        }
                    }

                    // The throw exception is intentional whether or not BufferedReceiveManager is set.
                    // This is to allow exception to bubble up the stack to WCF to cleanup various state (like Transaction).
                    // This is queue scenario and as far as the client is concerned, the client will not see any exception.
                    throw FxTrace.Exception.AsError(new FaultException(OperationExecutionFault.CreateOperationNotAvailableFault(thisPtr.workflowInstance.Id, thisPtr.bookmark.Name)));
                }

                lock (thisPtr.thisLock)
                {
                    if (thisPtr.CurrentState == State.ResultReceived)
                    {
                        thisPtr.CurrentState = State.Completed;
                        if (thisPtr.pendingException != null)
                        {
                            throw FxTrace.Exception.AsError(thisPtr.pendingException);
                        }
                        completed = true;
                    }
                    else
                    {
                        thisPtr.CurrentState = State.WaitForResult;
                        completed            = false;
                    }

                    // we are not really completed until the ReceiveContext finishes its work
                    if (completed)
                    {
                        completed = thisPtr.ProcessReceiveContext();
                    }

                    shouldAbandon = false;
                }
            }
            finally
            {
                if (shouldAbandon)
                {
                    BufferedReceiveManager.AbandonReceiveContext(thisPtr.receiveContext);
                }
                thisPtr.RemovePendingOperation();
            }

            return(completed);
        }