Esempio n. 1
0
 private bool TryContinueHelper(IAsyncResult result, out AsyncResult.AsyncCompletion callback)
 {
     if (result != null)
     {
         callback = null;
         if (this.checkSyncValidationFunc == null)
         {
             if (!result.CompletedSynchronously)
             {
                 return(false);
             }
         }
         else
         {
             if (!this.checkSyncValidationFunc(result))
             {
                 return(false);
             }
         }
         callback = this.GetNextCompletion();
         if (callback == null)
         {
             AsyncResult.ThrowInvalidAsyncResult("Only call Check/SyncContinue once per async operation (once per PrepareAsyncCompletion).");
         }
         return(true);
     }
     else
     {
         throw new InvalidOperationException("InvalidNullAsyncResult");                 //TODO: Fx.Exception.AsError(new InvalidOperationException(InternalSR.InvalidNullAsyncResult));
     }
 }
Esempio n. 2
0
 public void Prepared()
 {
     if (this.State != AsyncResult.TransactionSignalState.Ready)
     {
         AsyncResult.ThrowInvalidAsyncResult("PrepareAsyncCompletion should only be called once per PrepareTransactionalCall.");
     }
     this.State = AsyncResult.TransactionSignalState.Prepared;
 }
Esempio n. 3
0
        private static void AsyncCompletionWrapperCallback(IAsyncResult result)
        {
            if (result != null)
            {
                if (!result.CompletedSynchronously)
                {
                    AsyncResult asyncState = (AsyncResult)result.AsyncState;
                    if (asyncState.OnContinueAsyncCompletion(result))
                    {
                        AsyncResult.AsyncCompletion nextCompletion = asyncState.GetNextCompletion();
                        if (nextCompletion == null)
                        {
                            AsyncResult.ThrowInvalidAsyncResult(result);
                        }
                        bool      flag      = false;
                        Exception exception = null;
                        try
                        {
                            flag = nextCompletion(result);
                        }
                        catch (Exception exception2)
                        {
                            Exception exception1 = exception2;
                            //TODO:

                            /*if (!Fx.IsFatal(exception1))
                             * {
                             *      flag = true;
                             *      exception = exception1;
                             * }
                             * else
                             * {
                             *      throw;
                             * }
                             */
                            throw;
                        }
                        if (flag)
                        {
                            asyncState.Complete(false, exception);
                        }
                        return;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                throw new InvalidOperationException("InvalidNullAsyncResult");                 //TODO: Fx.Exception.AsError(new InvalidOperationException(InternalSR.InvalidNullAsyncResult));
            }
        }
            void IDisposable.Dispose()
            {
                if (State == TransactionSignalState.Ready)
                {
                    State = TransactionSignalState.Abandoned;
                }
                else if (State == TransactionSignalState.Prepared)
                {
                    State = TransactionSignalState.Completed;
                }
                else
                {
                    AsyncResult.ThrowInvalidAsyncResult("PrepareTransactionalCall should only be called in a using. Dispose called multiple times.");
                }

                try
                {
                    TransactionHelper.CompleteTransactionScope(ref this.transactionScope);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    // Complete and Dispose are not expected to throw.  If they do it can mess up the AsyncResult state machine.
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.AsyncTransactionException));
                }

                // This will release the callback to run, or tell us that we need to defer the callback to Check/SyncContinue.
                //
                // It's possible to avoid this Interlocked when CompletedSynchronously is true, but we have no way of knowing that
                // from here, and adding a way would add complexity to the AsyncResult transactional calling pattern. This
                // unnecessary Interlocked only happens when: PrepareTransactionalCall is called with a non-null transaction,
                // PrepareAsyncCompletion is reached, and the operation completes synchronously or with an exception.
                IAsyncResult result;

                if (State == TransactionSignalState.Completed && Unlock(out result))
                {
                    if (this.parent.deferredTransactionalResult != null)
                    {
                        AsyncResult.ThrowInvalidAsyncResult(this.parent.deferredTransactionalResult);
                    }
                    this.parent.deferredTransactionalResult = result;
                }
            }
Esempio n. 5
0
            void IDisposable.Dispose()
            {
                IAsyncResult result;

                if (this.State == AsyncResult.TransactionSignalState.Ready)
                {
                    this.State = AsyncResult.TransactionSignalState.Abandoned;
                }
                else if (this.State == AsyncResult.TransactionSignalState.Prepared)
                {
                    this.State = AsyncResult.TransactionSignalState.Completed;
                }
                else
                {
                    AsyncResult.ThrowInvalidAsyncResult("PrepareTransactionalCall should only be called in a using. Dispose called multiple times.");
                }
                try
                {
                    Fx.CompleteTransactionScope(ref this.transactionScope);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.AsyncTransactionException));
                }
                if ((this.State == AsyncResult.TransactionSignalState.Completed) && base.Unlock(out result))
                {
                    if (this.parent.deferredTransactionalResult != null)
                    {
                        AsyncResult.ThrowInvalidAsyncResult(this.parent.deferredTransactionalResult);
                    }
                    this.parent.deferredTransactionalResult = result;
                }
            }