예제 #1
0
		public static DateTimeValue XmlToValue(XElement parent)
		{
			DateTime now = DateTime.Now;
			DateTimeValue result;
			if (DateTime.TryParse(parent.Value, out now))
			{
				result = new DateTimeValue(now);
			}
			else
			{
				string s = parent.Value.Trim(new char[]
				{
					'Z'
				});
				DateTime value = DateTime.ParseExact(s, "yyyyMMddTHH:mm:ss", null);
				DateTimeValue dateTimeValue = new DateTimeValue(value);
				result = dateTimeValue;
			}
			return result;
		}
예제 #2
0
		public async Task<string> NewPostAsync(string title, string description, IList<string> categories, bool publish, DateTime? date_created)
		{
			XmlRPC.Array array;
			if (categories == null)
			{
				array = new XmlRPC.Array(0);
			}
			else
			{
				array = new XmlRPC.Array(categories.Count);
				List<Value> ss = new List<Value>();
				(
					from c in categories
					select new StringValue(c)).ToList<StringValue>().ForEach(delegate(StringValue i)
				{
					ss.Add(i);
				});
				array.AddRange(ss);
			}
			Service service = new Service(this.BlogConnectionInfo.MetaWeblogURL);
			Struct @struct = new Struct();
			@struct["title"] = new StringValue(title);
			@struct["description"] = new StringValue(description);
			@struct["categories"] = array;
			if (date_created.HasValue)
			{
				@struct["dateCreated"] = new DateTimeValue(date_created.Value);
				@struct["date_created_gmt"] = new DateTimeValue(date_created.Value.ToUniversalTime());
			}
			MethodCall methodCall = new MethodCall("metaWeblog.newPost");
			methodCall.Parameters.Add(this.BlogConnectionInfo.BlogID);
			methodCall.Parameters.Add(this.BlogConnectionInfo.Username);
			methodCall.Parameters.Add(this.BlogConnectionInfo.Password);
			methodCall.Parameters.Add(@struct);
			methodCall.Parameters.Add(publish);
			service.Cookies = this.BlogConnectionInfo.Cookies;
			MethodResponse methodResponse = await service.ExecuteAsync(methodCall);
			Value value = methodResponse.Parameters[0];
			return ((StringValue)value).String;
		}