Exemplo n.º 1
0
 public bool FlushTracking(ActivityExecutor executor)
 {
     try
     {
         if (trackingCallback == null)
         {
             trackingCallback = Fx.ThunkCallback(new AsyncCallback(System.Activities.Runtime.WorkItem.OnTrackingComplete));
         }
         IAsyncResult result = executor.BeginTrackPendingRecords(trackingCallback, new CallbackData(executor, this));
         if (result.CompletedSynchronously)
         {
             executor.EndTrackPendingRecords(result);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         this.workflowAbortException = exception;
     }
     return(true);
 }
Exemplo n.º 2
0
        protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
        {
            this._beforePrepareAsyncCompletionAction?.Invoke();

            this._nextAsyncCompletion = callback;
            if (AsyncResult.s_asyncCompletionWrapperCallback == null)
            {
                AsyncResult.s_asyncCompletionWrapperCallback = Fx.ThunkCallback(new AsyncCallback(AsyncCompletionWrapperCallback));
            }

            return(AsyncResult.s_asyncCompletionWrapperCallback);
        }
Exemplo n.º 3
0
        public bool FlushBookmarkScopeKeys(ActivityExecutor executor)
        {
            Fx.Assert(executor.BookmarkScopeManager.HasKeysToUpdate, "We should not have been called if we don't have pending keys.");

            try
            {
                // disassociation is local-only so we don't need to yield
                var keysToDisassociate = executor.BookmarkScopeManager.GetKeysToDisassociate();
                if (keysToDisassociate != null && keysToDisassociate.Count > 0)
                {
                    executor.DisassociateKeys(keysToDisassociate);
                }

                // if we have keys to associate, provide them for an asynchronous association
                var keysToAssociate = executor.BookmarkScopeManager.GetKeysToAssociate();

                // It could be that we only had keys to Disassociate. We should only do BeginAssociateKeys
                // if we have keysToAssociate.
                if (keysToAssociate != null && keysToAssociate.Count > 0)
                {
                    if (associateCallback == null)
                    {
                        associateCallback = Fx.ThunkCallback(new AsyncCallback(OnAssociateComplete));
                    }

                    var result = executor.BeginAssociateKeys(keysToAssociate, associateCallback, new CallbackData(executor, this));
                    if (result.CompletedSynchronously)
                    {
                        executor.EndAssociateKeys(result);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                _workflowAbortException = e;
            }

            return(true);
        }
Exemplo n.º 4
0
 public bool FlushBookmarkScopeKeys(ActivityExecutor executor)
 {
     try
     {
         ICollection <InstanceKey> keysToDisassociate = executor.BookmarkScopeManager.GetKeysToDisassociate();
         if ((keysToDisassociate != null) && (keysToDisassociate.Count > 0))
         {
             executor.DisassociateKeys(keysToDisassociate);
         }
         ICollection <InstanceKey> keysToAssociate = executor.BookmarkScopeManager.GetKeysToAssociate();
         if ((keysToAssociate != null) && (keysToAssociate.Count > 0))
         {
             if (associateCallback == null)
             {
                 associateCallback = Fx.ThunkCallback(new AsyncCallback(System.Activities.Runtime.WorkItem.OnAssociateComplete));
             }
             IAsyncResult result = executor.BeginAssociateKeys(keysToAssociate, associateCallback, new CallbackData(executor, this));
             if (result.CompletedSynchronously)
             {
                 executor.EndAssociateKeys(result);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         this.workflowAbortException = exception;
     }
     return(true);
 }
Exemplo n.º 5
0
        public bool FlushTracking(ActivityExecutor executor)
        {
            Fx.Assert(executor.HasPendingTrackingRecords, "We should not have been called if we don't have pending tracking records");

            try
            {
                if (trackingCallback == null)
                {
                    trackingCallback = Fx.ThunkCallback(new AsyncCallback(OnTrackingComplete));
                }

                var result = executor.BeginTrackPendingRecords(
                    trackingCallback,
                    new CallbackData(executor, this));

                if (result.CompletedSynchronously)
                {
                    executor.EndTrackPendingRecords(result);
                }
                else
                {
                    // Completed async so we'll return false
                    return(false);
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                _workflowAbortException = e;
            }

            return(true);
        }
Exemplo n.º 6
0
            public IOAsyncResult(PersistencePipeline pipeline, bool isLoad, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                _pipeline         = pipeline;
                _isLoad           = isLoad;
                _pendingModules   = _pipeline._modules.Where(value => value.IsIOParticipant).ToArray();
                _remainingModules = _pendingModules.Length;

                var completeSelf = false;

                if (_pendingModules.Length == 0)
                {
                    completeSelf = true;
                }
                else
                {
                    for (var i = 0; i < _pendingModules.Length; i++)
                    {
                        Fx.Assert(!completeSelf, "Shouldn't have been completed yet.");

                        var          module = _pendingModules[i];
                        IAsyncResult result = null;
                        try
                        {
                            if (_isLoad)
                            {
                                result = module.BeginOnLoad(_pipeline._readWriteView, timeout, Fx.ThunkCallback(new AsyncCallback(OnIOComplete)), i);
                            }
                            else
                            {
                                result = module.BeginOnSave(_pipeline._readWriteView, _pipeline._writeOnlyView, timeout, Fx.ThunkCallback(new AsyncCallback(OnIOComplete)), i);
                            }
                        }
                        catch (Exception exception)
                        {
                            if (Fx.IsFatal(exception))
                            {
                                throw;
                            }

                            _pendingModules[i] = null;
                            ProcessException(exception);
                        }
                        if (result == null)
                        {
                            if (CompleteOne())
                            {
                                completeSelf = true;
                            }
                        }
                        else if (result.CompletedSynchronously)
                        {
                            _pendingModules[i] = null;
                            if (IOComplete(result, module))
                            {
                                completeSelf = true;
                            }
                        }
                    }
                }

                if (completeSelf)
                {
                    Complete(true, _exception);
                }
            }