main
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.IO;
5using System.Net;
6using Autofac.Builder;
7using common;
8using Rhino.Queues;
9
10namespace client
11{
12 class Client
13 {
14 static void Main()
15 {
16 Process.Start(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\server\bin\Debug\server.exe")));
17
18 try
19 {
20 AppDomain.CurrentDomain.UnhandledException += (o, e) =>
21 {
22 (e.ExceptionObject as Exception).add_to_log();
23 };
24 AppDomain.CurrentDomain.ProcessExit += (o, e) =>
25 {
26 "shutting down".log();
27 try
28 {
29 Resolve.the<CommandProcessor>().stop();
30 Resolve.the<IQueueManager>().Dispose();
31 }
32 catch {}
33 Environment.Exit(Environment.ExitCode);
34 };
35 run();
36 Console.ReadLine();
37 }
38 catch (Exception e)
39 {
40 e.add_to_log();
41 Console.Out.WriteLine(e);
42 Console.ReadLine();
43 }
44 }
45
46 static void run()
47 {
48 var builder = new ContainerBuilder();
49 var registry = new AutofacDependencyRegistryBuilder(builder).build();
50 Resolve.initialize_with(registry);
51 builder.Register(x => registry).As<DependencyRegistry>().SingletonScoped();
52
53 //needs startups
54 builder.Register<StartServiceBus>().As<NeedStartup>();
55
56 // infrastructure
57
58 var manager = new QueueManager(new IPEndPoint(IPAddress.Loopback, 2201), "client.esent");
59 manager.CreateQueues("client");
60 builder.Register(x => new RhinoPublisher("server", 2200, manager)).As<ServiceBus>().SingletonScoped();
61 builder.Register(x => new RhinoReceiver(manager.GetQueue("client"), x.Resolve<CommandProcessor>())).As<RhinoReceiver>().As<Receiver>().SingletonScoped();
62
63
64 // commanding
65 //builder.Register<AsynchronousCommandProcessor>().As<CommandProcessor>().SingletonScoped();
66 builder.Register<SynchronousCommandProcessor>().As<CommandProcessor>().SingletonScoped();
67
68 builder.Register<RequestHandler>().As<Handler>();
69
70 Resolve.the<IEnumerable<NeedStartup>>().each(x => x.run());
71 Resolve.the<CommandProcessor>().run();
72 "started".log();
73 }
74 }
75}