public static void Configure() { var container = new Container(); container.Options.DefaultScopedLifestyle = new WebRequestLifestyle(); container.Register <ILogger>(() => LogManager.GetCurrentClassLogger(), Lifestyle.Singleton); container.Register <IMarkdown, SimpleQA.WebApp.Infrastructure.Markdown>(Lifestyle.Singleton); container.Register <ICommandExecuterMediator, CommandExecuterMediator>(Lifestyle.Singleton); container.Register <IModelBuilderMediator, ModelBuilderMediator>(Lifestyle.Singleton); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.RegisterMvcIntegratedFilterProvider(); RedisCommandsConfiguration.Configure(container, new IPEndPoint(IPAddress.Loopback, 6379), true); container.Verify(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); }
static void Main(string[] args) { DirectoryInfo directory; IPEndPoint endpoint; try { directory = new DirectoryInfo(args[0]); if (!directory.Exists) { throw new DirectoryNotFoundException(args[0]); } endpoint = new IPEndPoint(IPAddress.Parse(args[1]), Int32.Parse(args[2])); } catch (ArgumentOutOfRangeException) { Console.WriteLine("Usage: StackExchangeDumpLoader <Directory> <IPAddress> <Port>"); Console.ReadKey(true); return; } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Usage: StackExchangeDumpLoader <Directory> <IPAddress> <Port>"); Console.ReadKey(true); return; } var dicontainer = new SimpleInjector.Container(); dicontainer.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle(); dicontainer.Register <PostsXMLProcessor>(); dicontainer.Register <UsersXMLProcessor>(); dicontainer.Register <VotesXMLProcessor>(); dicontainer.Register <ICommandExecuterMediator>(() => new CommandExecuterMediator(dicontainer)); RedisCommandsConfiguration.Configure(dicontainer, endpoint, false); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nLOAD STACKEXCHANGE DUMP INTO SIMPLEQA\n"); Console.ResetColor(); Console.WriteLine("Reading files from " + directory); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nWARNING: This tool was not designed for uploading big dumps. Do not use it with dumps > 50Mb.\n"); Console.ResetColor(); Console.WriteLine("Press any key to start..."); Console.ReadKey(true); using (dicontainer.BeginExecutionContextScope()) { var users = dicontainer.GetInstance <UsersXMLProcessor>().Process(XDocument.Load(Path.Combine(directory.FullName, "Users.xml"))); var posts = dicontainer.GetInstance <PostsXMLProcessor>().Process(XDocument.Load(Path.Combine(directory.FullName, "Posts.xml")), users); dicontainer.GetInstance <VotesXMLProcessor>().Process(XDocument.Load(Path.Combine(directory.FullName, "Votes.xml")), users, posts); } Console.WriteLine("END"); Console.ReadKey(true); }