Пример #1
0
 public static DateTimeValue XmlToValue(SXL.XElement parent)
 {
     System.DateTime dt = System.DateTime.Now;
     if (System.DateTime.TryParse(parent.Value, out dt))
     {
         return new DateTimeValue(dt);
     }
     var x = System.DateTime.ParseExact(parent.Value, "yyyyMMddTHH:mm:ss", null);
     var y = new DateTimeValue(x);
     return y;
 }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="categories"></param>
        /// <param name="publish"></param>
        /// <param name="dateCreated"></param>
        /// <returns></returns>
        public async Task<string> NewPost(string title, string description, IList<string> categories, bool publish, System.DateTime? dateCreated)
        {
            Array categoriesArray;

            if (categories == null)
            {
                categoriesArray = new Array(0);
            }
            else
            {
                categoriesArray = new Array(categories.Count);
                categoriesArray.AddRange(categories.Select(c => new StringValue(c)));
            }

            var service = new Service(BlogConnectionInfo.MetaWeblogUrl);

            var _struct = new Struct();
            _struct["title"] = new StringValue(title);
            _struct["description"] = new StringValue(description);
            _struct["categories"] = categoriesArray;
            if (dateCreated.HasValue)
            {
                _struct["dateCreated"] = new DateTimeValue(dateCreated.Value);
                _struct["date_created_gmt"] = new DateTimeValue(dateCreated.Value.ToUniversalTime());

            }
            var method = new MethodCall("metaWeblog.newPost");
            method.Parameters.Add(BlogConnectionInfo.BlogId);
            method.Parameters.Add(BlogConnectionInfo.Username);
            method.Parameters.Add(BlogConnectionInfo.Password);
            method.Parameters.Add(_struct);
            method.Parameters.Add(publish);

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

            return postid;
        }