public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (!UnitOfWorkHelper.IsUnitOfWorkMethod(invocation.Method, out var unitOfWorkAttribute))
            {
                await invocation.ProceedAsync();

                return;
            }

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var options = CreateOptions(scope.ServiceProvider, invocation, unitOfWorkAttribute);

                var unitOfWorkManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>();

                //Trying to begin a reserved UOW by AbpUnitOfWorkMiddleware
                if (unitOfWorkManager.TryBeginReserved(UnitOfWork.UnitOfWorkReservationName, options))
                {
                    await invocation.ProceedAsync();

                    return;
                }

                using (var uow = unitOfWorkManager.Begin(options))
                {
                    await invocation.ProceedAsync();

                    await uow.CompleteAsync();
                }
            }
        }
Exemple #2
0
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (!ShouldIntercept(invocation, out var auditLog, out var auditLogAction))
            {
                await invocation.ProceedAsync();

                return;
            }

            var stopwatch = Stopwatch.StartNew();

            try
            {
                await invocation.ProceedAsync();
            }
            catch (Exception ex)
            {
                auditLog.Exceptions.Add(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                auditLogAction.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);
                auditLog.Actions.Add(auditLogAction);
            }
        }
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (!UnitOfWorkHelper.IsUnitOfWorkMethod(invocation.Method, out var unitOfWorkAttribute))
            {
                await invocation.ProceedAsync();

                return;
            }

            var options = CreateOptions(invocation, unitOfWorkAttribute);

            //Trying to begin a reserved UOW by AbpUnitOfWorkMiddleware
            if (_unitOfWorkManager.TryBeginReserved(UnitOfWork.UnitOfWorkReservationName, options))
            {
                await invocation.ProceedAsync();

                return;
            }

            using (var uow = _unitOfWorkManager.Begin(options))
            {
                await invocation.ProceedAsync();

                await uow.CompleteAsync();
            }
        }
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.Authorization))
            {
                await invocation.ProceedAsync();

                return;
            }

            AsyncHelper.RunSync(() => AuthorizeAsync(invocation));
            await invocation.ProceedAsync();
        }
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.Validation))
            {
                await invocation.ProceedAsync();

                return;
            }

            Validate(invocation);

            await invocation.ProceedAsync();
        }
Exemple #6
0
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking))
            {
                await invocation.ProceedAsync().ConfigureAwait(false);

                return;
            }

            await CheckFeaturesAsync(invocation).ConfigureAwait(false);

            await invocation.ProceedAsync().ConfigureAwait(false);
        }
Exemple #7
0
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            using (var serviceScope = _serviceScopeFactory.CreateScope())
            {
                var auditingHelper  = serviceScope.ServiceProvider.GetRequiredService <IAuditingHelper>();
                var auditingOptions = serviceScope.ServiceProvider.GetRequiredService <IOptions <AbpAuditingOptions> >().Value;

                if (!ShouldIntercept(invocation, auditingOptions, auditingHelper))
                {
                    await invocation.ProceedAsync();

                    return;
                }

                var auditingManager = serviceScope.ServiceProvider.GetRequiredService <IAuditingManager>();
                if (auditingManager.Current != null)
                {
                    await ProceedByLoggingAsync(invocation, auditingHelper, auditingManager.Current);
                }
                else
                {
                    var currentUser = serviceScope.ServiceProvider.GetRequiredService <ICurrentUser>();
                    await ProcessWithNewAuditingScopeAsync(invocation, auditingOptions, currentUser, auditingManager, auditingHelper);
                }
            }
        }
