/// <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); } }
protected async Task <string> ProcessRequest() { string responseXml = string.Empty; try { var rootUrl = Request.Host.ToUriComponent(); var inputXml = GetRequest(Request.Body); _logger.LogDebug(inputXml); var input = new XMLRPCRequest(inputXml); var output = new XMLRPCResponse(input.MethodName); var user = GetVerifyUserAsync(input.UserName, input.Password); if (user == null) { throw new MetaWeblogException("11", "User authentication failed"); } switch (input.MethodName) { case "metaWeblog.newPost": output.PostID = await this.NewPost( input.BlogID, input.UserName, input.Password, input.Post, input.Publish); break; case "metaWeblog.editPost": output.Completed = await this.EditPost( input.PostID, input.UserName, input.Password, input.Post, input.Publish); break; case "metaWeblog.getPost": output.Post = await this.GetPost(input.PostID, input.UserName, input.Password); break; case "metaWeblog.newMediaObject": output.MediaInfo = await this.NewMediaObject(input.BlogID, input.UserName, input.Password, input.MediaObject); break; case "metaWeblog.getCategories": output.Categories = await this.GetCategories(input.BlogID, input.UserName, input.Password, rootUrl); break; case "metaWeblog.getRecentPosts": output.Posts = await this.GetRecentPosts(input.BlogID, input.UserName, input.Password, input.NumberOfPosts); break; case "blogger.getUsersBlogs": case "metaWeblog.getUsersBlogs": output.Blogs = this.GetUserBlogs(input.AppKey, input.UserName, input.Password, rootUrl); break; case "blogger.deletePost": output.Completed = await this.DeletePost( input.AppKey, input.PostID, input.UserName, input.Password, input.Publish); break; case "blogger.getUserInfo": // Not implemented. Not planned. throw new MetaWeblogException("10", "The method GetUserInfo is not implemented."); case "wp.newPage": output.PageID = await this.NewPage(input.BlogID, input.UserName, input.Password, input.Page, input.Publish); break; case "wp.getPageList": case "wp.getPages": output.Pages = await this.GetPages(input.BlogID, input.UserName, input.Password); break; case "wp.getPage": output.Page = await this.GetPage(input.BlogID, input.PageID, input.UserName, input.Password); break; case "wp.editPage": output.Completed = await this.EditPage(input.BlogID, input.PageID, input.UserName, input.Password, input.Page, input.Publish); break; case "wp.deletePage": output.Completed = await this.DeletePage(input.BlogID, input.PageID, input.UserName, input.Password); break; case "wp.getAuthors": output.Authors = await this.GetAuthors(input.BlogID, input.UserName, input.Password); break; case "wp.getTags": output.Keywords = await this.GetKeywords(input.BlogID, input.UserName, input.Password); break; } responseXml = output.ResponseXml(); } catch (MetaWeblogException mex) { var output = new XMLRPCResponse("fault"); var fault = new MWAFault { faultCode = mex.Code, faultString = mex.Message }; output.Fault = fault; responseXml = output.ResponseXml(); } catch (Exception ex) { var output = new XMLRPCResponse("fault"); var fault = new MWAFault { faultCode = "0", faultString = ex.Message }; output.Fault = fault; responseXml = output.ResponseXml(); } return(responseXml); }