Example #1
0
        /// <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">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        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);
            }
        }
        /// <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">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        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);
            }
        }
Example #3
0
        /// <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 = Utils.AbsoluteWebRoot.ToString();// context.Request.Url.ToString().Substring(0, context.Request.Url.ToString().IndexOf("metaweblog.axd"));
                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":
                        //Not implemented.  Not planned.
                        throw new MetaWeblogException("10", "The method GetUserInfo is not implemented.");
                    case "wp.newPage":
                        output.PageID = NewPage(input.BlogID, input.UserName, input.Password, input.Page, input.Publish);
                        break;
                    case "wp.getPageList":
                    case "wp.getPages":
                        output.Pages = GetPages(input.BlogID, input.UserName, input.Password);
                        break;
                    case "wp.getPage":
                        output.Page = GetPage(input.BlogID, input.PageID, input.UserName, input.Password);
                        break;
                    case "wp.editPage":
                        output.Completed = EditPage(input.BlogID, input.PageID, input.UserName, input.Password, input.Page, input.Publish);
                        break;
                    case "wp.deletePage":
                        output.Completed = DeletePage(input.BlogID, input.PageID, input.UserName, input.Password);
                        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);
            }
        }
        /// <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 = Utils.AbsoluteWebRoot.ToString();        // context.Request.Url.ToString().Substring(0, context.Request.Url.ToString().IndexOf("metaweblog.axd"));
                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":
                    //Not implemented.  Not planned.
                    throw new MetaWeblogException("10", "The method GetUserInfo is not implemented.");

                case "wp.newPage":
                    output.PageID = NewPage(input.BlogID, input.UserName, input.Password, input.Page, input.Publish);
                    break;

                case "wp.getPageList":
                case "wp.getPages":
                    output.Pages = GetPages(input.BlogID, input.UserName, input.Password);
                    break;

                case "wp.getPage":
                    output.Page = GetPage(input.BlogID, input.PageID, input.UserName, input.Password);
                    break;

                case "wp.editPage":
                    output.Completed = EditPage(input.BlogID, input.PageID, input.UserName, input.Password, input.Page, input.Publish);
                    break;

                case "wp.deletePage":
                    output.Completed = DeletePage(input.BlogID, input.PageID, input.UserName, input.Password);
                    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);
            }
        }