Exemple #8
0
        private static async Task ProceedByLoggingAsync(
            IAbpMethodInvocation invocation,
            IAuditingHelper auditingHelper,
            IAuditLogScope auditLogScope)
        {
            var auditLog       = auditLogScope.Log;
            var auditLogAction = auditingHelper.CreateAuditLogAction(
                auditLog,
                invocation.TargetObject.GetType(),
                invocation.Method,
                invocation.Arguments
                );

            var stopwatch = Stopwatch.StartNew();

            try
            {
                await invocation.ProceedAsync();
            }
            catch (Exception ex)
            {
                auditLog.Exceptions.Add(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                auditLogAction.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);
                auditLog.Actions.Add(auditLogAction);
            }
        }
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            Console.WriteLine("in the aloha interceptor");
            await invocation.ProceedAsync();

            Console.WriteLine("out of aloha interceptor");
        }
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (!UnitOfWorkHelper.IsUnitOfWorkMethod(invocation.Method, out var unitOfWorkAttribute))
            {
                await invocation.ProceedAsync();

                return;
            }

            using (var uow = _unitOfWorkManager.Begin(CreateOptions(invocation, unitOfWorkAttribute)))
            {
                await invocation.ProceedAsync();

                await uow.CompleteAsync();
            }
        }
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            _logger.LogTrace($"{invocation.Method.Name} Executing ...");

            await invocation.ProceedAsync();

            _logger.LogTrace($"{invocation.Method.Name} Executed ...");
        }
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            //await Task.Delay(5); CAN NOT USE await before method execution! This is a restriction of Castle DynamicProxy
            (invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_InterceptAsync_BeforeInvocation");
            await invocation.ProceedAsync();

            (invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_InterceptAsync_AfterInvocation");
            await Task.Delay(5);
        }
Exemple #13
0
    public override async Task InterceptAsync(IAbpMethodInvocation invocation)
    {
        if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.GlobalFeatureChecking))
        {
            await invocation.ProceedAsync();

            return;
        }

        if (!GlobalFeatureHelper.IsGlobalFeatureEnabled(invocation.TargetObject.GetType(), out var attribute))
        {
            throw new AbpGlobalFeatureNotEnabledException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
                  .WithData("ServiceName", invocation.TargetObject.GetType().FullName)
                  .WithData("GlobalFeatureName", attribute.Name);
        }

        await invocation.ProceedAsync();
    }
Exemple #14
0
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            var profiler = StackExchange.Profiling.MiniProfiler.Current;

            using (profiler.Step(invocation.Method.Name))
            {
                // Do some work...
                await invocation.ProceedAsync();
            }
        }
    public override async Task InterceptAsync(IAbpMethodInvocation invocation)
    {
        await Task.Delay(5);

        (invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_InterceptAsync_BeforeInvocation");
        await invocation.ProceedAsync();

        (invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_InterceptAsync_AfterInvocation");
        await Task.Delay(5);
    }
Exemple #16
0
    public override async Task InterceptAsync(IAbpMethodInvocation invocation)
    {
        if (_cache.ContainsKey(invocation.Method))
        {
            invocation.ReturnValue = _cache[invocation.Method];
            return;
        }

        await invocation.ProceedAsync();

        _cache[invocation.Method] = invocation.ReturnValue;
    }
Exemple #17
0
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            var entityObj = invocation.Arguments.First();

            // TODO: 针对实体的变更执行一次定义的规则
            // IBasicRepository.InsertAsync || IBasicRepository.UpdateAsync || IBasicRepository.DeleteAsync
            if (entityObj != null && entityObj is IEntity entity)
            {
                await ApplyEntityRuleAsync(entity);
            }

            await invocation.ProceedAsync();
        }
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking))
            {
                await invocation.ProceedAsync();

                return;
            }

            var limitFeature = GetRequiresLimitFeature(invocation.Method);

            if (limitFeature == null)
            {
                await invocation.ProceedAsync();

                return;
            }

            // 获取功能限制上限
            var limit = await _featureChecker.GetAsync(limitFeature.LimitFeature, limitFeature.DefaultLimit);

            // 获取功能限制时长
            var interval = await _featureChecker.GetAsync(limitFeature.IntervalFeature, limitFeature.DefaultInterval);

            // 必要的上下文参数
            var limitFeatureContext = new RequiresLimitFeatureContext(limitFeature.LimitFeature, _options, limitFeature.Policy, interval, limit);

            // 检查次数限制
            await PreCheckFeatureAsync(limitFeatureContext);

            // 执行代理方法
            await invocation.ProceedAsync();

            // 调用次数递增
            // TODO: 使用Redis结合Lua脚本?
            await PostCheckFeatureAsync(limitFeatureContext);
        }
Exemple #19
0
 public async Task InterceptAsync(IAbpMethodInvocation invocation)
 {
     await invocation.ProceedAsync();
 }
Exemple #20
0
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            await AuthorizeAsync(invocation).ConfigureAwait(false);

            await invocation.ProceedAsync().ConfigureAwait(false);
        }
Exemple #21
0
        public async override Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            await AuthorizeAsync(invocation);

            await invocation.ProceedAsync();
        }
 public async override Task InterceptAsync(IAbpMethodInvocation invocation)
 {
     Validate(invocation);
     await invocation.ProceedAsync();
 }
Exemple #23
0
    public override async Task InterceptAsync(IAbpMethodInvocation invocation)
    {
        await ValidateAsync(invocation);

        await invocation.ProceedAsync();
    }
Exemple #24
0
 public override void Intercept(IAbpMethodInvocation invocation)
 {
     (invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_Intercept_BeforeInvocation");
     invocation.ProceedAsync();
     (invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_Intercept_AfterInvocation");
 }