/// <summary> /// Process the HTTP Request. Create XMLRPC request, find method call, process it and create response object and sent it back. /// This is the heart of the MetaWeblog API /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { try { string rootUrl = ConfigHelper.SiteUrl; XMLRPCRequest input = new XMLRPCRequest(context); XMLRPCResponse output = new XMLRPCResponse(input.MethodName); switch (input.MethodName) { case "metaWeblog.newPost": output.PostID = NewPost(input.BlogID, input.UserName, input.Password, input.Post, input.Publish); break; case "metaWeblog.editPost": output.Completed = EditPost(input.PostID, input.UserName, input.Password, input.Post, input.Publish); break; case "metaWeblog.getPost": output.Post = GetPost(input.PostID, input.UserName, input.Password); break; case "metaWeblog.newMediaObject": output.MediaInfo = NewMediaObject(input.BlogID, input.UserName, input.Password, input.MediaObject, context); break; case "metaWeblog.getCategories": output.Categories = GetCategories(input.BlogID, input.UserName, input.Password, rootUrl); break; case "metaWeblog.getRecentPosts": output.Posts = GetRecentPosts(input.BlogID, input.UserName, input.Password, input.NumberOfPosts); break; case "blogger.getUsersBlogs": case "metaWeblog.getUsersBlogs": output.Blogs = GetUserBlogs(input.AppKey, input.UserName, input.Password, rootUrl); break; case "blogger.deletePost": output.Completed = DeletePost(input.AppKey, input.PostID, input.UserName, input.Password, input.Publish); break; case "blogger.getUserInfo": throw new MetaWeblogException("10", "获取用户方法未实现."); case "wp.newPage": throw new MetaWeblogException("10", "创建页面未实现."); break; case "wp.getPageList": case "wp.getPages": throw new MetaWeblogException("10", "获取页面列表未实现."); break; case "wp.getPage": throw new MetaWeblogException("10", "获取页面未实现."); break; case "wp.editPage": throw new MetaWeblogException("10", "编辑页面未实现."); break; case "wp.deletePage": throw new MetaWeblogException("10", "删除页面未实现."); break; case "wp.getAuthors": output.Authors = GetAuthors(input.BlogID, input.UserName, input.Password); break; case "wp.getTags": output.Keywords = GetKeywords(input.BlogID, input.UserName, input.Password); break; } output.Response(context); } catch (MetaWeblogException mex) { XMLRPCResponse output = new XMLRPCResponse("fault"); MWAFault fault = new MWAFault(); fault.faultCode = mex.Code; fault.faultString = mex.Message; output.Fault = fault; output.Response(context); } catch (Exception ex) { XMLRPCResponse output = new XMLRPCResponse("fault"); MWAFault fault = new MWAFault(); fault.faultCode = "0"; fault.faultString = ex.Message; output.Fault = fault; output.Response(context); } }