internal void Initialize(
            string providerManifestToken,
            DbProviderServices providerServices,
            Type[] columnTypes,
            bool[] nullableColumns)
        {
            DbDataReader underlyingReader = this._underlyingReader;

            if (underlyingReader == null)
            {
                return;
            }
            this._underlyingReader = (DbDataReader)null;
            try
            {
                if (columnTypes != null && underlyingReader.GetType().Name != "SqlDataReader")
                {
                    this._bufferedDataRecords.Add(ShapedBufferedDataRecord.Initialize(providerManifestToken, providerServices, underlyingReader, columnTypes, nullableColumns));
                }
                else
                {
                    this._bufferedDataRecords.Add((BufferedDataRecord)ShapelessBufferedDataRecord.Initialize(providerManifestToken, providerServices, underlyingReader));
                }
                while (underlyingReader.NextResult())
                {
                    this._bufferedDataRecords.Add((BufferedDataRecord)ShapelessBufferedDataRecord.Initialize(providerManifestToken, providerServices, underlyingReader));
                }
                this._recordsAffected  = underlyingReader.RecordsAffected;
                this._currentResultSet = this._bufferedDataRecords[this._currentResultSetNumber];
            }
            finally
            {
                underlyingReader.Dispose();
            }
        }
 public void InitializeAsync_throws_OperationCanceledException_if_task_is_cancelled()
 {
     Assert.Throws <OperationCanceledException>(
         () => ShapedBufferedDataRecord.InitializeAsync(
             "manifestToken", new Mock <DbProviderServices>().Object,
             new Mock <DbDataReader>().Object, new Type[0], new bool[0], new CancellationToken(canceled: true))
         .GetAwaiter().GetResult());
 }
        internal async Task InitializeAsync(
            string providerManifestToken, DbProviderServices providerSerivces, Type[] columnTypes, bool[] nullableColumns,
            CancellationToken cancellationToken)
        {
            if (_underlyingReader == null)
            {
                return;
            }

            cancellationToken.ThrowIfCancellationRequested();

            var reader = _underlyingReader;

            _underlyingReader = null;

            try
            {
                if (columnTypes != null && reader.GetType().Name != "SqlDataReader")
                {
                    _bufferedDataRecords.Add(await
                                             ShapedBufferedDataRecord.InitializeAsync(
                                                 providerManifestToken, providerSerivces, reader, columnTypes, nullableColumns, cancellationToken)
                                             .ConfigureAwait(continueOnCapturedContext: false));
                }
                else
                {
                    _bufferedDataRecords.Add(await
                                             ShapelessBufferedDataRecord.InitializeAsync(providerManifestToken, providerSerivces, reader, cancellationToken)
                                             .ConfigureAwait(continueOnCapturedContext: false));
                }

                while (await reader.NextResultAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
                {
                    _bufferedDataRecords.Add(await
                                             ShapelessBufferedDataRecord.InitializeAsync(providerManifestToken, providerSerivces, reader, cancellationToken)
                                             .ConfigureAwait(continueOnCapturedContext: false));
                }

                _recordsAffected  = reader.RecordsAffected;
                _currentResultSet = _bufferedDataRecords[_currentResultSetNumber];
            }
            finally
            {
                reader.Dispose();
            }
        }
Example #4
0
        internal static BufferedDataRecord Initialize(
            string providerManifestToken, DbProviderServices providerServices, DbDataReader reader, Type[] columnTypes,
            bool[] nullableColumns)
        {
            var record = new ShapedBufferedDataRecord();

            record.ReadMetadata(providerManifestToken, providerServices, reader);

            DbSpatialDataReader spatialDataReader = null;

            if (columnTypes.Any(t => t == typeof(DbGeography) || t == typeof(DbGeometry)))
            {
                spatialDataReader = providerServices.GetSpatialDataReader(reader, providerManifestToken);
            }

            return(record.Initialize(reader, spatialDataReader, columnTypes, nullableColumns));
        }
        internal async Task InitializeAsync(
            string providerManifestToken,
            DbProviderServices providerSerivces,
            Type[] columnTypes,
            bool[] nullableColumns,
            CancellationToken cancellationToken)
        {
            if (this._underlyingReader == null)
            {
                return;
            }
            cancellationToken.ThrowIfCancellationRequested();
            DbDataReader reader = this._underlyingReader;

            this._underlyingReader = (DbDataReader)null;
            try
            {
                if (columnTypes != null && reader.GetType().Name != "SqlDataReader")
                {
                    this._bufferedDataRecords.Add(await ShapedBufferedDataRecord.InitializeAsync(providerManifestToken, providerSerivces, reader, columnTypes, nullableColumns, cancellationToken).WithCurrentCulture <BufferedDataRecord>());
                }
                else
                {
                    this._bufferedDataRecords.Add((BufferedDataRecord)await ShapelessBufferedDataRecord.InitializeAsync(providerManifestToken, providerSerivces, reader, cancellationToken).WithCurrentCulture <ShapelessBufferedDataRecord>());
                }
                while (true)
                {
                    if (await reader.NextResultAsync(cancellationToken).WithCurrentCulture <bool>())
                    {
                        this._bufferedDataRecords.Add((BufferedDataRecord)await ShapelessBufferedDataRecord.InitializeAsync(providerManifestToken, providerSerivces, reader, cancellationToken).WithCurrentCulture <ShapelessBufferedDataRecord>());
                    }
                    else
                    {
                        break;
                    }
                }
                this._recordsAffected  = reader.RecordsAffected;
                this._currentResultSet = this._bufferedDataRecords[this._currentResultSetNumber];
            }
            finally
            {
                reader.Dispose();
            }
        }
Example #6
0
        internal static Task <BufferedDataRecord> InitializeAsync(
            string providerManifestToken, DbProviderServices providerServices, DbDataReader reader, Type[] columnTypes,
            bool[] nullableColumns, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var record = new ShapedBufferedDataRecord();

            record.ReadMetadata(providerManifestToken, providerServices, reader);

            DbSpatialDataReader spatialDataReader = null;

            if (columnTypes.Any(t => t == typeof(DbGeography) || t == typeof(DbGeometry)))
            {
                spatialDataReader = providerServices.GetSpatialDataReader(reader, providerManifestToken);
            }

            return(record.InitializeAsync(reader, spatialDataReader, columnTypes, nullableColumns, cancellationToken));
        }
        internal void Initialize(
            string providerManifestToken, DbProviderServices providerServices, Type[] columnTypes, bool[] nullableColumns)
        {
            var reader = _underlyingReader;

            if (reader == null)
            {
                return;
            }
            _underlyingReader = null;

            try
            {
                if (columnTypes != null && reader.GetType().Name != "SqlDataReader")
                {
                    _bufferedDataRecords.Add(
                        ShapedBufferedDataRecord.Initialize(providerManifestToken, providerServices, reader, columnTypes, nullableColumns));
                }
                else
                {
                    _bufferedDataRecords.Add(ShapelessBufferedDataRecord.Initialize(providerManifestToken, providerServices, reader));
                }

                while (reader.NextResult())
                {
                    _bufferedDataRecords.Add(ShapelessBufferedDataRecord.Initialize(providerManifestToken, providerServices, reader));
                }

                _recordsAffected  = reader.RecordsAffected;
                _currentResultSet = _bufferedDataRecords[_currentResultSetNumber];
            }
            finally
            {
                reader.Dispose();
            }
        }
        public void InitializeAsync_throws_OperationCanceledException_if_task_is_cancelled_during_initialization_when_reading_rows()
        {
            var tokenSource   = new CancellationTokenSource();
            var taskCancelled = false;

            var mockDataReader = new Mock <DbDataReader>();

            mockDataReader
            .Setup(r => r.ReadAsync(It.IsAny <CancellationToken>()))
            .Returns(
                (CancellationToken token) =>
            {
                Assert.False(taskCancelled);
                tokenSource.Cancel();
                taskCancelled = true;
                return(Task.FromResult(true));
            });

            Assert.Throws <OperationCanceledException>(
                () => ShapedBufferedDataRecord.InitializeAsync(
                    "manifestToken", new Mock <DbProviderServices>().Object,
                    mockDataReader.Object, new Type[0], new bool[0], tokenSource.Token)
                .GetAwaiter().GetResult());
        }