Beispiel #1
0
        private void EndExecuteReaderCallBack(IAsyncResult result)
        {
            DbAsyncState state = null;

            try
            {
                // Retrieve the original command object, passed
                // to this procedure in the AsyncState property
                // of the IAsyncResult parameter.
                DaabAsyncResult blockResult = (DaabAsyncResult)result;
                state = (DbAsyncState)blockResult.AsyncState;

                state.State       = (object)state.Database.EndExecuteReader(blockResult);
                state.AsyncResult = blockResult;
            }

            catch (Exception exp)
            {
                state.Exception = exp;
            }

            finally
            {
                if (state != null)
                {
                    state.AutoResetEvent.Set();
                }
            }
        }
Beispiel #2
0
        protected DbAsyncState BeginExecute(Database db, AsyncCallback cb, Func <DbAsyncState, DaabAsyncResult> execute)
        {
            DbAsyncState stateObject = GetNewStateObject(db);

            stateObject.AsyncResult = execute(stateObject);
            bool stateSignalled = stateObject.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 20));

            if (stateSignalled == false && cb != null)
            {
                throw new Exception("Callback thread did not raise the event, test failed");
            }
            return(stateObject);
        }
        private DbAsyncState BeginExecuteXmlReader(SqlDatabase db, DbCommand command, DbTransaction transaction, AsyncCallback cb)
        {
            DbAsyncState stateObject = GetNewStateObject(db);

            stateObject.AsyncResult = (DaabAsyncResult)db.BeginExecuteXmlReader(command, transaction, cb, (object)stateObject);
            bool stateSignalled = stateObject.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 20));

            if (stateSignalled == false && cb != null)
            {
                throw new Exception("Callback thread did not raise the event, test failed");
            }
            return(stateObject);
        }
Beispiel #4
0
        public void RecordsAreReturnedWhenExecutingExecuteReaderWithStoredProcParamsAndCallBack()
        {
            Database      db = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            AsyncCallback cb = new AsyncCallback(EndExecuteReaderCallBack);

            object[]     paramsArray      = { "10248" };
            DataSet      ds               = db.ExecuteDataSet("CustOrdersDetail", paramsArray);
            int          expectedRowCount = ds.Tables[0].Rows.Count;
            DataTable    dt               = new DataTable();
            DbAsyncState state            = BeginExecuteReader(db, "CustOrdersDetail", cb, paramsArray);
            IDataReader  reader           = (IDataReader)state.State;

            dt.Load(reader);
            reader.Close();

            Assert.AreEqual <int>(expectedRowCount, dt.Rows.Count);
            Assert.AreEqual <ConnectionState>(ConnectionState.Closed, state.AsyncResult.Connection.State);
        }