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}"); } }
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)); }
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); }
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); }
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); }
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); } }
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)); }
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); }
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); }
/// <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); }
public AsyncInterceptorAdaper(IAsyncInterceptor asyncInterceptor) : base(asyncInterceptor) { }
public static TInterface Create(IAsyncInterceptor asyncInterceptor, IEventInterceptor eventInterceptor) => ProxyFactory.Create <TInterface>(asyncInterceptor, eventInterceptor);
/// <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)); }
public TraceInterceptor(TraceInterceptorAsync asyncInterceptor) { _asyncInterceptor = asyncInterceptor; }
public InterceptedAsyncHandler(IAsyncInterceptor <TInput, TOutput> innerInterceptor, IAsyncHandler <TInput, TOutput> innerHandler) { _innerInterceptor = innerInterceptor; _innerHandler = innerHandler; }
public static IInterfaceToProxy CreateProxy(ListLogger log, IAsyncInterceptor interceptor) { return(CreateProxy(() => new ClassWithInterfaceToProxy(log), interceptor)); }
/// <summary> /// Initializes a new instance of the <see cref="AsyncDeterminationInterceptor"/> class. /// </summary> public AsyncDeterminationInterceptor(IAsyncInterceptor asyncInterceptor) { AsyncInterceptor = asyncInterceptor; }
public TransactionInterceptor(TransactionInterceptorAsync asyncInterceptor) { _asyncInterceptor = asyncInterceptor; }
public static object CreateProxy(Type type, IAsyncInterceptor interceptor, object target) => Generator.CreateInterfaceProxyWithTarget(type, target, interceptor);
public TransactionInterceptor(ITransactionAsyncInterceptor asyncInterceptor) { this.asyncInterceptor = asyncInterceptor; }
public AsyncInterceptorMapper(IAsyncInterceptor asyncInterceptor) { this.AsyncInterceptor = asyncInterceptor; }
public LockInterceptor(ILockAsyncInterceptor asyncInterceptor) { this.asyncInterceptor = asyncInterceptor; }
public T Create <T>(IAsyncInterceptor asyncInterceptor, IEventInterceptor eventInterceptor) => (T)Create(asyncInterceptor, eventInterceptor);