public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            NativeActivityContext nativeContext = executor.NativeActivityContextPool.Acquire();

            try
            {
                nativeContext.Initialize(this.ActivityInstance, executor, bookmarkManager);
                this.callbackWrapper.Invoke(nativeContext, this.bookmark, this.state);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                this.ExceptionToPropagate = e;
            }
            finally
            {
                nativeContext.Dispose();
                executor.NativeActivityContextPool.Release(nativeContext);
            }

            return true;
        }
 internal sealed override void InternalExecute(System.Activities.ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     AsyncOperationContext asyncContext = executor.SetupAsyncOperationBlock(instance);
     instance.IncrementBusyCount();
     AsyncCodeActivityContext context = new AsyncCodeActivityContext(asyncContext, instance, executor);
     bool flag = false;
     try
     {
         IAsyncResult result = this.BeginExecute(context, OnExecuteComplete, asyncContext);
         if (result == null)
         {
             throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.BeginExecuteMustNotReturnANullAsyncResult));
         }
         if (!object.ReferenceEquals(result.AsyncState, asyncContext))
         {
             throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.BeginExecuteMustUseProvidedStateAsAsyncResultState));
         }
         if (result.CompletedSynchronously)
         {
             this.EndExecute(context, result);
             asyncContext.CompleteOperation();
         }
         flag = true;
     }
     finally
     {
         context.Dispose();
         if (!flag)
         {
             asyncContext.CancelOperation();
         }
     }
 }
 internal override void InternalExecute(System.Activities.ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     if (this.runtimeImplementation != null)
     {
         executor.ScheduleActivity(this.runtimeImplementation, instance, null, null, null);
     }
 }
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     NativeActivityFaultContext faultContext = null;
     try
     {
         faultContext = new NativeActivityFaultContext(base.ActivityInstance, executor, bookmarkManager, this.propagatedException, this.originalExceptionSource);
         this.callbackWrapper.Invoke(faultContext, this.propagatedException, this.propagatedFrom);
         if (!faultContext.IsFaultHandled)
         {
             base.SetExceptionToPropagateWithoutAbort(this.propagatedException);
         }
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         base.ExceptionToPropagate = exception;
     }
     finally
     {
         if (faultContext != null)
         {
             faultContext.Dispose();
         }
     }
     return true;
 }
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     if ((base.CompletedInstance.State != ActivityInstanceState.Closed) && base.ActivityInstance.IsPerformingDefaultCancelation)
     {
         base.ActivityInstance.MarkCanceled();
     }
     return base.Execute(executor, bookmarkManager);
 }
