Beispiel #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);
            }
        }
    }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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();
            }
        }