예제 #1
0
        public async Task <IChunk> ReadSingleBackwardAsync(string partitionId, long fromUpperIndexInclusive, CancellationToken cancellationToken)
        {
            using (var connection = Connect())
            {
                await connection.OpenAsync(cancellationToken).ConfigureAwait(false);

                using (var command = new SqlCommand(_options.GetLastChunkScript(), connection))
                {
                    command.Parameters.AddWithValue("@PartitionId", partitionId);
                    command.Parameters.AddWithValue("@toUpperIndexInclusive", fromUpperIndexInclusive);

                    using (var reader = await command.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false))
                    {
                        if (!reader.HasRows)
                        {
                            return(null);
                        }

                        await reader.ReadAsync(cancellationToken).ConfigureAwait(false);

                        var chunk = new MsSqlChunk
                        {
                            Position    = reader.GetInt64(0),
                            PartitionId = reader.GetString(1),
                            Index       = reader.GetInt64(2),
                            Payload     = _options.Serializer.Deserialize(reader.GetString(3)),
                            OperationId = reader.GetString(4),
                            Deleted     = reader.GetBoolean(5)
                        };

                        return(chunk);
                    }
                }
            }
        }
예제 #2
0
        public async Task <IChunk> ReadSingleBackwardAsync(string partitionId, long fromUpperIndexInclusive, CancellationToken cancellationToken)
        {
            using (var connection = Connect())
            {
                await connection.OpenAsync(cancellationToken).ConfigureAwait(false);

                using (var command = new SqlCommand(_options.GetLastChunkScript(), connection))
                {
                    command.Parameters.AddWithValue("@PartitionId", partitionId);
                    command.Parameters.AddWithValue("@toUpperIndexInclusive", fromUpperIndexInclusive);

                    return(await ReadSingleChunk(command, cancellationToken).ConfigureAwait(false));
                }
            }
        }