Exemplo n.º 6
0
        internal NativeActivityFaultContext(ActivityInstance executingActivityInstance,
            ActivityExecutor executor, BookmarkManager bookmarkManager, Exception exception, ActivityInstanceReference source)
            : base(executingActivityInstance, executor, bookmarkManager)
        {
            Fx.Assert(exception != null, "There must be an exception.");
            Fx.Assert(source != null, "There must be a source.");

            this.exception = exception;
            this.source = source;
        }
 internal sealed override void InternalCancel(System.Activities.ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     AsyncOperationContext context;
     if (executor.TryGetPendingOperation(instance, out context))
     {
         using (AsyncCodeActivityContext context2 = new AsyncCodeActivityContext(context, instance, executor))
         {
             context.HasCalledAsyncCodeActivityCancel = true;
             this.Cancel(context2);
         }
     }
 }
 internal override void InternalCancel(System.Activities.ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     NativeActivityContext context = executor.NativeActivityContextPool.Acquire();
     try
     {
         context.Initialize(instance, executor, bookmarkManager);
         this.Cancel(context);
     }
     finally
     {
         context.Dispose();
         executor.NativeActivityContextPool.Release(context);
     }
 }
 internal sealed override void InternalExecute(System.Activities.ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     CodeActivityContext context = executor.CodeActivityContextPool.Acquire();
     try
     {
         context.Initialize(instance, executor);
         this.Execute(context);
     }
     finally
     {
         context.Dispose();
         executor.CodeActivityContextPool.Release(context);
     }
 }
            public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
            {
                NativeActivityFaultContext faultContext = null;

                try
                {
                    faultContext = new NativeActivityFaultContext(this.ActivityInstance, executor, bookmarkManager, this.propagatedException, this.originalExceptionSource);
                    this.callbackWrapper.Invoke(faultContext, this.propagatedException, this.propagatedFrom);

                    if (!faultContext.IsFaultHandled)
                    {
                        SetExceptionToPropagateWithoutAbort(this.propagatedException);
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    this.ExceptionToPropagate = e;
                }
                finally
                {
                    if (faultContext != null)
                    {
                        faultContext.Dispose();
                    }

                    // Tell the executor to decrement its no persist count persistence of exceptions is disabled.
                    executor.ExitNoPersistForExceptionPropagation();
                }

                return true;
            }
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     base.ActivityInstance.ResolveArguments(executor, this.argumentValueOverrides, this.resultLocation, this.nextArgumentIndex);
     return true;
 }
        public void PurgeBookmarks(BookmarkManager nonScopedBookmarkManager, Bookmark singleBookmark, IList<Bookmark> multipleBookmarks)
        {
            if (singleBookmark != null)
            {
                PurgeBookmark(singleBookmark, nonScopedBookmarkManager);
            }
            else
            {
                Fx.Assert(multipleBookmarks != null, "caller should never pass null");
                for (int i = 0; i < multipleBookmarks.Count; i++)
                {
                    Bookmark bookmark = multipleBookmarks[i];

                    PurgeBookmark(bookmark, nonScopedBookmarkManager);
                }
            }
        }
        void PurgeBookmark(Bookmark bookmark, BookmarkManager nonScopedBookmarkManager)
        {
            BookmarkManager manager = null;

            if (bookmark.Scope != null)
            {
                BookmarkScope lookupScope = bookmark.Scope;

                if (bookmark.Scope.IsDefault)
                {
                    lookupScope = this.defaultScope;
                }

                Fx.Assert(this.bookmarkManagers.ContainsKey(bookmark.Scope), "We should have the single bookmark's sub instance registered");
                manager = this.bookmarkManagers[bookmark.Scope];
            }
            else
            {
                manager = nonScopedBookmarkManager;
            }

            manager.PurgeSingleBookmark(bookmark);
        }
            public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
            {
                NativeActivityContext context = executor.NativeActivityContextPool.Acquire();

                Fx.Assert(this.completedInstance.Activity != null, "Activity definition should always be associated with an activity instance.");

                try
                {
                    context.Initialize(this.ActivityInstance, executor, bookmarkManager);
                    this.callbackWrapper.Invoke(context, this.completedInstance);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    this.ExceptionToPropagate = e;
                }
                finally
                {
                    context.Dispose();
                    executor.NativeActivityContextPool.Release(context);

                    if (this.ActivityInstance.InstanceMap != null)
                    {
                        this.ActivityInstance.InstanceMap.RemoveEntry(this);
                    }
                }

                return true;
            }
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     this.location.TemporaryResolutionEnvironment.CollapseTemporaryResolutionLocation(this.location);
     return(true);
 }
 internal sealed override void InternalCancel(System.Activities.ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
 }
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     this.location.TemporaryResolutionEnvironment.CollapseTemporaryResolutionLocation(this.location);
     return true;
 }
 internal NativeActivityFaultContext(System.Activities.ActivityInstance executingActivityInstance, ActivityExecutor executor, BookmarkManager bookmarkManager, Exception exception, ActivityInstanceReference source) : base(executingActivityInstance, executor, bookmarkManager)
 {
     this.exception = exception;
     this.source = source;
 }
