コード例 #1
0
        public string NewPost(string title, string description, IList <string> categories, bool publish, DateTime?date_created)
        {
            XmlRPC.Array cats = null;

            if (categories == null)
            {
                cats = new XmlRPC.Array(0);
            }
            else
            {
                cats = new XmlRPC.Array(categories.Count);

                var ss = new List <Value>();

                categories.Select(c => new StringValue(c)).ToList().ForEach(i => ss.Add(i));

                cats.AddRange(ss);
            }

            var service = new Service(this.BlogConnectionInfo.MetaWeblogURL);

            var struct_ = new Struct();

            struct_["title"]       = new StringValue(title);
            struct_["description"] = new StringValue(description);
            struct_["categories"]  = cats;
            if (date_created.HasValue)
            {
                struct_["dateCreated"]      = new DateTimeValue(date_created.Value);
                struct_["date_created_gmt"] = new DateTimeValue(date_created.Value.ToUniversalTime());
            }
            var method = new MethodCall("metaWeblog.newPost");

            method.Parameters.Add(this.BlogConnectionInfo.BlogID);
            method.Parameters.Add(this.BlogConnectionInfo.Username);
            method.Parameters.Add(this.BlogConnectionInfo.Password);
            method.Parameters.Add(struct_);
            method.Parameters.Add(publish);

            service.Cookies = this.BlogConnectionInfo.Cookies;

            var response = service.Execute(method);
            var param    = response.Parameters[0];
            var postid   = ((StringValue)param).String;

            return(postid);
        }
コード例 #2
0
        public bool EditPost(string postid, string title, string description, IList <string> categories, bool publish)
        {
            // Create an array to hold any categories
            var categories_ = new XmlRPC.Array(categories == null ? 0 : categories.Count);

            if (categories != null)
            {
                var sorted = categories.Distinct().ToList();

                sorted.Sort();

                var ss = new List <Value>();

                sorted.Select(c => new StringValue(c)).ToList().ForEach(i => ss.Add(i));

                categories_.AddRange(ss);
            }

            var service = new Service(this.BlogConnectionInfo.MetaWeblogURL);
            var struct_ = new Struct();

            struct_["title"]       = new StringValue(title);
            struct_["description"] = new StringValue(description);
            struct_["categories"]  = categories_;

            var method = new MethodCall("metaWeblog.editPost");

            method.Parameters.Add(postid);
            method.Parameters.Add(this.BlogConnectionInfo.Username);
            method.Parameters.Add(this.BlogConnectionInfo.Password);
            method.Parameters.Add(struct_);
            method.Parameters.Add(publish);

            service.Cookies = this.BlogConnectionInfo.Cookies;

            var response = service.Execute(method);
            var param    = response.Parameters[0];
            var success  = (BooleanValue)param;

            return(success.Boolean);
        }