예제 #1
0
 public static void Trace(this IAsyncInterceptor interceptor, string message, IInvocation invocation, ILogger logger)
 {
     if (logger.IsEnabled(LogLevel.Trace))
     {
         logger.Log(LogLevel.Trace, $"{invocation.TargetType.FullName}#{invocation.MethodInvocationTarget.Name} {message}");
     }
 }
예제 #2
0
 private static T Intercept <T>(this IProxyGenerator generator, T instance, IAsyncInterceptor interceptor)
     where T : class
 {
     return(typeof(T).IsInterface
         ? generator.CreateInterfaceProxyWithTargetInterface(instance, interceptor)
         : generator.CreateClassProxyWithTarget(instance, interceptor));
 }
        private T CreateMethods <T>(IAsyncInterceptor interceptor)
        {
            var proxyBuilder = new ProxyFactoryBuilder(typeof(T));

            proxyBuilder.InterceptMethods();
            return(proxyBuilder.Build().Create <T>(interceptor, eventInterceptor: null));
        }
예제 #4
0
        public static T CreateProxy <T>(IAsyncInterceptor asyncInterceptor)
        {
            var typeBuilder = BuildTypeFromInterface(typeof(T).GetTypeInfo(), out var interfaceList);

            //Implement IAsyncInterceptorProxy
            var implementor = new AsyncInterceptorImplementor();

            implementor.ImplementProxy(typeBuilder);

            var methods = GetMethods(interfaceList);

            var builder = new ProxyMethodBuilder();

            for (var i = 0; i < methods.Count; i++)
            {
                builder.CreateMethod(implementor.InterceptorField, methods[i], i, typeBuilder);
            }

            var proxyType = typeBuilder.CreateTypeInfo();
            var result    = (T)Activator.CreateInstance(proxyType.AsType());

            var proxy = (IAsyncInterceptorProxy)result;

            proxy.Interceptor = asyncInterceptor;
            proxy.Methods     = methods.ToArray();

            return(result);
        }
예제 #5
0
        public static void Trace(this IAsyncInterceptor interceptor, string message, IInvocation invocation, ILogger logger)
        {
            var callerClassName = invocation.TargetType.FullName;

            NLog.LogEventInfo info = new NLog.LogEventInfo(NLog.LogLevel.Trace, logger.Name, message);
            // 呼び出し元情報を設定します。
            info.SetCallerInfo(callerClassName, invocation.MethodInvocationTarget.Name, null, 0);
            logger.Log(typeof(TraceInterceptor), info);
        }
예제 #6
0
        public static IAsyncHandler <TInput, TOutput> Intercepting <TInput, TOutput>(
            this IAsyncInterceptor <TInput, TOutput> interceptor,
            IAsyncHandler <TInput, TOutput> handler)
        {
            interceptor = interceptor ?? throw new ArgumentNullException(nameof(interceptor));
            handler     = handler ?? throw new ArgumentNullException(nameof(handler));

            return(new InterceptedAsyncHandler <TInput, TOutput>(interceptor, handler));
        }
        public static IInterfaceToProxy CreateProxy(
            ListLogger log,
            IAsyncInterceptor interceptor,
            out ClassWithInterfaceToProxy target)
        {
            var localTarget = new ClassWithInterfaceToProxy(log);

            target = localTarget;
            return(CreateProxy(() => localTarget, interceptor));
        }
        public static IInterfaceToProxy CreateProxy(List <string> log, IAsyncInterceptor interceptor)
        {
            // Arrange
            var classWithInterfaceToProxy = new ClassWithInterfaceToProxy(log);

            var proxy = Generator.CreateInterfaceProxyWithTargetInterface <IInterfaceToProxy>(
                classWithInterfaceToProxy,
                interceptor);

            return(proxy);
        }
        public object Create(IAsyncInterceptor asyncInterceptor, IEventInterceptor eventInterceptor)
        {
            var result = Activator.CreateInstance(_proxyImplementation);

            if (InterceptedMethods != null)
            {
                var asyncProxy = (IAsyncInterceptorProxy)result;
                asyncProxy.Interceptor = asyncInterceptor ?? throw new ArgumentNullException(nameof(asyncInterceptor));
                asyncProxy.Methods     = InterceptedMethods.ToArray();
            }

            if (InterceptedEvents != null)
            {
                var eventProxy = (IEventInterceptorProxy)result;
                eventProxy.Interceptor = eventInterceptor ?? throw new ArgumentNullException(nameof(asyncInterceptor));
                eventProxy.Events      = InterceptedEvents.ToArray();
            }

            return(result);
        }
예제 #10
0
        public static bool TryGetAsyncInterceptor(object instance, out IAsyncInterceptor asyncInterceptor)
        {
            var instanceTypeInfo = instance.GetType().GetTypeInfo();

            if (instanceTypeInfo.FullName.Contains("Castle.Proxies"))
            {
                var interceptors = (IInterceptor[])instanceTypeInfo.GetField("__interceptors").GetValue(instance);
                if (interceptors.Length != 1)
                {
                    throw new InvalidOperationException("Encountered multiple interceptors for type " + instanceTypeInfo.FullName + ": " + interceptors.Join(", "));
                }

                asyncInterceptor = (IAsyncInterceptor)interceptors[0];
                return(true);
            }
            else
            {
                asyncInterceptor = null;
                return(false);
            }
        }