Exemplo n.º 19
0
 sealed internal override void InternalCancel(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     Fx.Assert("Cancel should never be called on CodeActivity since it's synchronous");
 }
        /// <summary>
        /// Execute the work item
        /// </summary>
        /// <param name="executor">The executor</param>
        /// <param name="bookmarkManager">The bookmark manager</param>
        /// <returns>True to continue executing work items, false to yield the thread</returns>
        public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            ActivityInfo activityInfo = null;
            this.TrackExecuting(executor, ref activityInfo);

            try
            {
                executor.ExecuteInResolutionContextUntyped(this.ActivityInstance, this.expressionActivity, this.instanceId, this.resultLocation);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                this.TrackFaulted(executor, ref activityInfo);

                if (this.nextArgumentWorkItem != null)
                {
                    executor.ScheduleItem(this.nextArgumentWorkItem);
                }

                executor.ScheduleExpressionFaultPropagation(this.expressionActivity, this.instanceId, this.ActivityInstance, e);
                return true;
            }
            finally
            {
                if (this.ActivityInstance.InstanceMap != null)
                {
                    this.ActivityInstance.InstanceMap.RemoveEntry(this);
                }
            }

            this.TrackClosed(executor, ref activityInfo);

            if (this.nextArgumentWorkItem != null)
            {
                this.EvaluateNextArgument(executor);
            }

            return true;
        }
 public abstract bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager);
Exemplo n.º 22
0
 public abstract bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager);
Exemplo n.º 23
0
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     base.ActivityInstance.ResolveArguments(executor, this.argumentValueOverrides, this.resultLocation, this.nextArgumentIndex);
     return(true);
 }
Exemplo n.º 24
0
        public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            Fx.Assert("Empty work items should never been executed.");

            return(true);
        }
        public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            Fx.Assert("Empty work items should never been executed.");

            return true;
        }
Exemplo n.º 26
0
        public BookmarkResumptionResult TryGenerateWorkItem(ActivityExecutor executor, ref Bookmark bookmark, BookmarkScope scope, object value, System.Activities.ActivityInstance isolationInstance, bool nonScopedBookmarksExist, out ActivityExecutionWorkItem workItem)
        {
            BookmarkManager          manager = null;
            Bookmark                 bookmark3;
            BookmarkCallbackWrapper  wrapper2;
            BookmarkResumptionResult result3;

            workItem = null;
            BookmarkScope key = scope;

            if (scope.IsDefault)
            {
                key = this.defaultScope;
            }
            this.bookmarkManagers.TryGetValue(key, out manager);
            if (manager == null)
            {
                BookmarkResumptionResult notFound = BookmarkResumptionResult.NotFound;
                if (this.uninitializedScopes != null)
                {
                    for (int i = 0; i < this.uninitializedScopes.Count; i++)
                    {
                        Bookmark bookmark2;
                        BookmarkCallbackWrapper  wrapper;
                        BookmarkResumptionResult notReady;
                        BookmarkScope            scope3 = this.uninitializedScopes[i];
                        if (!this.bookmarkManagers[scope3].TryGetBookmarkFromInternalList(bookmark, out bookmark2, out wrapper))
                        {
                            notReady = BookmarkResumptionResult.NotFound;
                        }
                        else if (this.IsExclusiveScopeUnstable(bookmark2))
                        {
                            notReady = BookmarkResumptionResult.NotReady;
                        }
                        else
                        {
                            notReady = this.bookmarkManagers[scope3].TryGenerateWorkItem(executor, true, ref bookmark, value, isolationInstance, out workItem);
                        }
                        switch (notReady)
                        {
                        case BookmarkResumptionResult.Success:
                            this.InitializeBookmarkScopeWithoutKeyAssociation(scope3, scope.Id);
                            return(BookmarkResumptionResult.Success);

                        case BookmarkResumptionResult.NotReady:
                            notFound = BookmarkResumptionResult.NotReady;
                            break;

                        default:
                            if ((notFound == BookmarkResumptionResult.NotFound) && !this.IsStable(scope3, nonScopedBookmarksExist))
                            {
                                notFound = BookmarkResumptionResult.NotReady;
                            }
                            break;
                        }
                    }
                }
                return(notFound);
            }
            if (!manager.TryGetBookmarkFromInternalList(bookmark, out bookmark3, out wrapper2))
            {
                result3 = BookmarkResumptionResult.NotFound;
            }
            else if (this.IsExclusiveScopeUnstable(bookmark3))
            {
                result3 = BookmarkResumptionResult.NotReady;
            }
            else
            {
                result3 = manager.TryGenerateWorkItem(executor, true, ref bookmark, value, isolationInstance, out workItem);
            }
            if ((result3 == BookmarkResumptionResult.NotFound) && !this.IsStable(key, nonScopedBookmarksExist))
            {
                result3 = BookmarkResumptionResult.NotReady;
            }
            return(result3);
        }
