private void InternalExecuteQueryAsync(AseCommand command, AseTransaction transaction, TaskCompletionSource <DbDataReader> readerSource, CommandBehavior behavior) { AssertExecutionStart(); try { SendPacket(new NormalPacket(BuildCommandTokens(command, behavior))); var envChangeTokenHandler = new EnvChangeTokenHandler(_environment, _parameters.Charset); var doneHandler = new DoneTokenHandler(); var messageHandler = new MessageTokenHandler(EventNotifier); var dataReaderHandler = new DataReaderTokenHandler(); var responseParameterTokenHandler = new ResponseParameterTokenHandler(command.AseParameters); ReceiveTokens( envChangeTokenHandler, doneHandler, messageHandler, dataReaderHandler, responseParameterTokenHandler); AssertExecutionCompletion(doneHandler); if (transaction != null && doneHandler.TransactionState == TranState.TDS_TRAN_ABORT) { transaction.MarkAborted(); } messageHandler.AssertNoErrors(); if (doneHandler.Canceled) { readerSource.TrySetCanceled(); // If we have already begun returning data, then this will get lost. } else { #if ENABLE_SYSTEM_DATA_COMMON_EXTENSIONS readerSource.TrySetResult(new AseDataReader(dataReaderHandler.Results(), command, behavior)); #else readerSource.TrySetResult(new AseDataReader(dataReaderHandler.Results(), behavior)); #endif } } catch (Exception ex) { readerSource.TrySetException(ex); // If we have already begun returning data, then this will get lost. } }
private void InternalExecuteNonQueryAsync(AseCommand command, AseTransaction transaction, TaskCompletionSource <int> rowsAffectedSource) { AssertExecutionStart(); try { SendPacket(new NormalPacket(BuildCommandTokens(command, CommandBehavior.Default))); var envChangeTokenHandler = new EnvChangeTokenHandler(_environment, _parameters.Charset); var messageHandler = new MessageTokenHandler(EventNotifier); var responseParameterTokenHandler = new ResponseParameterTokenHandler(command.AseParameters); var doneHandler = new DoneTokenHandler(); ReceiveTokens( envChangeTokenHandler, messageHandler, responseParameterTokenHandler, doneHandler); AssertExecutionCompletion(doneHandler); if (transaction != null && doneHandler.TransactionState == TranState.TDS_TRAN_ABORT) { transaction.MarkAborted(); } messageHandler.AssertNoErrors(); if (doneHandler.Canceled) { rowsAffectedSource.TrySetCanceled(); } else { rowsAffectedSource.TrySetResult(doneHandler.RowsAffected); } } catch (Exception ex) { if (!rowsAffectedSource.TrySetException(ex)) { throw; } } }
private void InternalExecuteAsync(AseCommand command, AseTransaction transaction, TaskCompletionSource <int> rowsAffectedSource = null, TaskCompletionSource <DbDataReader> readerSource = null, CommandBehavior behavior = CommandBehavior.Default) { AssertExecutionStart(); try { SendPacket(new NormalPacket(BuildCommandTokens(command, behavior))); var doneHandler = new DoneTokenHandler(); var messageHandler = new MessageTokenHandler(EventNotifier); var dataReaderHandler = readerSource != null ? new DataReaderTokenHandler() : null; ReceiveTokens( new EnvChangeTokenHandler(_environment), messageHandler, dataReaderHandler, new ResponseParameterTokenHandler(command.AseParameters), doneHandler); AssertExecutionCompletion(doneHandler); if (transaction != null && doneHandler.TransactionState == TranState.TDS_TRAN_ABORT) { transaction.MarkAborted(); } messageHandler.AssertNoErrors(); if (doneHandler.Canceled) { rowsAffectedSource?.SetCanceled(); readerSource?.SetCanceled(); } else { rowsAffectedSource?.SetResult(doneHandler.RowsAffected); readerSource?.SetResult(new AseDataReader(dataReaderHandler.Results(), command, behavior)); } } catch (Exception ex) { rowsAffectedSource?.SetException(ex); readerSource?.SetException(ex); } }
private void InternalExecuteQueryAsync(AseCommand command, AseTransaction transaction, TaskCompletionSource <DbDataReader> readerSource, CommandBehavior behavior) { AssertExecutionStart(); #if ENABLE_SYSTEM_DATA_COMMON_EXTENSIONS var dataReader = new AseDataReader(command, behavior, EventNotifier); #else var dataReader = new AseDataReader(behavior, EventNotifier); #endif try { SendPacket(new NormalPacket(BuildCommandTokens(command, behavior))); var envChangeTokenHandler = new EnvChangeTokenHandler(_environment, _parameters.Charset); var doneHandler = new DoneTokenHandler(); var dataReaderHandler = new StreamingDataReaderTokenHandler(readerSource, dataReader, EventNotifier); var responseParameterTokenHandler = new ResponseParameterTokenHandler(command.AseParameters); Logger.Instance?.WriteLine(); Logger.Instance?.WriteLine("---------- Receive Tokens ----------"); try { #if ENABLE_ARRAY_POOL using (var tokenStream = new TokenReceiveStream(_networkStream, _environment, _arrayPool)) #else using (var tokenStream = new TokenReceiveStream(_networkStream, _environment)) #endif { foreach (var receivedToken in _reader.Read(tokenStream, _environment)) { if (envChangeTokenHandler.CanHandle(receivedToken.Type)) { envChangeTokenHandler.Handle(receivedToken); } if (doneHandler.CanHandle(receivedToken.Type)) { doneHandler.Handle(receivedToken); } if (dataReaderHandler.CanHandle(receivedToken.Type)) { dataReaderHandler.Handle(receivedToken); } if (responseParameterTokenHandler.CanHandle(receivedToken.Type)) { responseParameterTokenHandler.Handle(receivedToken); } } } } finally { LastActive = DateTime.UtcNow; } // This tells the data reader to stop waiting for more results. dataReader.CompleteAdding(); AssertExecutionCompletion(doneHandler); if (transaction != null && doneHandler.TransactionState == TranState.TDS_TRAN_ABORT) { transaction.MarkAborted(); } dataReaderHandler.AssertNoErrors(); if (doneHandler.Canceled) { readerSource.TrySetCanceled(); // If we have already begun returning data, then this will get lost. } else { readerSource.TrySetResult(dataReader); // Catchall - covers cases where no data is returned by the server. } } catch (Exception ex) { // If we have already begun returning data, then this will get lost. if (!readerSource.TrySetException(ex)) { throw; } } }
private void InternalExecuteQueryAsync(AseCommand command, AseTransaction transaction, TaskCompletionSource <DbDataReader> readerSource, CommandBehavior behavior, ReaderSourceType readerSourceType = ReaderSourceType.Standard) { AssertExecutionStart(); try { SendPacket(new NormalPacket(BuildCommandTokens(command, behavior))); var envChangeTokenHandler = new EnvChangeTokenHandler(_environment, _parameters.Charset); var doneHandler = new DoneTokenHandler(); var messageHandler = new MessageTokenHandler(EventNotifier); // Only one of these two data readers will not be null var dataReaderHandler = readerSourceType == ReaderSourceType.Standard ? new DataReaderTokenHandler() : null; var dataReaderEventHandler = readerSourceType == ReaderSourceType.ForCallback ? new DataReaderCallbackTokenHandler(behavior, EventNotifier) : null; var responseParameterTokenHandler = new ResponseParameterTokenHandler(command.AseParameters); if (readerSourceType == ReaderSourceType.ForCallback) { ReceivePartialTokens( envChangeTokenHandler, doneHandler, messageHandler, dataReaderEventHandler, responseParameterTokenHandler); } else { ReceiveTokens( envChangeTokenHandler, doneHandler, messageHandler, dataReaderHandler, responseParameterTokenHandler); } AssertExecutionCompletion(doneHandler); if (transaction != null && doneHandler.TransactionState == TranState.TDS_TRAN_ABORT) { transaction.MarkAborted(); } messageHandler.AssertNoErrors(); if (doneHandler.Canceled) { readerSource.TrySetCanceled(); // If we have already begun returning data, then this will get lost. } else { if (dataReaderHandler != null) #if ENABLE_SYSTEM_DATA_COMMON_EXTENSIONS { readerSource.TrySetResult(new AseDataReader(dataReaderHandler.Results(), command, behavior)); } #else { readerSource.TrySetResult(new AseDataReader(dataReaderHandler.Results(), behavior)); } #endif else if (dataReaderEventHandler != null) { // Set this so that Task.Wait will stop waiting readerSource.SetResult(null); } }