예제 #1
0
		public async Task<MediaObjectInfo> NewMediaObjectAsync(string name, string type, byte[] bits)
		{
			Service service = new Service(this.BlogConnectionInfo.MetaWeblogURL);
			Struct @struct = new Struct();
			@struct["name"] = new StringValue(name);
			@struct["type"] = new StringValue(type);
			@struct["bits"] = new Base64Data(bits);
			MethodCall methodCall = new MethodCall("metaWeblog.newMediaObject");
			methodCall.Parameters.Add(this.BlogConnectionInfo.BlogID);
			methodCall.Parameters.Add(this.BlogConnectionInfo.Username);
			methodCall.Parameters.Add(this.BlogConnectionInfo.Password);
			methodCall.Parameters.Add(@struct);
			service.Cookies = this.BlogConnectionInfo.Cookies;
			MethodResponse methodResponse = await service.ExecuteAsync(methodCall);
			Value value = methodResponse.Parameters[0];
			Struct struct2 = (Struct)value;
			return new MediaObjectInfo
			{
				URL = struct2.Get<StringValue>("url", StringValue.NullString).String
			};
		}
예제 #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;
		}
예제 #3
0
		public async Task<bool> EditPostAsync(string postid, string title, string description, IList<string> categories, bool publish)
		{
			XmlRPC.Array array = new XmlRPC.Array((categories == null) ? 0 : categories.Count);
			if (categories != null)
			{
				List<string> list = categories.Distinct<string>().ToList<string>();
				list.Sort();
				List<Value> ss = new List<Value>();
				(
					from c in list
					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;
			MethodCall methodCall = new MethodCall("metaWeblog.editPost");
			methodCall.Parameters.Add(postid);
			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];
			BooleanValue booleanValue = (BooleanValue)value;
			return booleanValue.Boolean;
		}
예제 #4
0
		public static Value ParseXml(XElement value_el)
		{
			if (value_el.Name != "value")
			{
				string message = string.Format("XML Element should have name \"value\" instead found \"{0}\"", value_el.Name);
				throw new XmlRPCException();
			}
			string value = value_el.Value;
			Value result;
			if (value_el.HasElements)
			{
				XElement xElement = value_el.Elements().First<XElement>();
				string text = xElement.Name.ToString();
				if (text == Array.TypeString)
				{
					result = Array.XmlToValue(xElement);
				}
				else
				{
					if (text == Struct.TypeString)
					{
						result = Struct.XmlToValue(xElement);
					}
					else
					{
						if (text == StringValue.TypeString)
						{
							result = StringValue.XmlToValue(xElement);
						}
						else
						{
							if (text == DoubleValue.TypeString)
							{
								result = DoubleValue.XmlToValue(xElement);
							}
							else
							{
								if (text == Base64Data.TypeString)
								{
									result = Base64Data.XmlToValue(xElement);
								}
								else
								{
									if (text == DateTimeValue.TypeString)
									{
										result = DateTimeValue.XmlToValue(xElement);
									}
									else
									{
										if (text == IntegerValue.TypeString || text == IntegerValue.AlternateTypeString)
										{
											result = IntegerValue.XmlToValue(xElement);
										}
										else
										{
											if (text != BooleanValue.TypeString)
											{
												string message = string.Format("Unsupported type: {0}", text);
												throw new XmlRPCException(message);
											}
											result = BooleanValue.XmlToValue(xElement);
										}
									}
								}
							}
						}
					}
				}
			}
			else
			{
				result = new StringValue(value);
			}
			return result;
		}