2011-02-22 04:05:23 +00:00
|
|
|
|
using System.Collections.Specialized;
|
2011-02-17 05:30:31 +00:00
|
|
|
|
using System.Configuration;
|
2011-02-25 23:36:21 +00:00
|
|
|
|
using System.IO;
|
2011-02-17 05:30:31 +00:00
|
|
|
|
using System.Web.Mvc;
|
2011-02-09 03:50:45 +00:00
|
|
|
|
using System.Web.Routing;
|
2011-02-25 23:36:21 +00:00
|
|
|
|
using Lucene.Net.Analysis;
|
|
|
|
|
using Lucene.Net.Analysis.Standard;
|
|
|
|
|
using Lucene.Net.Index;
|
|
|
|
|
using Lucene.Net.QueryParsers;
|
|
|
|
|
using Lucene.Net.Search;
|
|
|
|
|
using Lucene.Net.Store;
|
|
|
|
|
using Lucene.Net.Util;
|
2011-02-10 04:39:59 +00:00
|
|
|
|
using Microsoft.Practices.Unity;
|
2011-02-25 23:36:21 +00:00
|
|
|
|
using Microsoft.Practices.Unity.InterceptionExtension;
|
2011-02-17 05:30:31 +00:00
|
|
|
|
using Portoa.Logging;
|
2011-02-26 01:08:38 +00:00
|
|
|
|
using Portoa.Lucene;
|
2011-02-25 23:36:21 +00:00
|
|
|
|
using Portoa.Persistence;
|
2011-02-26 01:08:38 +00:00
|
|
|
|
using Portoa.Search;
|
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-17 20:55:47 +00:00
|
|
|
|
using Portoa.Web.Security;
|
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-25 23:36:21 +00:00
|
|
|
|
using VideoGameQuotes.Web.Configuration;
|
2011-02-16 02:48:11 +00:00
|
|
|
|
using VideoGameQuotes.Web.Controllers;
|
|
|
|
|
using VideoGameQuotes.Web.Models;
|
2011-02-26 01:08:38 +00:00
|
|
|
|
using VideoGameQuotes.Web.Search;
|
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-25 23:36:21 +00:00
|
|
|
|
using Directory = Lucene.Net.Store.Directory;
|
2011-02-09 03:50:45 +00:00
|
|
|
|
|
|
|
|
|
namespace VideoGameQuotes.Web {
|
2011-02-21 23:59:06 +00:00
|
|
|
|
public class MvcApplication : MvcApplicationBase<User> {
|
2011-02-13 09:55:01 +00:00
|
|
|
|
|
|
|
|
|
protected override void ConfigureModelBinders(ModelBinderDictionary binders) {
|
2011-02-16 02:48:11 +00:00
|
|
|
|
binders
|
2011-02-23 01:30:53 +00:00
|
|
|
|
.Add<Region, FlagEnumModelBinder<Region>>()
|
2011-02-16 02:48:11 +00:00
|
|
|
|
.Add<BrowseModel, BrowseModelBinder>()
|
|
|
|
|
.Add<ApiModel, ApiModelBinder>();
|
2011-02-13 09:55:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-25 23:36:21 +00:00
|
|
|
|
protected override void ConfigureUnityExtensions() {
|
2011-02-10 04:39:59 +00:00
|
|
|
|
Container
|
|
|
|
|
.AddNewExtension<ConfigureLog4Net>()
|
|
|
|
|
.Configure<ILog4NetConfigurator>()
|
2011-02-10 20:34:55 +00:00
|
|
|
|
.SetName("VideoGameQuotes.Web")
|
|
|
|
|
.UseXml();
|
2011-02-25 23:36:21 +00:00
|
|
|
|
|
|
|
|
|
Container.AddNewExtension<LogAllMethodCalls>();
|
|
|
|
|
Container.AddNewExtension<UpdateSearchIndex>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ConfigureUnity() {
|
2011-02-10 04:39:59 +00:00
|
|
|
|
Container
|
2011-02-21 23:59:06 +00:00
|
|
|
|
.RegisterType<VerifyUserAttribute>(new InjectionProperty<VerifyUserAttribute>(attr => attr.UserProvider))
|
2011-02-25 23:36:21 +00:00
|
|
|
|
.RegisterAndIntercept<ICurrentUserProvider<User>, SessionBasedUserProvider>()
|
|
|
|
|
.RegisterAndIntercept<IUserService, UserService>()
|
|
|
|
|
.RegisterAndIntercept<IAdministrationService, AdministrationService>()
|
|
|
|
|
.RegisterAndIntercept<IQuoteService, QuoteService>()
|
|
|
|
|
.RegisterAndIntercept<ISystemService, SystemService>()
|
|
|
|
|
.RegisterAndIntercept<ICategoryService, CategoryService>()
|
|
|
|
|
.RegisterAndIntercept<IPublisherService, PublisherService>()
|
|
|
|
|
.RegisterAndIntercept<IGameService, GameService>()
|
|
|
|
|
.RegisterAndIntercept<IApiService, ApiService>()
|
|
|
|
|
.RegisterAndIntercept<IAuthenticationService, FormsAuthenticationService>()
|
|
|
|
|
.RegisterAndIntercept<IUserRepository, UserRepository>();
|
|
|
|
|
|
|
|
|
|
//search stuff
|
|
|
|
|
Container
|
|
|
|
|
.RegisterType<Directory>(new ContainerControlledLifetimeManager(), new InjectionFactory(CreateIndexDirectory))
|
|
|
|
|
.RegisterType<IndexWriter>(new ContainerControlledLifetimeManager(), new InjectionFactory(CreateIndexWriter))
|
|
|
|
|
.RegisterInstance(Version.LUCENE_29)
|
|
|
|
|
.RegisterType<Analyzer, StandardAnalyzer>(new InjectionConstructor(typeof(Version)))
|
|
|
|
|
.RegisterType<QueryParser>(new InjectionFactory(CreateQueryParser))
|
|
|
|
|
.RegisterAndIntercept(typeof(ISearcher<>), typeof(LuceneEntitySearcher<>))
|
|
|
|
|
.RegisterAndIntercept(typeof(ISearchService<>), typeof(SearchService<>))
|
|
|
|
|
.RegisterAndIntercept<ILuceneDocumentHandler<Quote>, QuoteDocumentHandler>()
|
|
|
|
|
.RegisterAndIntercept(typeof(ISearchIndexBuilder<>), typeof(LuceneEntityIndexBuilder<>));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region lucene-related factories
|
|
|
|
|
private static QueryParser CreateQueryParser(IUnityContainer container) {
|
|
|
|
|
return new QueryParser(container.Resolve<Version>(), "text", container.Resolve<Analyzer>());
|
2011-02-17 20:55:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-25 23:36:21 +00:00
|
|
|
|
private static Directory CreateIndexDirectory(IUnityContainer container) {
|
2011-02-17 20:55:47 +00:00
|
|
|
|
var indexDirectory = ((NameValueCollection)ConfigurationManager.GetSection("vgquotes"))["luceneIndexDirectory"];
|
2011-02-25 23:36:21 +00:00
|
|
|
|
return new SimpleFSDirectory(new DirectoryInfo(indexDirectory));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IndexWriter CreateIndexWriter(IUnityContainer container) {
|
|
|
|
|
return new IndexWriter(
|
|
|
|
|
container.Resolve<Directory>(),
|
|
|
|
|
new StandardAnalyzer(Version.LUCENE_29),
|
|
|
|
|
true,
|
|
|
|
|
IndexWriter.MaxFieldLength.UNLIMITED
|
|
|
|
|
);
|
2011-02-17 05:30:31 +00:00
|
|
|
|
}
|
2011-02-25 23:36:21 +00:00
|
|
|
|
#endregion
|
2011-02-17 05:30:31 +00:00
|
|
|
|
|
|
|
|
|
protected override void AfterStartUp() {
|
2011-02-25 23:36:21 +00:00
|
|
|
|
Container.Resolve<ISearchIndexBuilder<Quote>>().BuildIndex();
|
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-17 20:55:47 +00:00
|
|
|
|
//bullshit route so that RenderAction works
|
|
|
|
|
routes.MapRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" });
|
|
|
|
|
|
2011-02-24 08:07:50 +00:00
|
|
|
|
routes.MapRoute("crud-default", "{controller}/{action}", null, new { controller = "system|publisher|game|category", action = "create|edit|delete" });
|
2011-02-22 09:39:59 +00:00
|
|
|
|
|
2011-02-21 23:59:06 +00:00
|
|
|
|
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 });
|
2011-02-17 20:55:47 +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-17 20:55:47 +00:00
|
|
|
|
routes.MapRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" });
|
2011-02-24 22:45:29 +00:00
|
|
|
|
routes.MapRoute("paged", "{action}/{page}", new { controller = "Quote", page = 1 }, new { action = "best|recent", page = @"\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" });
|
2011-02-19 09:41:09 +00:00
|
|
|
|
routes.MapRoute("quote-task", "{action}/{id}", new { controller = "Quote" }, new { action = "edit|flags", id = @"\d+" });
|
2011-02-22 04:05:23 +00:00
|
|
|
|
routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|vote|report" });
|
2011-02-19 09:41:09 +00:00
|
|
|
|
routes.MapRoute("dismiss-flag", "dismiss-flag", new { controller = "Quote", action = "DismissFlag" });
|
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-17 05:30:31 +00:00
|
|
|
|
routes.MapRoute("default", "{controller}", new { controller = "home", action = "index" });
|
2011-02-09 03:50:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|