Ejemplo n.º 1
0
 public override void Commit()
 {
     base.Commit();
     _clientSessionHandle.CommitTransaction();
     _clientSessionHandle.Dispose();
     _clientSessionHandle = null;
 }
Ejemplo n.º 2
0
        public void Commit()
        {
            if (_transactionCounter == 1)
            {
                try
                {
                    Transaction.Commit();
                    _mongoSession.CommitTransaction();
                }
                catch
                {
                    Transaction.Rollback();
                    _mongoSession.AbortTransaction();
                    throw;
                }
                finally
                {
                    _connection.Close();
                    Transaction.Dispose();
                    _mongoSession.Dispose();
                }
            }

            _transactionCounter--;
        }
Ejemplo n.º 3
0
        public async void CommitAsync()
        {
            if (_session == null)
            {
                throw new Exception("Session has been gone somehow!");
            }

            await _session.CommitTransactionAsync();

            _session.Dispose();
        }
Ejemplo n.º 4
0
 public void Commit()
 {
     try
     {
         _transactionSession.CommitTransaction();
     }
     finally
     {
         _transactionSession.Dispose();
     }
 }
Ejemplo n.º 5
0
 public void Dispose()
 {
     if (_clientSessionHandle != null)
     {
         _clientSessionHandle.Dispose();
     }
 }
Ejemplo n.º 6
0
 public void Dispose()
 {
     if (_session != null)
     {
         _session.Dispose();
     }
 }
 public void EndSession(IClientSessionHandle session)
 {
     if (!session.IsInTransaction)
     {
         session.Dispose();
     }
 }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         session?.Dispose();
     }
 }
Ejemplo n.º 9
0
 public void Dispose()
 {
     if (!_disposed)
     {
         _transactionSession?.Dispose();
         _disposed = true;
     }
 }
 public override void Dispose()
 {
     if (_session?.IsInTransaction == true)
     {
         _session.AbortTransaction();
     }
     _session?.Dispose();
     base.Dispose();
 }
Ejemplo n.º 11
0
        public void Dispose()
        {
            _session.Dispose();

            if (!_isCompleted)
            {
                _onCompleted(false);
            }
        }
 protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             _transaction?.Dispose();
         }
         disposedValue = true;
     }
 }
Ejemplo n.º 13
0
        public virtual void Dispose()
        {
            transaction = transactionStack.Pop();
            transaction.Dispose();

            if (transactionStack.Count > 0)
            {
                transaction = transactionStack.First();
                return;
            }
        }
Ejemplo n.º 14
0
        public async Task ApplyChangesAsync(CancellationToken token = default)
        {
            if (_operations.Count > 0)
            {
                IClientSessionHandle session = null;
                if (_connection.UseTransactions)
                {
                    session = _connection.StartSession();
                    session.StartTransaction();
                }

                try
                {
                    while (_operations.Count > 0)
                    {
                        var item = _operations.Dequeue();
                        await item.ProcessAsync(session, token);
                    }

                    if (session != null)
                    {
                        await session.CommitTransactionAsync(token);

                        session.Dispose();
                    }

                    _operations.Clear();
                }
                catch
                {
                    if (session != null)
                    {
                        await session.AbortTransactionAsync(token);

                        session.Dispose();
                    }

                    throw;
                }
            }
        }
Ejemplo n.º 15
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         session?.Dispose();
     }
     catch
     {
         //No need to throw on disposal
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 16
0
        public void Dispose()
        {
            if (null != session)
            {
                if (session.IsInTransaction)
                {
                    session.AbortTransaction();
                }

                session.Dispose();
            }
        }
Ejemplo n.º 17
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _mongoClient = null;
            _clientSessionHandle?.Dispose();
            _clientSessionHandle = null;

            base.Dispose(disposing);
        }
Ejemplo n.º 18
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing && _dispose)
            {
                _Session.Dispose();
            }

            _disposed = true;
        }
