Ejemplo n.º 1
0
        protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
        {
            if (_beforePrepareAsyncCompletionAction != null)
            {
                _beforePrepareAsyncCompletionAction();
            }

            _nextAsyncCompletion = callback;
            if (AsyncResult.s_asyncCompletionWrapperCallback == null)
            {
                AsyncResult.s_asyncCompletionWrapperCallback = Fx.ThunkCallback(new AsyncCallback(AsyncCompletionWrapperCallback));
            }
            return(AsyncResult.s_asyncCompletionWrapperCallback);
        }
Ejemplo n.º 2
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
                ICollection <InstanceKey> 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
                ICollection <InstanceKey> 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 (s_associateCallback == null)
                    {
                        s_associateCallback = Fx.ThunkCallback(new AsyncCallback(OnAssociateComplete));
                    }

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

                this.workflowAbortException = e;
            }

            return(true);
        }
Ejemplo n.º 3
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 (s_trackingCallback == null)
                {
                    s_trackingCallback = Fx.ThunkCallback(new AsyncCallback(OnTrackingComplete));
                }

                IAsyncResult result = executor.BeginTrackPendingRecords(
                    s_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;
                }

                this.workflowAbortException = e;
            }

            return(true);
        }
Ejemplo n.º 4
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;

                bool completeSelf = false;

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

                        IPersistencePipelineModule 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);
                }
            }