2011-02-17 05:30:31 +00:00
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Web.Mvc;
|
2011-02-09 03:50:45 +00:00
|
|
|
|
using System.Web.Routing;
|
2011-02-10 04:39:59 +00:00
|
|
|
|
using Microsoft.Practices.Unity;
|
2011-02-17 05:30:31 +00:00
|
|
|
|
using Portoa.Logging;
|
|
|
|
|
using Portoa.Persistence;
|
2011-02-10 04:39:59 +00:00
|
|
|
|
using Portoa.Web;
|
2011-02-13 09:55:01 +00:00
|
|
|
|
using Portoa.Web.Models;
|
2011-02-10 04:39:59 +00:00
|
|
|
|
using Portoa.Web.Unity;
|
2011-02-12 23:53:43 +00:00
|
|
|
|
using UnityGenerics;
|
2011-02-10 04:39:59 +00:00
|
|
|
|
using VideoGameQuotes.Api;
|
|
|
|
|
using VideoGameQuotes.Api.Persistence;
|
2011-02-17 05:30:31 +00:00
|
|
|
|
using VideoGameQuotes.Api.Search;
|
|
|
|
|
using VideoGameQuotes.Api.Search.Lucene;
|
2011-02-16 02:48:11 +00:00
|
|
|
|
using VideoGameQuotes.Web.Controllers;
|
|
|
|
|
using VideoGameQuotes.Web.Models;
|
2011-02-10 04:39:59 +00:00
|
|
|
|
using VideoGameQuotes.Web.Security;
|
2011-02-12 23:53:43 +00:00
|
|
|
|
using VideoGameQuotes.Web.Services;
|
2011-02-09 03:50:45 +00:00
|
|
|
|
|
|
|
|
|
namespace VideoGameQuotes.Web {
|
2011-02-13 09:55:01 +00:00
|
|
|
|
public class MvcApplication : MvcApplicationBase {
|
|
|
|
|
|
|
|
|
|
protected override void ConfigureModelBinders(ModelBinderDictionary binders) {
|
2011-02-16 02:48:11 +00:00
|
|
|
|
binders
|
|
|
|
|
.Add<Region, FlagEnumModelBinder>()
|
|
|
|
|
.Add<BrowseModel, BrowseModelBinder>()
|
|
|
|
|
.Add<ApiModel, ApiModelBinder>();
|
2011-02-13 09:55:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 04:39:59 +00:00
|
|
|
|
protected override void ConfigureUnity() {
|
|
|
|
|
Container
|
|
|
|
|
.AddNewExtension<ConfigureLog4Net>()
|
|
|
|
|
.Configure<ILog4NetConfigurator>()
|
2011-02-10 20:34:55 +00:00
|
|
|
|
.SetName("VideoGameQuotes.Web")
|
|
|
|
|
.UseXml();
|
2011-02-10 04:39:59 +00:00
|
|
|
|
|
|
|
|
|
Container
|
|
|
|
|
.AddNewExtension<LogAllMethodCalls>()
|
2011-02-10 21:04:13 +00:00
|
|
|
|
.RegisterType<ICurrentUserProvider, SessionBasedUserProvider>()
|
2011-02-12 23:53:43 +00:00
|
|
|
|
.RegisterType<IsValidUserAttribute>(new InjectionProperty<IsValidUserAttribute>(attr => attr.UserProvider))
|
2011-02-10 04:39:59 +00:00
|
|
|
|
.RegisterType<IUserService, UserService>()
|
2011-02-12 23:53:43 +00:00
|
|
|
|
.RegisterType<IQuoteService, QuoteService>()
|
2011-02-16 02:48:11 +00:00
|
|
|
|
.RegisterType<IApiService, ApiService>()
|
2011-02-17 05:30:31 +00:00
|
|
|
|
.RegisterType<IQuoteSearcher, LuceneQuoteSearcher>()
|
|
|
|
|
.RegisterType<ISearchIndexLocator, SearchIndexLocator>(
|
|
|
|
|
new ContainerControlledLifetimeManager(),
|
|
|
|
|
new InjectionFactory(container => new SearchIndexLocator(((NameValueCollection)ConfigurationManager.GetSection("vgquotes"))["luceneIndexDirectory"]))
|
|
|
|
|
).RegisterType<IUserRepository, UserRepository>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AfterStartUp() {
|
|
|
|
|
var logger = Container.Resolve<ILogger>();
|
|
|
|
|
logger.Info("Building lucene index");
|
|
|
|
|
Container.Resolve<IQuoteSearcher>().BuildIndex();
|
|
|
|
|
logger.Info("Done building lucene index");
|
2011-02-10 04:39:59 +00:00
|
|
|
|
}
|
2011-02-09 03:50:45 +00:00
|
|
|
|
|
2011-02-10 04:39:59 +00:00
|
|
|
|
protected override void RegisterRoutes(RouteCollection routes) {
|
2011-02-09 03:50:45 +00:00
|
|
|
|
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
|
2011-02-10 04:39:59 +00:00
|
|
|
|
routes.IgnoreRoute("media/{*anything}");
|
2011-02-09 03:50:45 +00:00
|
|
|
|
|
2011-02-16 10:11:55 +00:00
|
|
|
|
routes.MapRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" });
|
2011-02-14 19:19:15 +00:00
|
|
|
|
routes.MapRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact" });
|
2011-02-14 19:48:36 +00:00
|
|
|
|
routes.MapRoute("best", "best/{start}-{end}/", new { controller = "Quote", action = "Best" }, new { start = @"\d+", end = @"\d+" });
|
2011-02-16 02:48:11 +00:00
|
|
|
|
routes.MapRoute("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" });
|
2011-02-17 05:30:31 +00:00
|
|
|
|
routes.MapRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" });
|
|
|
|
|
routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|best|vote|report" });
|
2011-02-14 07:39:45 +00:00
|
|
|
|
routes.MapRoute("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" });
|
2011-02-14 19:19:15 +00:00
|
|
|
|
routes.MapRoute("create-category", "category/create", new { controller = "Quote", action = "CreateCategory" });
|
2011-02-17 05:30:31 +00:00
|
|
|
|
routes.MapRoute("default", "{controller}", new { controller = "home", action = "index" });
|
2011-02-09 03:50:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|