private XmlRpcValue[] EnsureArraySize(int size) { if (type != XmlRpcType.Empty && type != XmlRpcType.Array) { throw new XmlRpcException($"Cannot convert {type} to array"); } int before = 0; var array = value as XmlRpcValue[]; if (array == null) { array = new XmlRpcValue[size]; } else { before = array.Length; if (array.Length < size) { Array.Resize(ref array, size); } } for (int i = before; i < array.Length; i++) { array[i] = new XmlRpcValue(); } value = array; type = XmlRpcType.Array; return(array); }
public static string GetXmlRpcTypeString(XmlRpcType t) { string ret; switch (t) { case XmlRpcType.tInt32: ret = "integer"; break; case XmlRpcType.tInt64: ret = "i8"; break; case XmlRpcType.tBoolean: ret = "boolean"; break; case XmlRpcType.tString: ret = "string"; break; case XmlRpcType.tDouble: ret = "double"; break; case XmlRpcType.tDateTime: ret = "dateTime"; break; case XmlRpcType.tBase64: ret = "base64"; break; case XmlRpcType.tStruct: ret = "struct"; break; case XmlRpcType.tHashtable: ret = "struct"; break; case XmlRpcType.tArray: ret = "array"; break; case XmlRpcType.tMultiDimArray: ret = "array"; break; case XmlRpcType.tVoid: ret = "void"; break; default: ret = null; break; } return(ret); }
public void StructWithEnum() { Type type = typeof(struct2); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tStruct, rpcType, "struct doesn't map to XmlRpcType.tInvalid"); }
public void RecursiveArrayClass() { Type type = typeof(ExampleWithArray); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tStruct, rpcType); }
public void RecursiveClass() { Type type = typeof(Example); XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tStruct, rpcType); }
/// <summary> /// Default constructor /// </summary> /// <param name="aMethodType"></param> /// <param name="aArtist"></param> /// <param name="aTitle"></param> /// <param name="aFriendsUserName"></param> public XmlRpcParams(XmlRpcType aMethodType, string aArtist, string aTitle, string aFriendsUserName) { MethodType = aMethodType; Artist = aArtist; Title = aTitle; FriendsUserName = aFriendsUserName; }
public void DBNull() { DBNull value = System.DBNull.Value; Type type = value.GetType(); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tStruct, rpcType, "GetXmlRpcType return DBNull as tStruct"); }
static public string GetXmlRpcTypeString(XmlRpcType t) { string ret = null; if (t == XmlRpcType.tInt32) { ret = "integer"; } else if (t == XmlRpcType.tInt64) { ret = "i8"; } else if (t == XmlRpcType.tBoolean) { ret = "boolean"; } else if (t == XmlRpcType.tString) { ret = "string"; } else if (t == XmlRpcType.tDouble) { ret = "double"; } else if (t == XmlRpcType.tDateTime) { ret = "dateTime"; } else if (t == XmlRpcType.tBase64) { ret = "base64"; } else if (t == XmlRpcType.tStruct) { ret = "struct"; } else if (t == XmlRpcType.tHashtable) { ret = "struct"; } else if (t == XmlRpcType.tArray) { ret = "array"; } else if (t == XmlRpcType.tMultiDimArray) { ret = "array"; } else if (t == XmlRpcType.tVoid) { ret = "void"; } else { ret = null; } return(ret); }
public void DBNull() { DBNull value = System.DBNull.Value; Type type = value.GetType(); XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tInvalid, rpcType, "GetXmlRpcType return DBNull as tInvalid"); }
public void NullableDateTime() { Type type = typeof(DateTime?); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tDateTime, rpcType, "DateTime? doesn't map to XmlRpcType.tDateTime"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "dateTime", "DateTime? doesn't map to 'dateTime'"); }
public void JaggedIntArray() { Type type = typeof(Int32[][]); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tArray, rpcType, "Int32[] doesn't map to XmlRpcType.tArray"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "array", "Int32[] doesn't map to 'array'"); }
public void Array() { Type type = typeof(Array); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tArray, rpcType, "Array doesn't map to XmlRpcType.tArray"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "array", "Array doesn't map to 'array'"); }
public void String() { Type type = typeof(string); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tString, rpcType, "String doesn't map to XmlRpcType.tString"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "string", "String doesn't map to 'string'"); }
public void XmlRpcDouble() { Type type = typeof(double?); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tDouble, rpcType, "XmlRpcDouble doesn't map to XmlRpcType.tDouble"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "double", "XmlRpcDouble doesn't map to 'double'"); }
public void XmlRpcBoolean() { Type type = typeof(bool?); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tBoolean, rpcType, "XmlRpcBoolean doesn't map to XmlRpcType.tBoolean"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "boolean", "XmlRpcBoolean doesn't map to 'boolean'"); }
public void XmlRpcStruct() { Type type = typeof(XmlRpcStruct); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tHashtable, rpcType, "XmlRpcStruct doesn't map to XmlRpcType.tHashtable"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "struct", "XmlRpcStruct doesn't map to 'struct'"); }
private static XmlRpcValue GetParamTypeChecked(string key, XmlRpcType expectedType, bool useCache = false) { var result = GetParamChecked(key, useCache); if (result.Type != expectedType) { throw new XmlRpcException($"{expectedType} response expected"); } return(result); }
public void Void() { Type type = typeof(void); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tVoid, rpcType, "void doesn't map to XmlRpcType.tVoid"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "void", "void doesn't map to 'void'"); }
public void NullableIn64() { Type type = typeof(long?); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tInt64, rpcType, "long? doesn't map to XmlRpcType.tInt64"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "i8", "long? doesn't map to 'i8'"); }
private static async Task <XmlRpcValue> GetParamTypeCheckedAsync(string key, XmlRpcType expectedType, bool useCache = false) { var result = await GetParamCheckedAsync(key, useCache).ConfigureAwait(false); if (result.Type != expectedType) { throw new XmlRpcException($"{expectedType} response expected"); } return(result); }
public void XmlRpcInt() { Type type = typeof(int?); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tInt32, rpcType, "XmlRpcInt doesn't map to XmlRpcType.tInt32"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "integer", "XmlRpcInt doesn't map to 'integer'"); }
public void NullableStruct() { Type type = typeof(TestStruct?); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tStruct, rpcType, "TestStruct? doesn't map to XmlRpcType.tStruct"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "struct", "TestStruct? doesn't map to 'struct'"); }
public void Base64() { Type type = typeof(byte[]); XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tBase64, rpcType, "Byte[] doesn't map to XmlRpcType.tBase64"); string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "base64", "Byte[] doesn't map to 'base64'"); }
public void Int64() { Type type = typeof(long); XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tInt64, rpcType, "Int64 doesn't map to XmlRpcType.tInt64"); string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "i8", "Int64 doesn't map to 'i8'"); }
public void MultiDimIntArray() { Type type = typeof(Int32[, ]); XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tMultiDimArray, rpcType, "Int32[] doesn't map to XmlRpcType.tMultiDimArray"); string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "array", "Int32['] doesn't map to 'array'"); }
public void Struct() { Type type = typeof(struct1); XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tStruct, rpcType, "struct doesn't map to XmlRpcType.tStruct"); string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "struct", "struct doesn't map to 'struct'"); }
public void XmlRpcDateTime() { Type type = typeof(XmlRpcDateTime); XmlRpcType rpcType = XmlRpcServiceInfo.GetXmlRpcType(type); Assert.AreEqual(XmlRpcType.tDateTime, rpcType, "XmlRpcDateTime doesn't map to XmlRpcType.tDateTime"); string rpcString = XmlRpcServiceInfo.GetXmlRpcTypeString(type); Assert.AreEqual(rpcString, "dateTime", "XmlRpcDateTime doesn't map to 'dateTime'"); }
private static async Task <XmlRpcValue> GetParamTypeCheckedAsync(string key, XmlRpcType expectedType, bool useCache = false) { var result = new XmlRpcValue(); if (!await GetParamAsync(key, result, useCache)) { throw new RosException($"Getting ROS param '{key}' failed."); } if (result.Type != expectedType) { throw new XmlRpcException($"{expectedType} response expected"); } return(result); }
private static XmlRpcValue GetParamTypeChecked(string key, XmlRpcType expectedType, bool useCache = false) { var result = GetParam(key, useCache); if (result == null) { throw new RosException($"Getting ROS param '{key}' failed."); } if (result.Type != expectedType) { throw new XmlRpcException($"{expectedType} response expected"); } return(result); }
public static string GetXmlRpcTypeString(XmlRpcType t) { switch (t) { case XmlRpcType.tInt32: return("integer"); case XmlRpcType.tInt64: return("i8"); case XmlRpcType.tBoolean: return("boolean"); case XmlRpcType.tString: return("string"); case XmlRpcType.tDouble: return("double"); case XmlRpcType.tDateTime: return("dateTime"); case XmlRpcType.tBase64: return("base64"); case XmlRpcType.tStruct: return("struct"); case XmlRpcType.tHashtable: return("struct"); case XmlRpcType.tArray: return("array"); case XmlRpcType.tMultiDimArray: return("array"); case XmlRpcType.tVoid: return("void"); case XmlRpcType.tInvalid: case XmlRpcType.tNil: default: return(null); } }
/// <summary> /// Fills the parameter properties of this method call with the information contained in the XElement. /// </summary> /// <typeparam name="T">The XmlRpcType of the parameter.</typeparam> /// <param name="paramsElement">The XElement containing the information.</param> /// <param name="param">The parameter.</param> /// <returns>Whether it was successful or not.</returns> protected static bool parseCallParamXml <T>(XElement paramsElement, XmlRpcType <T> param) { if (!paramsElement.HasElements) { return(false); } XElement paramElement = paramsElement.Elements().First(); if (!isValidParamElement(paramElement)) { return(false); } paramElement.Remove(); return(param.ParseXml(paramElement.Elements().First())); }
static public string GetXmlRpcTypeString(XmlRpcType t) { string ret = null; if (t == XmlRpcType.tInt32) ret = "integer"; else if (t == XmlRpcType.tBoolean) ret = "boolean"; else if (t == XmlRpcType.tString) ret = "string"; else if (t == XmlRpcType.tDouble) ret = "double"; else if (t == XmlRpcType.tDateTime) ret = "dateTime"; else if (t == XmlRpcType.tBase64) ret = "base64"; else if (t == XmlRpcType.tStruct) ret = "struct"; else if (t == XmlRpcType.tHashtable) ret = "struct"; else if (t == XmlRpcType.tArray) ret = "array"; else if (t == XmlRpcType.tMultiDimArray) ret = "array"; else if (t == XmlRpcType.tVoid) ret = "void"; else ret = null; return ret; }
/// <summary> /// Formats an XML post header for last.fm's api access /// </summary> /// <param name="aMethodType">Is a type of the method to be called: e.g. LoveTrack, BanTrack, etc</param> /// <param name="aUser">The users last.fm username.</param> /// <param name="aChallenge">The current UNIX timestamp.</param> /// <param name="aAuth">The authentication token, a 32-byte ASCII hexadecimal representation of the MD5 hash of the users last.fm password and the timestamp: md5(md5(password) + timestamp)</param> /// <param name="aArtist">The artist to get love/ban.</param> /// <param name="aTitle">The track title to get love/ban.</param> /// <param name="aFriendsUserName">The friends name to remove.</param> /// <returns>The XML data in string format</returns> private string BuildXmlRpcRequest(XmlRpcType aMethodType, string aUser, string aChallenge, string aAuth, string aArtist, string aTitle, string aFriendsUserName) { string ResultXml = String.Empty; List<string> AllParams = new List<string>(5); try { if (!String.IsNullOrEmpty(aUser)) { AllParams.Add(aUser); } if (!String.IsNullOrEmpty(aChallenge)) { AllParams.Add(aChallenge); } if (!String.IsNullOrEmpty(aAuth)) { AllParams.Add(aAuth); } if (aMethodType == XmlRpcType.removeFriend) { if (!String.IsNullOrEmpty(aFriendsUserName)) { AllParams.Add(aFriendsUserName); } } else { if (!String.IsNullOrEmpty(aArtist)) { AllParams.Add(aArtist); } if (!String.IsNullOrEmpty(aTitle)) { AllParams.Add(aTitle); } } using (MemoryStream memoryStream = new MemoryStream()) { XmlWriterSettings settings = new XmlWriterSettings(); //settings.Indent = true; //settings.IndentChars = (" "); settings.CloseOutput = true; // If i use Encodings.UTF8 the BOM will be prepended... settings.Encoding = new UTF8Encoding(false); using (XmlWriter writer = XmlWriter.Create(memoryStream, settings)) { writer.WriteStartElement("methodCall"); writer.WriteElementString("methodName", aMethodType.ToString()); writer.WriteStartElement("params"); foreach (string singleParam in AllParams) { writer.WriteStartElement("param"); writer.WriteStartElement("value"); writer.WriteElementString("string", singleParam); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); } ResultXml = Encoding.UTF8.GetString(memoryStream.GetBuffer()); Log.Debug("AudioscrobblerUtils: Successfully created XMLRPC call for method {0}", aMethodType.ToString()); } } catch (Exception ex) { Log.Error("AudioscrobblerUtils: Error in BuildXmlRpcRequest - {0}", ex.Message); } return ResultXml; }
public static string GetXmlRpcTypeString(XmlRpcType t) { switch (t) { case XmlRpcType.tInt32: return "integer"; case XmlRpcType.tInt64: return "i8"; case XmlRpcType.tBoolean: return "boolean"; case XmlRpcType.tString: return "string"; case XmlRpcType.tDouble: return "double"; case XmlRpcType.tDateTime: return "dateTime"; case XmlRpcType.tBase64: return "base64"; case XmlRpcType.tStruct: return "struct"; case XmlRpcType.tHashtable: return "struct"; case XmlRpcType.tArray: return "array"; case XmlRpcType.tMultiDimArray: return "array"; case XmlRpcType.tVoid: return "void"; default: return null; } }