예제 #11
0
 private static object Intercept(this IProxyGenerator generator, Type type, object instance, IAsyncInterceptor interceptor)
 {
     return(type.IsInterface
         ? generator.CreateInterfaceProxyWithTargetInterface(type, instance, interceptor)
         : generator.CreateClassProxyWithTarget(type, instance, interceptor));
 }
예제 #12
0
 public MessageInterceptor(IAsyncInterceptor interceptorClient) : base()
 {
     _interceptorClient = interceptorClient;
 }
        public static IInterfaceToProxy CreateProxy(Func <IInterfaceToProxy> factory, IAsyncInterceptor interceptor)
        {
            IInterfaceToProxy implementation = factory();
            IInterfaceToProxy proxy          = Generator.CreateInterfaceProxyWithTargetInterface(implementation, interceptor);

            return(proxy);
        }
예제 #14
0
 public AsyncToSyncInterceptorAdapter(IAsyncInterceptor asyncInterceptor)
 {
     _asyncInterceptor = asyncInterceptor;
 }
 public static IInterfaceToProxy CreateProxy(ListLogger log, IAsyncInterceptor interceptor)
 {
     return(CreateProxy(log, interceptor, out _));
 }
 public TransactionalInterceptor(NemesisContext context)
 {
     _asyncInterceptor = new AsyncTransactionalInterceptor(context);
 }
예제 #17
0
 /// <summary>
 /// This method is created as a delegate and used to make the call to the generic
 /// <see cref="IAsyncInterceptor.InterceptAsynchronous{T}"/> method.
 /// </summary>
 /// <typeparam name="TResult">The type of the <see cref="Task{T}"/> <see cref="Task{T}.Result"/> of the method
 /// <paramref name="invocation"/>.</typeparam>
 private static void HandleAsyncWithResult <TResult>(IInvocation invocation, IAsyncInterceptor asyncInterceptor)
 {
     asyncInterceptor.InterceptAsynchronous <TResult>(invocation);
 }
예제 #18
0
 public AsyncInterceptorAdaper(IAsyncInterceptor asyncInterceptor) : base(asyncInterceptor)
 {
 }
예제 #19
0
 public static TInterface Create(IAsyncInterceptor asyncInterceptor, IEventInterceptor eventInterceptor) =>
 ProxyFactory.Create <TInterface>(asyncInterceptor, eventInterceptor);
예제 #20
0
 /// <summary>
 /// Creates an <see cref="IInterceptor"/> for the supplied <paramref name="interceptor"/>.
 /// </summary>
 /// <param name="interceptor">The interceptor for asynchronous operations.</param>
 /// <returns>The <see cref="IInterceptor"/> for the supplied <paramref name="interceptor"/>.</returns>
 public static IInterceptor ToInterceptor(this IAsyncInterceptor interceptor)
 {
     return(new AsyncDeterminationInterceptor(interceptor));
 }
예제 #21
0
 public TraceInterceptor(TraceInterceptorAsync asyncInterceptor)
 {
     _asyncInterceptor = asyncInterceptor;
 }
예제 #22
0
 public InterceptedAsyncHandler(IAsyncInterceptor <TInput, TOutput> innerInterceptor,
                                IAsyncHandler <TInput, TOutput> innerHandler)
 {
     _innerInterceptor = innerInterceptor;
     _innerHandler     = innerHandler;
 }
예제 #23
0
 public static IInterfaceToProxy CreateProxy(ListLogger log, IAsyncInterceptor interceptor)
 {
     return(CreateProxy(() => new ClassWithInterfaceToProxy(log), interceptor));
 }
예제 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncDeterminationInterceptor"/> class.
 /// </summary>
 public AsyncDeterminationInterceptor(IAsyncInterceptor asyncInterceptor)
 {
     AsyncInterceptor = asyncInterceptor;
 }
예제 #25
0
 public TransactionInterceptor(TransactionInterceptorAsync asyncInterceptor)
 {
     _asyncInterceptor = asyncInterceptor;
 }
예제 #26
0
 public static object CreateProxy(Type type, IAsyncInterceptor interceptor, object target) => Generator.CreateInterfaceProxyWithTarget(type, target, interceptor);
예제 #27
0
 public TransactionInterceptor(ITransactionAsyncInterceptor asyncInterceptor)
 {
     this.asyncInterceptor = asyncInterceptor;
 }
예제 #28
0
 public AsyncInterceptorMapper(IAsyncInterceptor asyncInterceptor)
 {
     this.AsyncInterceptor = asyncInterceptor;
 }
예제 #29
0
 public LockInterceptor(ILockAsyncInterceptor asyncInterceptor)
 {
     this.asyncInterceptor = asyncInterceptor;
 }
 public T Create <T>(IAsyncInterceptor asyncInterceptor, IEventInterceptor eventInterceptor) =>
 (T)Create(asyncInterceptor, eventInterceptor);