Example #1
0
            public Task <Stream> ReadStreamAsync(TKey key, CancellationToken cancellationToken)
            {
                // Note: we're technically fully synchronous.  However, we're called from several
                // async methods.  We just return a Task<stream> here so that all our callers don't
                // need to call Task.FromResult on us.

                cancellationToken.ThrowIfCancellationRequested();

                if (!Storage._shutdownTokenSource.IsCancellationRequested)
                {
                    using (var pooledConnection = Storage.GetPooledConnection())
                    {
                        var connection = pooledConnection.Connection;
                        if (TryGetDatabaseId(connection, key, out var dataId))
                        {
                            // Ensure all pending document writes to this name are flushed to the DB so that
                            // we can find them below.
                            FlushPendingWrites(connection, key);

                            try
                            {
                                // Lookup the row from the DocumentData table corresponding to our dataId.
                                return(Task.FromResult(ReadBlob(connection, dataId)));
                            }
                            catch (Exception ex)
                            {
                                StorageDatabaseLogger.LogException(ex);
                            }
                        }
                    }
                }

                return(SpecializedTasks.Default <Stream>());
            }
            public async Task <Stream> ReadStreamAsync(TKey key, CancellationToken cancellationToken)
            {
                // Note: we're technically fully synchronous.  However, we're called from several
                // async methods.  We just return a Task<stream> here so that all our callers don't
                // need to call Task.FromResult on us.

                cancellationToken.ThrowIfCancellationRequested();

                if (!Storage._shutdownTokenSource.IsCancellationRequested)
                {
                    bool        haveDataId;
                    TDatabaseId dataId;
                    using (var pooledConnection = Storage.GetPooledConnection())
                    {
                        haveDataId = TryGetDatabaseId(pooledConnection.Connection, key, out dataId);
                    }

                    if (haveDataId)
                    {
                        // Ensure all pending document writes to this name are flushed to the DB so that
                        // we can find them below.
                        await FlushPendingWritesAsync(key, cancellationToken).ConfigureAwait(false);

                        try
                        {
                            using (var pooledConnection = Storage.GetPooledConnection())
                            {
                                // Lookup the row from the DocumentData table corresponding to our dataId.
                                return(ReadBlob(pooledConnection.Connection, dataId));
                            }
                        }
                        catch (Exception ex)
                        {
                            StorageDatabaseLogger.LogException(ex);
                        }
                    }
                }

                return(null);
            }
            private async Task <Stream> ReadBlobColumnAsync(
                TKey key, string columnName, Checksum checksumOpt, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (!Storage._shutdownTokenSource.IsCancellationRequested)
                {
                    bool        haveDataId;
                    TDatabaseId dataId;
                    using (var pooledConnection = Storage.GetPooledConnection())
                    {
                        haveDataId = TryGetDatabaseId(pooledConnection.Connection, key, out dataId);
                    }

                    if (haveDataId)
                    {
                        // Ensure all pending document writes to this name are flushed to the DB so that
                        // we can find them below.
                        await FlushPendingWritesAsync(key, cancellationToken).ConfigureAwait(false);

                        try
                        {
                            using (var pooledConnection = Storage.GetPooledConnection())
                            {
                                // Lookup the row from the DocumentData table corresponding to our dataId.
                                return(ReadBlob(
                                           pooledConnection.Connection, dataId, columnName,
                                           checksumOpt, cancellationToken));
                            }
                        }
                        catch (Exception ex)
                        {
                            StorageDatabaseLogger.LogException(ex);
                        }
                    }
                }

                return(null);
            }