示例#1
0
    public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
    {
        if (context.HandlerMethod == null || !context.ActionDescriptor.IsPageAction())
        {
            await next();

            return;
        }

        var methodInfo     = context.HandlerMethod.MethodInfo;
        var unitOfWorkAttr = UnitOfWorkHelper.GetUnitOfWorkAttributeOrNull(methodInfo);

        context.HttpContext.Items["_AbpActionInfo"] = new AbpActionInfoInHttpContext
        {
            IsObjectResult = ActionResultHelper.IsObjectResult(context.HandlerMethod.MethodInfo.ReturnType, typeof(void))
        };

        if (unitOfWorkAttr?.IsDisabled == true)
        {
            await next();

            return;
        }

        var options = CreateOptions(context, unitOfWorkAttr);

        var unitOfWorkManager = context.GetRequiredService <IUnitOfWorkManager>();

        //Trying to begin a reserved UOW by AbpUnitOfWorkMiddleware
        if (unitOfWorkManager.TryBeginReserved(UnitOfWork.UnitOfWorkReservationName, options))
        {
            var result = await next();

            if (Succeed(result))
            {
                await SaveChangesAsync(context, unitOfWorkManager);
            }
            else
            {
                await RollbackAsync(context, unitOfWorkManager);
            }

            return;
        }

        using (var uow = unitOfWorkManager.Begin(options))
        {
            var result = await next();

            if (Succeed(result))
            {
                await uow.CompleteAsync(context.HttpContext.RequestAborted);
            }
            else
            {
                await uow.RollbackAsync(context.HttpContext.RequestAborted);
            }
        }
    }
示例#2
0
        private bool ShouldSaveAudit(PageHandlerExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;

            var options = context.GetRequiredService <IOptions <AbpAuditingOptions> >().Value;

            if (!options.IsEnabled)
            {
                return(false);
            }

            if (!context.ActionDescriptor.IsPageAction())
            {
                return(false);
            }

            var auditLogScope = context.GetRequiredService <IAuditingManager>().Current;

            if (auditLogScope == null)
            {
                return(false);
            }

            var auditingHelper = context.GetRequiredService <IAuditingHelper>();

            if (!auditingHelper.ShouldSaveAudit(context.HandlerMethod.MethodInfo, true))
            {
                return(false);
            }

            auditLog       = auditLogScope.Log;
            auditLogAction = auditingHelper.CreateAuditLogAction(
                auditLog,
                context.HandlerMethod.MethodInfo.DeclaringType,
                context.HandlerMethod.MethodInfo,
                context.HandlerArguments
                );

            return(true);
        }
示例#3
0
        private AbpUnitOfWorkOptions CreateOptions(PageHandlerExecutingContext context, UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var options = new AbpUnitOfWorkOptions();

            unitOfWorkAttribute?.SetOptions(options);

            if (unitOfWorkAttribute?.IsTransactional == null)
            {
                var abpUnitOfWorkDefaultOptions = context.GetRequiredService <IOptions <AbpUnitOfWorkDefaultOptions> >().Value;
                options.IsTransactional = abpUnitOfWorkDefaultOptions.CalculateIsTransactional(
                    autoValue: !string.Equals(context.HttpContext.Request.Method, HttpMethod.Get.Method, StringComparison.OrdinalIgnoreCase)
                    );
            }

            return(options);
        }
示例#4
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            if (context.HandlerMethod == null || !context.ActionDescriptor.IsPageAction())
            {
                await next();

                return;
            }

            var methodInfo = context.HandlerMethod.MethodInfo;

            using (AbpCrossCuttingConcerns.Applying(context.HandlerInstance, AbpCrossCuttingConcerns.FeatureChecking))
            {
                var methodInvocationFeatureCheckerService = context.GetRequiredService <IMethodInvocationFeatureCheckerService>();
                await methodInvocationFeatureCheckerService.CheckAsync(new MethodInvocationFeatureCheckerContext(methodInfo));

                await next();
            }
        }