public override async Task <IServiceResult> Intercept(IInterceptorContext context)
        {
            var service  = ServiceFactory.Get(context.ServiceRoute);
            var instance = context.ServiceProvider.GetRequiredService(service.MethodInfo.DeclaringType);

            return(new ServiceResult(await service.MethodInvoker.Invoke(instance, context.Args)));
        }
Beispiel #2
0
        public override async Task <IServiceResult> Intercept(IInterceptorContext context)
        {
            if (!(context is InterceptorContext ctx))
            {
                throw new ArgumentNullException(nameof(context));
            }
            //No circuit breaker
            if (UraganoSettings.CircuitBreakerOptions == null)
            {
                if (ctx.ReturnType != null)
                {
                    return(new ServiceResult(await Exec(ctx.ServiceName, ctx.ServiceRoute, ctx.Args, ctx.Meta,
                                                        ctx.ReturnType)));
                }
                await Exec(ctx.ServiceName, ctx.ServiceRoute, ctx.Args, ctx.Meta, null);

                return(new ServiceResult(null));
            }
            //Circuit breaker
            if (ctx.ReturnType != null)
            {
                return(new ServiceResult(await CircuitBreaker.ExecuteAsync(ctx.ServiceRoute,
                                                                           async() => await Exec(ctx.ServiceName, ctx.ServiceRoute, ctx.Args, ctx.Meta,
                                                                                                 ctx.ReturnType), ctx.ReturnType)));
            }

            await CircuitBreaker.ExecuteAsync(ctx.ServiceRoute,
                                              async() => { await Exec(ctx.ServiceName, ctx.ServiceRoute, ctx.Args, ctx.Meta, null); });

            return(new ServiceResult(null));
        }
        public override async Task <IServiceResult> Intercept(IInterceptorContext context)
        {
            Logger.LogTrace("\n------------------>Server Interceptor attribute\n");
            var r = await context.Next();

            return(r);
        }
Beispiel #4
0
        public override async Task <IServiceResult> Intercept(IInterceptorContext context)
        {
            var service = ServiceFactory.Get(context.ServiceRoute);

            if (service.CachingConfig == null)
            {
                return(await context.Next());
            }
            var key = KeyGenerator.ReplacePlaceholder(service.CachingConfig.KeyPlaceholder, service.CachingConfig.CustomKey,
                                                      context.Args);

            if (!(context is InterceptorContext ctx))
            {
                throw new ArgumentNullException();
            }
            var(value, hasKey) = await Caching.Get(key, ctx.ReturnType);

            if (hasKey)
            {
                return(new ServiceResult(value));
            }
            var result = await context.Next();

            if (result.Status != RemotingStatus.Ok)
            {
                return(result);
            }
            await Caching.Set(key, result.Result, service.CachingConfig.ExpireSeconds);

            return(result);
        }
Beispiel #5
0
 private void SetParameters(object ImplementationObj, IInterceptorContext context, IProxySelector proxySelector, Type serviceType, Type impType)
 {
     this._implementationObj = ImplementationObj;
     this._context           = context;
     this._proxySelector     = proxySelector;
     this._serviceType       = serviceType;
     this._impType           = impType;
 }
        public override void OnPreInvoke(IInterceptorContext context)
        {
            MockAttribute mockAttr = context.Method.DeclaringType.GetCustomAttribute <MockAttribute>();

            if (mockAttr == null)
            {
                return;
            }

            Object     mockObject = context.ServiceProvider.GetService(mockAttr.Type);
            MethodInfo method     = mockObject.GetType().GetMethod(context.Method.Name, context.Method.GetParameters().Select(x => x.ParameterType).ToArray());

            context.Result = method.Invoke(mockObject, context.Arguments);
        }
Beispiel #7
0
        public override void OnRespond(IInterceptorContext context, HttpResponseMessage response)
        {
            ResponseMediaTypeAttribute attr = context.Method.GetCustomAttribute <ResponseMediaTypeAttribute>();

            if (attr == null)
            {
                return;
            }

            if (response.Content.Headers.ContentType == null)
            {
                return;
            }

            response.Content.Headers.ContentType.MediaType = attr.MediaType;
        }
Beispiel #8
0
        public object Create(Type serviceType, Type implementationType, object implementationObj, IInterceptorContext context)
        {
            MethodInfo method        = typeof(DispatchProxy).GetMethod("Create");
            var        proxyType     = typeof(ProxyGenerator);
            MethodInfo genericMethod = method.MakeGenericMethod(serviceType, proxyType);

            //service dispatcher ile birlikte açılır, her method fire olduğunda dispatcher araya girer.
            object service = genericMethod.Invoke(null, null);

            ((ProxyGenerator)service).SetParameters(implementationObj, context, _proxySelector, serviceType, implementationType);
            return(service);
        }
 public virtual void OnRespond(IInterceptorContext context, HttpResponseMessage response)
 {
 }
Beispiel #10
0
 public override async Task <ResultMessage> Intercept(IInterceptorContext context)
 {
     Console.WriteLine("---------------->Interceptor2");
     return(await context.Next());
 }
 public virtual void OnClientUrlFound(IInterceptorContext context, ref string url)
 {
 }
Beispiel #12
0
 public override async Task <ResultMessage> Intercept(IInterceptorContext context)
 {
     return(await context.Next());
 }
 public override async Task <IServiceResult> Intercept(IInterceptorContext context)
 {
     Logger.LogTrace("\n---------------->Server global interceptor\n");
     return(await context.Next());
 }
 public virtual void OnPreInvoke(IInterceptorContext context)
 {
 }
 public override async Task <ResultMessage> Intercept(IInterceptorContext context)
 {
     Logger.LogDebug("\n---------------->Server global interceptor\n");
     return(await context.Next());
 }
Beispiel #16
0
 public void Dispose()
 {
     this._context = null;
 }
Beispiel #17
0
 public InterceptorBase(IInterceptorContext context)
 {
     _context = context;
 }
Beispiel #18
0
 public abstract Task <IServiceResult> Intercept(IInterceptorContext context);
Beispiel #19
0
 public override async Task <ResultMessage> Intercept(IInterceptorContext context)
 {
     Logger.LogDebug("\n--------------->Client interceptor attribute\n");
     return(await context.Next());
 }
 public virtual void OnHttpClientPrepaired(IInterceptorContext context)
 {
 }