public static void Test() { // Map behaviors. InterfaceBehaviorCollection interfaceBehaviors = new InterfaceBehaviorCollection(); interfaceBehaviors .Add <I1, Ti1>() .Insert <I2, Ti2>(0) .Insert(0, typeof(I3 <,>), typeof(Ti3 <,>)) .Add(typeof(I4 <>), typeof(Ti4)); IBehaviorProvider behaviorProvider = new BehaviorProviderCollection() .Add(interfaceBehaviors) .Add( new AttributeBehaviorCollection() .Add(typeof(ReprocessAttribute), typeof(ReprocessBehavior)) ); IEnumerable <Type> behaviors = behaviorProvider.GetBehaviors(typeof(Test)); Console.WriteLine("Number of behaviors for Test class '{0}'.", behaviors.Count()); // Create reflection providers. IReflectionBehaviorFactory behaviorInstance = new ReflectionBehaviorFactoryCollection() .Add(typeof(ReprocessBehavior), new ReflectionReprocessBehaviorInstanceProvider()); // Invoke pipeline. //ReflectionMethodInvokePipeline<HelloService, string> pipeline = new ReflectionMethodInvokePipeline<HelloService, string>(interfaceBehaviors, behaviorInstance, "SayHello"); //pipeline.ExecuteAsync().ContinueWith(message => Console.WriteLine("Method result: '{0}'.", message.Result)); }
private static void TestServices() { Console.WriteLine("Current ThreadID: {0}", Thread.CurrentThread.ManagedThreadId); IBehaviorProvider behaviors = new BehaviorProviderCollection() .Add( new AttributeBehaviorCollection() .Add(typeof(ReprocessAttribute), typeof(ReprocessBehavior)) ); ICompilerConfiguration configuration = new CompilerConfiguration() //.BaseType(typeof(WorkerPipelineHandler<>)) .AddTempDirectory(@"C:\Temp\Pipelines"); configuration.References() .AddDirectory(Environment.CurrentDirectory); configuration.GetBehaviorGenerator( new CodeDomBehaviorGeneratorCollection() .Add(typeof(ReprocessAttribute), new CodeDomReprocessBehaviorInstanceGenerator()) ); ServiceHandlerCollection collection = new ServiceHandlerCollection(); //collection.Add(new TempCheckServiceHandler()); collection.Add( new BackgroundServiceCollection() .AddIntervalHandler(TimeSpan.FromSeconds(5), new TempCheckWorkerHandler()) ); //collection.Add(new Temp2CheckServiceHandler()); Console.WriteLine("Starting services..."); collection.Start(); Console.WriteLine("Press any key to stop services..."); Console.ReadKey(true); collection.Stop(); Console.WriteLine("All services stopped..."); }