コード例 #1
0
    public async Task <FbBatchNonQueryResult> ExecuteNonQueryAsync(CancellationToken cancellationToken = default)
    {
        CheckCommand();

        FbBatchNonQueryResult result;

        using (var explicitCancellation = ExplicitCancellation.Enter(cancellationToken, Cancel))
        {
            try
            {
                result = await ExecuteCommandAsync(false, explicitCancellation.CancellationToken).ConfigureAwait(false);

                //if (_statement.StatementType == DbStatementType.StoredProcedure)
                //{
                //	await SetOutputParametersAsync(explicitCancellation.CancellationToken).ConfigureAwait(false);
                //}

                await CommitImplicitTransactionAsync(explicitCancellation.CancellationToken).ConfigureAwait(false);
            }
            catch (IscException ex)
            {
                await RollbackImplicitTransactionAsync(explicitCancellation.CancellationToken).ConfigureAwait(false);

                throw FbException.Create(ex);
            }
            catch
            {
                await RollbackImplicitTransactionAsync(explicitCancellation.CancellationToken).ConfigureAwait(false);

                throw;
            }
        }

        return(result);
    }
コード例 #2
0
        public void TestCancellation()
        {
            var sut = new ExplicitCancellation();
            var cts = new CancellationTokenSource();
            var cancellationToken = cts.Token;

            var numbers   = new int[] { 1, 2, 3, 4 };
            var source    = sut.Generate(cancellationToken, numbers);
            var sequence1 = sut.Squre(source, cancellationToken);
            var sequence2 = sut.Squre(source, cancellationToken);
            var merged    = sut.FanIn(cancellationToken, sequence1, sequence2);

            // pass a CancellationToken to the enumerator.
            var sequence = merged.GetConsumingEnumerable(cancellationToken);
            // consumes first one.
            var value = sequence.FirstOrDefault();

            Assert.True(value > 0);

            // Cancellation is not a synchronized operation.
            cts.Cancel();

            // An OperationCancelledException will be thrown when get next item from the collection.
            Assert.Throws <OperationCanceledException>(() => sequence.FirstOrDefault());
        }
コード例 #3
0
    public FbBatchNonQueryResult ExecuteNonQuery()
    {
        CheckCommand();

        FbBatchNonQueryResult result;

        using (var explicitCancellation = ExplicitCancellation.Enter(CancellationToken.None, Cancel))
        {
            try
            {
                result = ExecuteCommand(false);

                //if (_statement.StatementType == DbStatementType.StoredProcedure)
                //{
                //	SetOutputParameters();
                //}

                CommitImplicitTransaction();
            }
            catch (IscException ex)
            {
                RollbackImplicitTransaction();
                throw FbException.Create(ex);
            }
            catch
            {
                RollbackImplicitTransaction();
                throw;
            }
        }

        return(result);
    }
コード例 #4
0
        public override async Task <bool> ReadAsync(CancellationToken cancellationToken)
        {
            CheckState();

            if (IsCommandBehavior(CommandBehavior.SchemaOnly))
            {
                return(false);
            }
            else if (IsCommandBehavior(CommandBehavior.SingleRow) && _position != StartPosition)
            {
                return(false);
            }
            else
            {
                using (var explicitCancellation = ExplicitCancellation.Enter(cancellationToken, _command.Cancel))
                {
                    _row = await _command.FetchAsync(explicitCancellation.CancellationToken).ConfigureAwait(false);

                    if (_row != null)
                    {
                        _position++;
                        return(true);
                    }
                    else
                    {
                        _eof = true;
                        return(false);
                    }
                }
            }
        }
コード例 #5
0
        public override bool Read()
        {
            CheckState();

            if (IsCommandBehavior(CommandBehavior.SchemaOnly))
            {
                return(false);
            }
            else if (IsCommandBehavior(CommandBehavior.SingleRow) && _position != StartPosition)
            {
                return(false);
            }
            else
            {
                using (var explicitCancellation = ExplicitCancellation.Enter(CancellationToken.None, _command.Cancel))
                {
                    _row = _command.Fetch();
                    if (_row != null)
                    {
                        _position++;
                        return(true);
                    }
                    else
                    {
                        _eof = true;
                        return(false);
                    }
                }
            }
        }
コード例 #6
0
    public void Prepare()
    {
        CheckCommand();

        using (var explicitCancellation = ExplicitCancellation.Enter(CancellationToken.None, Cancel))
        {
            try
            {
                Prepare(false);
            }
            catch (IscException ex)
            {
                RollbackImplicitTransaction();
                throw FbException.Create(ex);
            }
            catch
            {
                RollbackImplicitTransaction();
                throw;
            }
        }
    }
コード例 #7
0
    public async Task PrepareAsync(CancellationToken cancellationToken = default)
    {
        CheckCommand();

        using (var explicitCancellation = ExplicitCancellation.Enter(cancellationToken, Cancel))
        {
            try
            {
                await PrepareAsync(false, explicitCancellation.CancellationToken).ConfigureAwait(false);
            }
            catch (IscException ex)
            {
                await RollbackImplicitTransactionAsync(explicitCancellation.CancellationToken).ConfigureAwait(false);

                throw FbException.Create(ex);
            }
            catch
            {
                await RollbackImplicitTransactionAsync(explicitCancellation.CancellationToken).ConfigureAwait(false);

                throw;
            }
        }
    }
コード例 #8
0
        public void TestCancellation_during_enumerating()
        {
            var sut = new ExplicitCancellation();
            var cts = new CancellationTokenSource();
            var cancellationToken = cts.Token;

            var numbers   = new int[] { 1, 2, 3, 4 };
            var source    = sut.Generate(cancellationToken, numbers);
            var sequence1 = sut.Squre(source, cancellationToken);
            var sequence2 = sut.Squre(source, cancellationToken);
            var merged    = sut.FanIn(cancellationToken, sequence1, sequence2);

            var sequence = merged.GetConsumingEnumerable(cancellationToken);

            Assert.Throws <OperationCanceledException>(() =>
            {
                foreach (var n in sequence)
                {
                    // cancel at the first iteration.
                    cts.Cancel();
                    // It will be thrown at the next iteration.
                }
            });
        }