using System.Collections.Specialized; using System.Configuration; using System.Web.Mvc; using System.Web.Routing; using Microsoft.Practices.Unity; using Portoa.Logging; using Portoa.Web; using Portoa.Web.Models; using Portoa.Web.Security; using Portoa.Web.Unity; using UnityGenerics; using VideoGameQuotes.Api; using VideoGameQuotes.Api.Persistence; using VideoGameQuotes.Api.Search; using VideoGameQuotes.Api.Search.Lucene; using VideoGameQuotes.Web.Controllers; using VideoGameQuotes.Web.Models; using VideoGameQuotes.Web.Security; using VideoGameQuotes.Web.Services; namespace VideoGameQuotes.Web { public class MvcApplication : MvcApplicationBase { protected override void ConfigureModelBinders(ModelBinderDictionary binders) { binders .Add>() .Add() .Add(); } protected override void ConfigureUnity() { Container .AddNewExtension() .Configure() .SetName("VideoGameQuotes.Web") .UseXml(); Container .AddNewExtension() .RegisterType, SessionBasedUserProvider>() .RegisterType(new InjectionProperty(attr => attr.UserProvider)) .RegisterType() .RegisterType() .RegisterType() .RegisterType() .RegisterType() .RegisterType() .RegisterType() .RegisterType() .RegisterType() .RegisterType() .RegisterType(new ContainerControlledLifetimeManager(), new InjectionFactory(CreateIndexLocator)) .RegisterType(); } private static SearchIndexLocator CreateIndexLocator(IUnityContainer container) { var indexDirectory = ((NameValueCollection)ConfigurationManager.GetSection("vgquotes"))["luceneIndexDirectory"]; return new SearchIndexLocator(indexDirectory); } protected override void AfterStartUp() { var logger = Container.Resolve(); logger.Info("Building lucene index"); Container.Resolve().BuildIndex(); logger.Info("Done building lucene index"); } protected override void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("media/{*anything}"); //bullshit route so that RenderAction works routes.MapRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" }); routes.MapRoute("crud-default", "{controller}/{action}", null, new { controller = "system|publisher|game|category", action = "create|edit|delete" }); routes.MapRoute("users-paged", "admin/users/{start}-{end}", new { controller = "Admin", action = "Users" }, new { start = @"\d+", end = @"\d+" }); routes.MapRoute("admin", "admin/{action}", new { controller = "Admin", action = "Index" }, new { action = "users|create|flags|password" }); routes.MapRoute("user-edit", "user/edit/{usernameOrIp}", new { controller = "User", action = "Edit", usernameOrIp = @"\w+" }); routes.MapRoute("user-default", "user/{action}/{id}", new { controller = "User", action = "delete|ban", id = UrlParameter.Optional }); routes.MapRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" }); routes.MapRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" }); routes.MapRoute("paged", "{action}/{page}", new { controller = "Quote", page = 1 }, new { action = "best|recent", page = @"\d+" }); routes.MapRoute("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" }); routes.MapRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" }); routes.MapRoute("quote-task", "{action}/{id}", new { controller = "Quote" }, new { action = "edit|flags", id = @"\d+" }); routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|vote|report" }); routes.MapRoute("dismiss-flag", "dismiss-flag", new { controller = "Quote", action = "DismissFlag" }); routes.MapRoute("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" }); routes.MapRoute("default", "{controller}", new { controller = "home", action = "index" }); } } }