Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
        {
            if (!_configuration.CacheList.TryGetValue(invocation.TargetMethod, out var pointCut))
            {
                if (!invocation.TargetMethod.DeclaringType.GetTypeInfo().IsGenericType ||
                    !_configuration.DynamicCacheList.TryGetValue(invocation.TargetMethod.GetMethodInfoUniqueName(),
                                                                 out var pointCutDynamic))
                {
                    //该方法不需要拦截
                    await invocation.ProceedAsync();

                    return;
                }

                pointCut = pointCutDynamic;
            }


            var aspectContext = new AspectContext(_component, invocation);

            aspectContext.Proceed = async() =>
            {
                await invocation.ProceedAsync();
            };
            var runTask = pointCut.AspectFunc.Value;

            await runTask(aspectContext);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
        {
            #region 先从缓存里面拿到这个方法时候打了继承AspectInvokeAttribute的标签

            if (!_cache.CacheList.TryGetValue(invocation.TargetMethod, out var attribute))
            {
                //动态泛型类
                if (!invocation.TargetMethod.DeclaringType.GetTypeInfo().IsGenericType ||
                    (!_cache.DynamicCacheList.TryGetValue(invocation.TargetMethod.GetMethodInfoUniqueName(), out var AttributesDynamic)))
                {
                    await invocation.ProceedAsync();

                    return;
                }

                attribute = AttributesDynamic;
            }

            #endregion

            var aspectContext = new AspectContext(_component, invocation);
            aspectContext.Proceed = async() =>
            {
                await invocation.ProceedAsync();
            };

            var runTask = attribute.AspectFunc.Value;
            await runTask(aspectContext);
        }
Пример #3
0
        protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
        {
            await this.task;

            if (this.proceed)
            {
                await invocation.ProceedAsync();
            }
        }
Пример #4
0
        protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
        {
            await invocation.ProceedAsync();

            if (invocation.Result is string)
            {
                invocation.Result = "b";
            }
        }
Пример #5
0
        /// <inheritdoc />
        public async Task InterceptAsync(IAsyncInvocation invocation)
        {
            var freezableClock = _freezableClockFactory();

            freezableClock.FreezeTime();
            await invocation.ProceedAsync();

            freezableClock.UnfreezeTime();
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
        {
            //单例的
            if (_instanceCache.TryGetValue(invocation.TargetMethod, out var instance))
            {
                invocation.Result = instance;
                return;
            }

            await invocation.ProceedAsync();

            _instanceCache.TryAdd(invocation.TargetMethod, invocation.Result);
        }
Пример #7
0
        /// <inheritdoc />
        public async Task InterceptAsync(IAsyncInvocation invocation)
        {
            var retryPolicy = _retryPolicyCoordinator.RequestPolicy();

            await retryPolicy.ExecuteAsync(async() => await invocation.ProceedAsync());
        }
Пример #8
0
 protected override ValueTask InterceptAsync(IAsyncInvocation invocation)
 {
     invocation.Result = this.value;
     return(default);
Пример #9
0
 protected abstract ValueTask InterceptAsync(IAsyncInvocation invocation);
 public AsyncStateMachine(IAsyncInvocation asyncInvocation, object builder, ValueTask task)
 {
     this.asyncInvocation = asyncInvocation;
     this.builder         = builder;
     this.task            = task;
 }
Пример #11
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="context"></param>
 /// <param name="invocation"></param>
 public AspectContext(IComponentContext context, IAsyncInvocation invocation)
 {
     this.ComponentContext       = context;
     this.IAsyncnvocationContext = invocation;
 }
Пример #12
0
 public async Task InterceptAsync(IAsyncInvocation invocation)
 {
     await invocation.ProceedAsync();
 }