public void ProcessRequest(HttpContext context)
{
try
{
var rootUrl = Utils.AbsoluteWebRoot.ToString();
// context.Request.Url.ToString().Substring(0, context.Request.Url.ToString().IndexOf("metaweblog.axd"));
var input = new XMLRPCRequest(context);
var output = new XMLRPCResponse(input.MethodName);
Security.ImpersonateUser(input.UserName, input.Password);
// After user credentials have been set, we can use the normal Security
// class to authorize individual requests.
if (!Security.IsAuthenticated)
{
throw new MetaWeblogException("11", "User authentication failed");
}
switch (input.MethodName)
{
case "metaWeblog.newPost":
output.PostID = this.NewPost(
input.BlogID, input.UserName, input.Password, input.Post, input.Publish);
break;
case "metaWeblog.editPost":
output.Completed = this.EditPost(
input.PostID, input.UserName, input.Password, input.Post, input.Publish);
break;
case "metaWeblog.getPost":
output.Post = this.GetPost(input.PostID, input.UserName, input.Password);
break;
case "metaWeblog.newMediaObject":
output.MediaInfo = this.NewMediaObject(
input.BlogID, input.UserName, input.Password, input.MediaObject, context);
break;
case "metaWeblog.getCategories":
output.Categories = this.GetCategories(input.BlogID, input.UserName, input.Password, rootUrl);
break;
case "metaWeblog.getRecentPosts":
output.Posts = 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 = 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 = this.NewPage(
input.BlogID, input.UserName, input.Password, input.Page, input.Publish);
break;
case "wp.getPageList":
case "wp.getPages":
output.Pages = this.GetPages(input.BlogID, input.UserName, input.Password);
break;
case "wp.getPage":
output.Page = this.GetPage(input.BlogID, input.PageID, input.UserName, input.Password);
break;
case "wp.editPage":
output.Completed = this.EditPage(
input.BlogID, input.PageID, input.UserName, input.Password, input.Page, input.Publish);
break;
case "wp.deletePage":
output.Completed = this.DeletePage(input.BlogID, input.PageID, input.UserName, input.Password);
break;
case "wp.getAuthors":
output.Authors = this.GetAuthors(input.BlogID, input.UserName, input.Password);
break;
case "wp.getTags":
output.Keywords = this.GetKeywords(input.BlogID, input.UserName, input.Password);
break;
}
output.Response(context);
}
catch (MetaWeblogException mex)
{
var output = new XMLRPCResponse("fault");
var fault = new MWAFault { faultCode = mex.Code, faultString = mex.Message };
output.Fault = fault;
output.Response(context);
}
catch (Exception ex)
{
var output = new XMLRPCResponse("fault");
var fault = new MWAFault { faultCode = "0", faultString = ex.Message };
output.Fault = fault;
output.Response(context);
}
}