private FlowData ProcessFlow(IFlow flow) { var options = new ProxyGenerationOptions(new FreezableProxyGenerationHook(flow)); var flowProxy = _proxyGenerator.CreateClassProxyWithTarget(flow.GetType(), flow, options, new IInterceptor[] { this }) as IFlow; _flow = flow; try { // clear previous statuses _counter = 0; _flowData.IsStopped = false; _flowData.LastException = null; // run flow flowProxy.Execute(); _flowData.IsFinished = true; } catch (FlowStopException e) { _flowData.IsStopped = true; } catch (Exception e) { _flowData.LastException = e; } return(_flowData); }
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)); }
/// <summary> /// See the <see cref="IProxyGenerator .CreateClassProxyWithTarget(Type, object, IInterceptor[])"/> documentation. /// </summary> public static object CreateClassProxyWithTarget( this IProxyGenerator proxyGenerator, Type classToProxy, object target, params IAsyncInterceptor[] interceptors) { return(proxyGenerator.CreateClassProxyWithTarget(classToProxy, target, interceptors.ToInterceptors())); }
/// <summary> /// See the <see cref="IProxyGenerator .CreateClassProxyWithTarget{TClass}(TClass, IInterceptor[])"/> documentation. /// </summary> public static TClass CreateClassProxyWithTarget <TClass>( this IProxyGenerator proxyGenerator, TClass target, params IAsyncInterceptor[] interceptors) where TClass : class { return(proxyGenerator.CreateClassProxyWithTarget(target, interceptors.ToInterceptors())); }
/// <summary> /// See the <see cref="IProxyGenerator .CreateClassProxyWithTarget(Type, Type[], object, ProxyGenerationOptions, IInterceptor[])"/> documentation. /// </summary> public static object CreateClassProxyWithTarget( this IProxyGenerator proxyGenerator, Type classToProxy, Type[] additionalInterfacesToProxy, object target, ProxyGenerationOptions options, params IAsyncInterceptor[] interceptors) { return(proxyGenerator.CreateClassProxyWithTarget( classToProxy, additionalInterfacesToProxy, target, options, interceptors.ToInterceptors())); }
/// <summary> /// See the <see cref="IProxyGenerator .CreateClassProxyWithTarget(Type, object, ProxyGenerationOptions, object[], IInterceptor[])"/> documentation. /// </summary> public static object CreateClassProxyWithTarget( this IProxyGenerator proxyGenerator, Type classToProxy, object target, ProxyGenerationOptions options, object[] constructorArguments, params IAsyncInterceptor[] interceptors) { return(proxyGenerator.CreateClassProxyWithTarget( classToProxy, target, options, constructorArguments, interceptors.ToInterceptors())); }
public FileService() { this.InitiateDirectories(); this.watcher = new FileSystemWatcher(this.inDir); this.watcher.Created += this.Watcher_Created; this.workThread = new Thread(this.WorkProcedure); this.stopWork = new ManualResetEvent(false); this.newFileEvent = new AutoResetEvent(false); IProxyGenerator generator = Ioc.GetInstance <IProxyGenerator>(); this.pdfCreator = generator.CreateClassProxyWithTarget(Ioc.GetInstance <PdfCreator>(), Ioc.GetInstance <IInterceptor>()); this.pdfCreator.CallbackWhenReadyToSave += this.SavePdfDocument; this.pdfCreator.CallbackWhenSecuenceHasWrongFileExtention += this.MoveAllFileSequenceToOtherDir; }
/// <summary> /// Create a proxy wrapping specified target instance and interceptors. /// </summary> /// <param name="typeToProxy">The declaration type of proxy to create.</param> /// <param name="target">The target instance wrapped by the created proxy.</param> /// <param name="initerceptors">The interceptors specific to each methods.</param> /// <returns>The proxy wrapping the specified target instance.</returns> /// <exception cref="ArgumentNullException">The argument <paramref name="typeToProxy"/> is null.</exception> /// <exception cref="ArgumentNullException">The argument <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentNullException">The argument <paramref name="initerceptors"/> is null.</exception> protected object CreateProxyCore(Type typeToProxy, object target, IDictionary <MethodInfo, InterceptorDelegate> initerceptors) { if (!initerceptors.Any()) { return(target); } IDictionary <MethodInfo, IInterceptor> dic = initerceptors.ToDictionary(it => it.Key, it => (IInterceptor) new DynamicProxyInterceptor(it.Value)); var selector = new DynamicProxyInterceptorSelector(dic); var options = new ProxyGenerationOptions { Selector = selector }; if (typeToProxy.GetTypeInfo().IsInterface) { return(_proxyGenerator.CreateInterfaceProxyWithTarget(typeToProxy, target, options, dic.Values.ToArray())); } else { return(_proxyGenerator.CreateClassProxyWithTarget(typeToProxy, target, options, dic.Values.ToArray())); } }
private static object CreateProxyWithTarget( Type serviceType, object target, ProxyGenerationOptions proxyGenerationOptions, IInterceptor[] interceptors) { if (serviceType.IsInterface) { return(ProxyGenerator.CreateInterfaceProxyWithTarget( serviceType, target, proxyGenerationOptions, interceptors)); } else { return(ProxyGenerator.CreateClassProxyWithTarget( serviceType, target, proxyGenerationOptions, interceptors)); } }
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 T CreateClass <T>(T real, IInterceptor[] interceptors) where T : class { var proxy = _generator.CreateClassProxyWithTarget(real, ProxyGenerationOptions.Default, interceptors); return(proxy); }
public T GetModelProxy <T>(T source) where T : class { var proxy = _proxyGenerator.CreateClassProxyWithTarget(source.GetType(), source, new IInterceptor[] { _interceptor }) as T; return(proxy); }