Ejemplo n.º 19
0
        private static async Task CommitOrAbortTx(IClientSessionHandle session, AppendResult result)
        {
            if (session != null)
            {
                if (result.HadWrongVersion || string.IsNullOrWhiteSpace(result.CommitId) || result.CurrentVersion <= 0)
                {
                    await session.AbortTransactionAsync();
                }
                else
                {
                    await session.CommitTransactionAsync();
                }

                session.Dispose();
            }
        }
Ejemplo n.º 20
0
        public async Task CommitAsync()
        {
            _mongoDbSession = await _eventStoreContext.Client.StartSessionAsync();

            _mongoDbSession.StartTransaction();

            var insertToESTasks = new List <Task>();

            foreach (var eventTransaction in _transactions)
            {
                insertToESTasks.Add(InsertEventsToESAsync(eventTransaction.Value, eventTransaction.Key));
            }

            await Task.WhenAll(insertToESTasks);

            await _mongoDbSession.CommitTransactionAsync();

            _mongoDbSession.Dispose();
        }
Ejemplo n.º 21
0
        private async Task ExecuteWithClientSession(IMongoCollection <T> collection, IClientSessionHandle session,
                                                    Func <IClientSessionHandle, Task> action)
        {
            var closeSession = false;

            if (session == null)
            {
                session      = collection.Database.Client.StartSession();
                closeSession = true;
            }

            try
            {
                await action(session);
            }
            finally
            {
                if (closeSession)
                {
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 22
0
        public async Task <int> SaveChangesAsync()
        {
            int count = _commands.Count;
            CancellationToken token = new CancellationToken();

            using (Session = await MongoClient.StartSessionAsync(options: null, cancellationToken: token))
            {
                Session.StartTransaction();

                var commandTasks = _commands.Select(c => c());

                await Task.WhenAll(commandTasks);

                //await Session.AbortTransactionAsync(token);

                await Session.CommitTransactionAsync();

                _commands.Clear();
                Session.Dispose();
                Session = null;
            }

            return(count);
        }
Ejemplo n.º 23
0
 public void Dispose()
 {
     _clientSessionHandle.Dispose();
 }
 public void Dispose()
 {
     _session?.Dispose();
 }
Ejemplo n.º 25
0
 public void Dispose()
 {
     mongoSession.Dispose();
 }
Ejemplo n.º 26
0
 public void Execute()
 {
     _session.Dispose();
 }
Ejemplo n.º 27
0
    public async Task HandleAsync(string messageId, Func <Task> handler)
    {
        if (!Enabled)
        {
            _logger.LogWarning("Outbox is disabled, incoming messages won't be processed.");
            return;
        }

        if (string.IsNullOrWhiteSpace(messageId))
        {
            throw new ArgumentException("Message id to be processed cannot be empty.", nameof(messageId));
        }

        _logger.LogTrace($"Received a message with id: '{messageId}' to be processed.");
        if (await _inboxRepository.ExistsAsync(m => m.Id == messageId))
        {
            _logger.LogTrace($"Message with id: '{messageId}' was already processed.");
            return;
        }

        IClientSessionHandle session = null;

        if (_transactionsEnabled)
        {
            session = await _sessionFactory.CreateAsync();

            session.StartTransaction();
        }

        try
        {
            _logger.LogTrace($"Processing a message with id: '{messageId}'...");
            await handler();

            await _inboxRepository.AddAsync(new InboxMessage
            {
                Id          = messageId,
                ProcessedAt = DateTime.UtcNow
            });

            if (session is not null)
            {
                await session.CommitTransactionAsync();
            }

            _logger.LogTrace($"Processed a message with id: '{messageId}'.");
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, $"There was an error when processing a message with id: '{messageId}'.");
            if (session is not null)
            {
                await session.AbortTransactionAsync();
            }

            throw;
        }
        finally
        {
            session?.Dispose();
        }
    }
Ejemplo n.º 28
0
 public void Dispose()
 => _session.Dispose();
Ejemplo n.º 29
0
 public void Dispose()
 {
     session.Dispose();
 }
Ejemplo n.º 30
0
 public void Dispose()
 {
     _session?.Dispose();
     GC.SuppressFinalize(this);
 }