using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using FLocal.Core; using FLocal.Common.URL; using URL = FLocal.Common.URL; namespace FLocal.IISHandler { class HandlersFactory { private static readonly Dictionary> handlersDictionary = new Dictionary> { { typeof(URL.forum.AllPosts),CreateHandler }, { typeof(URL.forum.AllThreads), CreateHandler }, { typeof(URL.forum.board.Headlines), CreateHandler }, { typeof(URL.forum.board.NewThread), CreateHandler }, { typeof(URL.forum.board.thread.post.Edit), CreateHandler }, { typeof(URL.forum.board.thread.post.PMReply), CreateHandler }, { typeof(URL.forum.board.thread.post.Punish), CreateHandler }, { typeof(URL.forum.board.thread.post.Reply), CreateHandler }, { typeof(URL.forum.board.thread.post.Show), CreateHandler }, { typeof(URL.forum.board.thread.Posts), CreateHandler }, { typeof(URL.forum.board.Threads), CreateHandler }, { typeof(URL.forum.Boards), CreateHandler }, { typeof(URL.maintenance.CleanCache), CreateHandler }, { typeof(URL.maintenance.LocalNetworks), CreateHandler }, { typeof(URL.my.Avatars), CreateHandler }, { typeof(URL.my.conversations.Conversation), CreateHandler }, { typeof(URL.my.conversations.List), CreateHandler }, { typeof(URL.my.conversations.NewPM), CreateHandler }, { typeof(URL.my.conversations.Reply), CreateHandler }, { typeof(URL.my.login.Login), CreateHandler }, { typeof(URL.my.login.Migrate), CreateHandler }, { typeof(URL.my.login.RegisterByInvite), CreateHandler }, { typeof(URL.my.Settings), CreateHandler }, { typeof(URL.my.UserData), CreateHandler }, { typeof(URL.polls.Info), CreateHandler }, { typeof(URL.polls.List), CreateHandler }, { typeof(URL.polls.New), CreateHandler }, { typeof(URL.QuickLink), CreateHandler }, { typeof(URL.Robots), CreateHandler }, { typeof(URL.Static), CreateHandler }, { typeof(URL.upload.Item), CreateHandler }, { typeof(URL.upload.List), CreateHandler }, { typeof(URL.upload.New), CreateHandler }, { typeof(URL.users.Active), CreateHandler }, { typeof(URL.users.All), CreateHandler }, { typeof(URL.users.Online), CreateHandler }, { typeof(URL.users.user.Info), CreateHandler }, { typeof(URL.users.user.PollsParticipated), CreateHandler }, { typeof(URL.users.user.Posts), CreateHandler }, { typeof(URL.users.user.Replies), CreateHandler }, { typeof(URL.users.user.Threads), CreateHandler }, }; private static ISpecificHandler CreateHandler(AbstractUrl url) where TUrl : AbstractUrl where THandler : handlers.AbstractGetHandler, new() { return new THandler() { url = (TUrl)url }; } public static ISpecificHandler getHandler(WebContext context) { if(context.httprequest.Path.ToLower().StartsWith("/do/")) { string action = context.httprequest.Path.ToLower().Substring(4).Trim('/'); if(action.StartsWith("markthreadasread")) { return new handlers.request.MarkThreadAsReadHandler(); } switch(action) { case "login": return new handlers.request.LoginHandler(); case "logout": return new handlers.request.LogoutHandler(); case "migrateaccount": return new handlers.request.MigrateAccountHandler(); case "register": return new handlers.request.RegisterHandler(); case "registerbyinvite": return new handlers.request.RegisterByInviteHandler(); case "edit": return new handlers.request.EditHandler(); case "punish": return new handlers.request.PunishHandler(); case "reply": return new handlers.request.ReplyHandler(); case "newthread": return new handlers.request.CreateThreadHandler(); case "settings": return new handlers.request.SettingsHandler(); case "userdata": return new handlers.request.UserDataHandler(); case "sendpm": return new handlers.request.SendPMHandler(); case "upload": return new handlers.request.UploadHandler(); case "newpoll": return new handlers.request.CreatePollHandler(); case "vote": return new handlers.request.VoteHandler(); case "avatars/add": return new handlers.request.avatars.AddHandler(); case "avatars/remove": return new handlers.request.avatars.RemoveHandler(); case "avatars/setasdefault": return new handlers.request.avatars.SetAsDefaultHandler(); case "maintenance/cleancache": return new handlers.request.maintenance.CleanCacheHandler(); default: return new handlers.WrongUrlHandler(); } } AbstractUrl url = UrlManager.Parse(context.httprequest.Path, context.httprequest.QueryString, context.account != null); if(url == null) { return new handlers.WrongUrlHandler(); } if(!context.httprequest.Path.StartsWith(url.canonical)) { //throw new ApplicationException("Going to redirect to: '" + url.canonicalFull + "' (canonical='" + url.canonicalFull + "')"); throw new RedirectException(url.canonicalFull); } return handlersDictionary[url.GetType()](url); } } }