Exemplo n.º 27
0
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     return(true);
 }
 sealed internal override void InternalCancel(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     AsyncOperationContext asyncContext;
     if (executor.TryGetPendingOperation(instance, out asyncContext))
     {
         AsyncCodeActivityContext context = new AsyncCodeActivityContext(asyncContext, instance, executor);
         try
         {
             asyncContext.HasCalledAsyncCodeActivityCancel = true;
             Cancel(context);
         }
         finally
         {
             context.Dispose();
         }
     }
 }
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     return true;
 }
                public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
                {
                    AsyncCodeActivityContext context = null;

                    try
                    {
                        context = new AsyncCodeActivityContext(this.asyncContext, this.ActivityInstance, executor);
                        IAsyncCodeActivity owner = (IAsyncCodeActivity)this.ActivityInstance.Activity;
                        owner.FinishExecution(context, this.result);
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        this.ExceptionToPropagate = e;
                    }
                    finally
                    {
                        if (context != null)
                        {
                            context.Dispose();
                        }
                    }

                    return true;
                }
 public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
 {
     NativeActivityContext context = executor.NativeActivityContextPool.Acquire();
     try
     {
         context.Initialize(base.ActivityInstance, executor, bookmarkManager);
         this.callbackWrapper.Invoke(context, this.completedInstance);
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         base.ExceptionToPropagate = exception;
     }
     finally
     {
         context.Dispose();
         executor.NativeActivityContextPool.Release(context);
         if (base.ActivityInstance.InstanceMap != null)
         {
             base.ActivityInstance.InstanceMap.RemoveEntry(this);
         }
     }
     return true;
 }
        public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            this.ActivityInstance.ResolveArguments(executor, argumentValueOverrides, resultLocation, nextArgumentIndex);

            // Return true always to prevent scheduler from yielding silently.
            return true;
        }
 internal NativeActivityTransactionContext(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarks, RuntimeTransactionHandle handle)
     : base(instance, executor, bookmarks)
 {
     this.executor = executor;
     this.transactionHandle = handle;
 }
