private void handle_metaWeblog_deletePost(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall) { this.WriteLogMethodName(); var appkey = (MP.XmlRpc.StringValue)methodcall.Parameters[0]; var postid = (MP.XmlRpc.StringValue)methodcall.Parameters[1]; var username = (MP.XmlRpc.StringValue)methodcall.Parameters[2]; var password = (MP.XmlRpc.StringValue)methodcall.Parameters[3]; this.WriteLog("AppKey = {0}", postid.String); this.WriteLog("PostId = {0}", postid.String); this.WriteLog("Username = {0}", username.String); var post = this.PostList.TryGetPostById(postid.String); if (post == null) { this.WriteLog("No such Post with ID {0}", postid.String); // Post was not found respond_error_invalid_postid_parameter(context, 404); return; } // Post was found this.WriteLog("Found Post with ID {0}", postid.String); this.PostList.Delete(post.Value); var method_response = new MP.XmlRpc.MethodResponse(); method_response.Parameters.Add(true); // this is supposed to always return true WriteResponseString(context, method_response.CreateDocument().ToString(), 200, "text/xml"); }
public static void SerializeToXmlFile(MP.PostInfo[] posts, string filename) { var serializer = new System.Xml.Serialization.XmlSerializer(typeof(MP.PostInfo[])); var textWriter = new System.IO.StreamWriter(filename); serializer.Serialize(textWriter, posts); textWriter.Close(); }
private void handle_blogger_getUsersBlog(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall) { this.WriteLogMethodName(); var method_response = BuildStructArrayResponse(this.BlogList.Select(i => i.ToStruct())); var method_response_xml = method_response.CreateDocument(); var method_response_string = method_response_xml.ToString(); WriteResponseString(context, method_response_string, 200, "text/xml"); }
private void handle_blogger_getCategories(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall) { this.WriteLogMethodName(); var cats = this.CategoryList.ToList(); var method_response = BuildStructArrayResponse(cats.Select(c => c.ToStruct())); var method_response_xml = method_response.CreateDocument(); var method_response_string = method_response_xml.ToString(); WriteResponseString(context, method_response_string, 200, "text/xml"); }
public static void SaveBlogConnectionInfo(MP.BlogConnectionInfo coninfo, string filename) { var doc = new System.Xml.Linq.XDocument(); var p = new System.Xml.Linq.XElement("blogconnectioninfo"); doc.Add(p); p.Add(new System.Xml.Linq.XElement("blogurl", coninfo.BlogUrl)); p.Add(new System.Xml.Linq.XElement("blogid", coninfo.BlogId)); p.Add(new System.Xml.Linq.XElement("metaweblog_url", coninfo.MetaWeblogUrl)); p.Add(new System.Xml.Linq.XElement("username", coninfo.Username)); p.Add(new System.Xml.Linq.XElement("password", coninfo.Password)); doc.Save(filename); }
public PostInfoRecord(MP.PostInfo p) { this.Title = p.Title; this.Link = p.Link; this.DateCreated = p.DateCreated; this.PostId = p.PostId; this.UserId = p.UserId; this.CommentCount = p.CommentCount; this.PostStatus = p.PostStatus; this.Permalink = p.Permalink; this.Description = p.Description; this.Categories = BlogServer.join_cat_strings(p.Categories.Select(s=>s.Trim())); }
private void handle_metaWeblog_editPost(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall) { this.WriteLogMethodName(); var postid = (MP.XmlRpc.StringValue)methodcall.Parameters[0]; var username = (MP.XmlRpc.StringValue)methodcall.Parameters[1]; var password = (MP.XmlRpc.StringValue)methodcall.Parameters[2]; var struct_ = (MP.XmlRpc.Struct)methodcall.Parameters[3]; var publish = (MP.XmlRpc.BooleanValue)methodcall.Parameters[4]; this.AuthenicateUser(username.String,password.String); this.WriteLog("PostId = {0}", postid.String); this.WriteLog("Username = {0}", username.String); this.WriteLog("Publish = {0}", publish.Boolean); // Post was found var post_title = struct_.Get<MP.XmlRpc.StringValue>("title", null); var post_description = struct_.Get<MP.XmlRpc.StringValue>("description", null); var post_categories = struct_.Get<MP.XmlRpc.Array>("categories", null); var cats = GetCategoriesFromArray(post_categories); this.PostList.Edit(postid.String, null, post_title.String, post_description.String, cats, publish.Boolean); var method_response = new MP.XmlRpc.MethodResponse(); method_response.Parameters.Add(true); // this is supposed to always return true WriteResponseString(context, method_response.CreateDocument().ToString(), 200, "text/xml"); }
private void respond_unknown_xmlrpc_method(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall, string body) { this.WriteLogMethodName(); WriteLog("Unhandled XmlRpcMethod {0}", methodcall.Name); WriteLog("{0}", body); var f = new MP.XmlRpc.Fault(); f.FaultCode = 0; f.FaultString = string.Format("unsupported method {0}", methodcall.Name); WriteResponseString(context, f.CreateDocument().ToString(), 200, "text/xml"); }
private void handle_metaWeblog_newPost(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall) { this.WriteLogMethodName(); var blogid = (MP.XmlRpc.StringValue)methodcall.Parameters[0]; var username = (MP.XmlRpc.StringValue)methodcall.Parameters[1]; var password = (MP.XmlRpc.StringValue)methodcall.Parameters[2]; this.WriteLog("BlogId = {0}", blogid.String); this.WriteLog("Username = {0}", username.String); this.AuthenicateUser(username.String, password.String); var struct_ = (MP.XmlRpc.Struct)methodcall.Parameters[3]; var publish = (MP.XmlRpc.BooleanValue)methodcall.Parameters[4]; var post_title = struct_.Get<MP.XmlRpc.StringValue>("title").String; var post_description = struct_.Get<MP.XmlRpc.StringValue>("description"); var post_categories = struct_.Get<MP.XmlRpc.Array>("categories", null); var cats = GetCategoriesFromArray(post_categories); this.WriteLog(" Categories {0}", string.Join(",", cats)); var new_post = this.PostList.Add(null, post_title, post_description.String, cats, publish.Boolean); var method_response = new MP.XmlRpc.MethodResponse(); method_response.Parameters.Add(new_post.PostId); this.WriteLog("New Post Created with ID = {0}", new_post.PostId); WriteResponseString(context, method_response.CreateDocument().ToString(), 200, "text/xml"); }
private void handle_metaWeblog_newMediaObject(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall) { this.WriteLogMethodName(); var blogid = (MP.XmlRpc.StringValue)methodcall.Parameters[0]; var username = (MP.XmlRpc.StringValue)methodcall.Parameters[1]; var password = (MP.XmlRpc.StringValue)methodcall.Parameters[2]; this.AuthenicateUser(username.String, password.String); this.WriteLog("BlogId = {0}", blogid.String); this.WriteLog("Username = {0}", username.String); var struct_ = (MP.XmlRpc.Struct)methodcall.Parameters[3]; var name = struct_.Get<MP.XmlRpc.StringValue>("name"); var type = struct_.Get<MP.XmlRpc.StringValue>("type"); var bits = struct_.Get<MP.XmlRpc.Base64Data>("bits"); this.WriteLog("Name = {0}", name.String); this.WriteLog("Type = {0}", type.String); this.WriteLog("Bits = {0} Bytes Characters", bits.Bytes); var mo = this.MediaObjectList.StoreNewObject(blogid.String, username.String, name.String, type.String, Convert.ToBase64String(bits.Bytes)); var s_ = new MP.XmlRpc.Struct(); s_["url"] = new MP.XmlRpc.StringValue(this.ServerUrlPrimary + mo.Url.Substring(1)); var method_response = new MP.XmlRpc.MethodResponse(); method_response.Parameters.Add(s_); string response_body = method_response.CreateDocument().ToString(); this.WriteLog(response_body); WriteResponseString(context, response_body, 200, "text/xml"); }
private void handle_metaWeblog_getRecentPosts(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall) { this.WriteLogMethodName(); var method_response = BuildStructArrayResponse(this.PostList.Select(i => i.ToPostInfo().ToStruct())); var method_response_xml = method_response.CreateDocument(); var method_response_string = method_response_xml.ToString(); WriteResponseString(context, method_response_string, 200, "text/xml"); }
private void handle_metaWeblog_getPost(System.Net.HttpListenerContext context, MP.XmlRpc.MethodCall methodcall) { this.WriteLogMethodName(); var postid = (MP.XmlRpc.StringValue)methodcall.Parameters[0]; var username = (MP.XmlRpc.StringValue)methodcall.Parameters[1]; var password = (MP.XmlRpc.StringValue)methodcall.Parameters[2]; this.AuthenicateUser(username.String, password.String); this.WriteLog("PostId = {0}", postid.String); this.WriteLog("Username = {0}", username.String); var post = this.PostList.TryGetPostById(postid.String); if (post == null) { // Post was not found respond_error_invalid_postid_parameter(context, 200); return; } // Post was found respond_post(context, post.Value); }
private List<string> GetCategoriesFromArray(MP.XmlRpc.Array post_categories) { List<string> cats; if (post_categories.Items == null) { cats = new List<string>(0); } else { cats = new List<string>(post_categories.Count); foreach (var c in post_categories.Items) { var sv = c as MP.XmlRpc.StringValue; cats.Add(sv.String); } } return cats; }