protected virtual void Dispose(bool disposing)
        {
            bool wasSucceeded = ScopeStatusManager.WasSucceeded();

            foreach (DbConnectionAndTransactionPair dbAndTran in DbConnectionAndTransactions)
            {
                try
                {
                    if (dbAndTran.RollbackOnScopeStatusFailure == false)
                    {
                        dbAndTran.Transaction?.Commit();
                    }
                    else
                    {
                        if (wasSucceeded)
                        {
                            dbAndTran.Transaction?.Commit();
                        }
                        else
                        {
                            dbAndTran.Transaction?.Rollback();
                        }
                    }
                }
                finally
                {
                    dbAndTran.Transaction?.Dispose();
                    dbAndTran.Connection.Dispose();
                }
            }
        }
Example #2
0
        public virtual async Task AuthenticateLocalAsync(LocalAuthenticationContext context, CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            try
            {
                if (context.AuthenticateResult == null)
                {
                    BitJwtToken bitJwtToken = await LocalLogin(context, cancellationToken).ConfigureAwait(false);

                    AuthenticateResult result = new AuthenticateResult(bitJwtToken.UserId, bitJwtToken.UserId,
                                                                       BuildClaimsFromBitJwtToken(bitJwtToken),
                                                                       authenticationMethod: "custom");

                    context.AuthenticateResult = result;
                }
            }
            catch (Exception ex)
            {
                ScopeStatusManager.MarkAsFailed("LocalLogin_Failed");
                if (context.AuthenticateResult == null && ExceptionToHttpErrorMapper.IsKnownError(ex))
                {
                    context.AuthenticateResult = new AuthenticateResult(ExceptionToHttpErrorMapper.GetMessage(ex));
                }
                else
                {
                    throw;
                }
            }

            await base.AuthenticateLocalAsync(context).ConfigureAwait(false);
        }
Example #3
0
        public async ValueTask DisposeAsync()
        {
            bool wasSucceeded = ScopeStatusManager.WasSucceeded();

            foreach (DbConnectionAndTransactionPair dbAndTran in DbConnectionAndTransactions)
            {
                try
                {
                    if (dbAndTran.RollbackOnScopeStatusFailure == false)
                    {
                        if (dbAndTran.Transaction != null)
                        {
                            await dbAndTran.Transaction.CommitAsync().ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        if (wasSucceeded)
                        {
                            if (dbAndTran.Transaction != null)
                            {
                                await dbAndTran.Transaction.CommitAsync().ConfigureAwait(false);
                            }
                        }
                        else
                        {
                            if (dbAndTran.Transaction != null)
                            {
                                await dbAndTran.Transaction.RollbackAsync().ConfigureAwait(false);
                            }
                        }
                    }
                }
                finally
                {
                    if (dbAndTran.Transaction != null)
                    {
                        await dbAndTran.Transaction.DisposeAsync();
                    }
                    await dbAndTran.Connection.DisposeAsync();
                }
            }
        }