Exemplo n.º 34
0
        public BookmarkResumptionResult TryGenerateWorkItem(ActivityExecutor executor, ref Bookmark bookmark, BookmarkScope scope, object value, ActivityInstance isolationInstance, bool nonScopedBookmarksExist, out ActivityExecutionWorkItem workItem)
        {
            Fx.Assert(scope != null, "We should never have a null sub instance.");

            BookmarkManager manager = null;

            workItem = null;
            BookmarkScope lookupScope = scope;

            if (scope.IsDefault)
            {
                lookupScope = this.defaultScope;
            }

            // We don't really care about the return value since we'll
            // use null to know we should check uninitialized sub instances
            this.bookmarkManagers.TryGetValue(lookupScope, out manager);

            if (manager == null)
            {
                Fx.Assert(lookupScope != null, "The sub instance should not be default if we are here.");

                BookmarkResumptionResult finalResult = BookmarkResumptionResult.NotFound;

                // Check the uninitialized sub instances for a matching bookmark
                if (this.uninitializedScopes != null)
                {
                    for (int i = 0; i < this.uninitializedScopes.Count; i++)
                    {
                        BookmarkScope uninitializedScope = this.uninitializedScopes[i];

                        Fx.Assert(this.bookmarkManagers.ContainsKey(uninitializedScope), "We must always have the uninitialized sub instances.");

                        Bookmark internalBookmark;
                        BookmarkCallbackWrapper  callbackWrapper;
                        BookmarkResumptionResult resumptionResult;
                        if (!this.bookmarkManagers[uninitializedScope].TryGetBookmarkFromInternalList(bookmark, out internalBookmark, out callbackWrapper))
                        {
                            resumptionResult = BookmarkResumptionResult.NotFound;
                        }
                        else if (IsExclusiveScopeUnstable(internalBookmark))
                        {
                            resumptionResult = BookmarkResumptionResult.NotReady;
                        }
                        else
                        {
                            resumptionResult = this.bookmarkManagers[uninitializedScope].TryGenerateWorkItem(executor, true, ref bookmark, value, isolationInstance, out workItem);
                        }

                        if (resumptionResult == BookmarkResumptionResult.Success)
                        {
                            // We are using InitializeBookmarkScopeWithoutKeyAssociation because we know this is a new uninitialized scope and
                            // the key we would associate is already associated. And if we did the association here, the subsequent call to
                            // FlushBookmarkScopeKeys would try to flush it out, but it won't have the transaction correct so will hang waiting for
                            // the transaction that has the PersistenceContext locked to complete. But it won't complete successfully until
                            // we finish processing here.
                            InitializeBookmarkScopeWithoutKeyAssociation(uninitializedScope, scope.Id);

                            // We've found what we were looking for
                            return(BookmarkResumptionResult.Success);
                        }
                        else if (resumptionResult == BookmarkResumptionResult.NotReady)
                        {
                            // This uninitialized sub-instance has a matching bookmark but
                            // it can't currently be resumed.  We won't return BookmarkNotFound
                            // because of this.
                            finalResult = BookmarkResumptionResult.NotReady;
                        }
                        else
                        {
                            if (finalResult == BookmarkResumptionResult.NotFound)
                            {
                                // If we still are planning on returning failure then
                                // we'll incur the cost of seeing if this scope is
                                // stable or not.

                                if (!IsStable(uninitializedScope, nonScopedBookmarksExist))
                                {
                                    // There exists an uninitialized scope which is unstable.
                                    // At the very least this means we'll return NotReady since
                                    // this uninitialized scope might eventually contain this
                                    // bookmark.
                                    finalResult = BookmarkResumptionResult.NotReady;
                                }
                            }
                        }
                    }
                }

                return(finalResult);
            }
            else
            {
                Bookmark bookmarkFromList;
                BookmarkCallbackWrapper  callbackWrapper;
                BookmarkResumptionResult resumptionResult;
                if (!manager.TryGetBookmarkFromInternalList(bookmark, out bookmarkFromList, out callbackWrapper))
                {
                    resumptionResult = BookmarkResumptionResult.NotFound;
                }
                else
                {
                    if (IsExclusiveScopeUnstable(bookmarkFromList))
                    {
                        resumptionResult = BookmarkResumptionResult.NotReady;
                    }
                    else
                    {
                        resumptionResult = manager.TryGenerateWorkItem(executor, true, ref bookmark, value, isolationInstance, out workItem);
                    }
                }


                if (resumptionResult == BookmarkResumptionResult.NotFound)
                {
                    if (!IsStable(lookupScope, nonScopedBookmarksExist))
                    {
                        resumptionResult = BookmarkResumptionResult.NotReady;
                    }
                }

                return(resumptionResult);
            }
        }