public OpenAsyncResult(SqlPersistenceProviderFactory provider, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                Fx.Assert(provider != null,
                    "Provider should never be null.");

                this.provider = provider;
                this.timeout = timeout;

                ActionItem.Schedule(ScheduledCallback, null);
            }
 public DeleteHandler(SqlPersistenceProviderFactory provider)
     : base(provider)
 {
 }
 public LoadHandler(SqlPersistenceProviderFactory provider)
     : base(provider)
 {
 }
            public CloseAsyncResult(SqlPersistenceProviderFactory provider, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                // There is no point in even pretending SqlConnection.Close needs async
                provider.OnClose(timeout);

                Complete(true);
            }
 public UnlockHandler(SqlPersistenceProviderFactory provider)
     : base(provider)
 {
 }
 public SqlPersistenceProvider(Guid id, SqlPersistenceProviderFactory factory)
     : base(id)
 {
     this.factory = factory;
 }
 public OperationHandler(SqlPersistenceProviderFactory provider)
 {
     this.provider = provider;
 }
            public OperationAsyncResult(OperationHandler handler, SqlPersistenceProviderFactory provider, Guid id, TimeSpan timeout, AsyncCallback callback, object state, params object[] additionalParameters)
                : base(callback, state)
            {
                Fx.Assert(provider != null,
                    "Provider should never be null.");

                this.handler = handler;
                this.provider = provider;
                this.id = id;

                if (this.handler.ShortcutExecution)
                {
                    Complete(true);
                    return;
                }

                TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
                SqlConnection connection = this.provider.OpenConnection(timeoutHelper.RemainingTime());

                bool completeSelf = false;
                Exception delayedException = null;
                try
                {
                    this.command = this.provider.CreateCommand(connection, timeoutHelper.RemainingTime());

                    this.handler.SetupCommand(this.command, this.id, additionalParameters);

                    IAsyncResult result = null;

                    if (this.handler.ExecuteReader)
                    {
                        result = this.command.BeginExecuteReader(commandCallback, this);
                    }
                    else
                    {
                        result = this.command.BeginExecuteNonQuery(commandCallback, this);
                    }

                    if (result.CompletedSynchronously)
                    {
                        delayedException = CompleteOperation(result);

                        completeSelf = true;
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    try
                    {
                        connection.Close();
                        this.provider.CleanupCommand(this.command);
                    }
                    catch (Exception e1)
                    {
                        if (Fx.IsFatal(e1))
                        {
                            throw;
                        }
                        // do not rethrow non-fatal exceptions thrown from cleanup code
                    }
                    finally
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                            new PersistenceException(
                            SR2.GetString(SR2.PersistenceOperationError, this.handler.OperationName), e));
                    }
                }

                if (completeSelf)
                {
                    connection.Close();
                    this.provider.CleanupCommand(this.command);

                    if (delayedException != null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(delayedException);
                    }

                    Complete(true);
                }
            }