public static DedimaniaPlayerArriveReply Parse(object multiCallResultElement) { if (multiCallResultElement == null || !multiCallResultElement.GetType().IsArray) { return(null); } object[] rootElements = (object[])multiCallResultElement; if (rootElements.Length != 1 || rootElements[0].GetType() != typeof(XmlRpcStruct)) { return(null); } XmlRpcStruct replyStruct = (XmlRpcStruct)rootElements[0]; if (!replyStruct.ContainsKey("Options") || !replyStruct.ContainsKey("Nation") || !replyStruct.ContainsKey("TeamName") || !replyStruct.ContainsKey("Login") || !replyStruct.ContainsKey("Aliases")) { return(null); } DedimaniaPlayerArriveReply result = new DedimaniaPlayerArriveReply(); result.Aliases = new List <AliasTextTool>(); result.Options = new List <OptionValueTool>(); result.Login = Convert.ToString(replyStruct["Login"]); result.TeamName = Convert.ToString(replyStruct["TeamName"]); result.Nation = Convert.ToString(replyStruct["Nation"]); return(result); }
internal static TestPlanTotal ToTestPlanTotal(XmlRpcStruct data) { var item = new TestPlanTotal(); item.Total_tc = ToInt(data, "total_tc"); if (data.ContainsKey("type")) { item.Type = (string)data["type"]; } if (data.ContainsKey("name")) { item.Name = (string)data["name"]; } var xdetails = data["details"] as XmlRpcStruct; foreach (string key in xdetails.Keys) { var val = xdetails[key] as XmlRpcStruct; var qty = ToInt(val, "qty"); item.Details.Add(key, qty); } return(item); }
public static DedimaniaWarningsAndTTRReply Parse(object multiCallResultElement) { if (multiCallResultElement == null || !multiCallResultElement.GetType().IsArray) { return(null); } object[] rootObjects = (object[])multiCallResultElement; if (rootObjects.Length == 0 || rootObjects[0].GetType() != typeof(XmlRpcStruct)) { return(null); } XmlRpcStruct rootStruct = (XmlRpcStruct)rootObjects[0]; if (!rootStruct.ContainsKey("globalTTR") || !rootStruct.ContainsKey("methods") || !rootStruct["methods"].GetType().IsArray) { return(null); } DedimaniaWarningsAndTTRReply result = new DedimaniaWarningsAndTTRReply(); result.GlobalTTR = Convert.ToDouble(rootStruct["globalTTR"], new CultureInfo("en-us")); List <DedimaniaWarningsAndTTRElement> warnings = new List <DedimaniaWarningsAndTTRElement>(); foreach (object warningElement in (IEnumerable)rootStruct["methods"]) { warnings.Add(DedimaniaWarningsAndTTRElement.Parse(warningElement)); } result.Methods = warnings.ToArray(); return(result); }
public bool Ping(string name, string url) { bool result = false; try { XmlRpcStruct rpcstruct = Notify(name, url); if (rpcstruct.ContainsKey("flerror")) { //Weblogs.com return false if there is no error //I want to return true, indicating a successful notification result = !(bool)rpcstruct["flerror"]; if (!result) { if (rpcstruct.ContainsKey("message")) { _errorMessage = (string)rpcstruct["message"]; } else { _errorMessage = "Unknown Error"; } } } } catch (Exception ex) { Log.Warn("Error while Ping: " + ex.Message); _errorMessage = "Error: " + ex.Message; } return(result); }
public void StructProperties() { string xml = @"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <struct> <member> <name>member1</name> <value> <i4>1</i4> </value> </member> <member> <name>member2</name> <value> <i4>2</i4> </value> </member> <member> <name>member-3</name> <value> <i4>3</i4> </value> </member> <member> <name>member-4</name> <value> <i4>4</i4> </value> </member> </struct> </value> </param> </params> </methodCall>"; StringReader sr = new StringReader(xml); XmlRpcSerializer serializer = new XmlRpcSerializer(); XmlRpcRequest request = serializer.DeserializeRequest(sr, null); Assert.AreEqual(request.args[0].GetType(), typeof(XmlRpcStruct), "argument is XmlRpcStruct"); XmlRpcStruct xrs = (XmlRpcStruct)request.args[0]; Assert.IsTrue(xrs.Count == 4, "XmlRpcStruct has 4 members"); Assert.IsTrue(xrs.ContainsKey("member1") && (int)xrs["member1"] == 1, "member1"); Assert.IsTrue(xrs.ContainsKey("member2") && (int)xrs["member2"] == 2, "member2"); Assert.IsTrue(xrs.ContainsKey("member-3") && (int)xrs["member-3"] == 3, "member-3"); Assert.IsTrue(xrs.ContainsKey("member-4") && (int)xrs["member-4"] == 4, "member-4"); }
public void NormalFailure() { XmlRpcStruct result = _client.run_keyword("NormalFail", new object[0]); //check continuable or fatal are not set Assert.IsFalse(result.ContainsKey("fatal")); Assert.IsFalse(result.ContainsKey("continuable")); }
public void returnstructure() { XmlRpcStruct result = _client.run_keyword("exec noerror", new object[0]); Assert.IsTrue(result.ContainsKey("return")); Assert.IsTrue(result.ContainsKey("status")); Assert.IsTrue(result.ContainsKey("error")); Assert.IsTrue(result.ContainsKey("traceback")); Assert.IsTrue(result.ContainsKey("output")); }
public void FatalFailure() { XmlRpcStruct result = _client.run_keyword("FatalFail", new object[0]); //check no continuable element Assert.IsFalse(result.ContainsKey("continuable")); //check there is a fatal element Assert.IsTrue(result.ContainsKey("fatal")); //check fatal is true Assert.IsTrue(Convert.ToBoolean(result["fatal"])); }
internal TestCaseFromTestSuite(XmlRpcStruct data) { active = int.Parse((string)data["active"]) == 1; id = toInt(data, "id"); name = (string)data["name"]; version = toInt(data, "version"); tcversion_id = toInt(data, "tcversion_id"); //steps = (string)data["steps"]; //expected_results = (string)data["expected_results"]; external_id = (string)data["tc_external_id"]; testSuite_id = toInt(data, "parent_id"); is_open = int.Parse((string)data["is_open"]) == 1; modification_ts = base.toDate(data, "modification_ts"); updater_id = toInt(data, "updater_id"); execution_type = toInt(data, "execution_type"); summary = (string)data["summary"]; if (data.ContainsKey("details")) { details = (string)data["details"]; } else { details = ""; } author_id = toInt(data, "author_id"); creation_ts = base.toDate(data, "creation_ts"); importance = toInt(data, "importance"); parent_id = toInt(data, "parent_id"); node_type_id = toInt(data, "node_type_id"); node_order = toInt(data, "node_order"); node_table = (string)data["node_table"]; layout = (string)data["layout"]; status = toInt(data, "status"); preconditions = (string)data["preconditions"]; }
//protected TestCaseResultStatus ToExecStatus(XmlRpcStruct data, string name) //{ // var result = TestCaseResultStatus.undefined; // if (data.ContainsKey(name)) // { // var c = ToChar(data, name); // switch (c) // { // case 'f': // case 'F': // result = TestCaseResultStatus.Failed; // break; // case 'b': // case 'B': // result = TestCaseResultStatus.Blocked; // break; // case 'p': // case 'P': // result = TestCaseResultStatus.Passed; // break; // } // } // return result; //} protected static DateTime ToDate(XmlRpcStruct data, string name) { if (data.ContainsKey(name) && DateTime.TryParse((string)data[name], out var n)) { return(n); } return(DateTime.MinValue); }
/// <summary> /// convert a data value to a single char /// </summary> /// <param name="data"></param> /// <param name="name"></param> /// <returns></returns> internal char toChar(XmlRpcStruct data, string name) { if (data.ContainsKey(name) && (data[name] is string)) { string s = (string)(data[name]); return(s[0]); } return('\x00'); }
public static FaultInfo Parse(object multiCallResultElement) { if (multiCallResultElement == null || multiCallResultElement.GetType() != typeof(XmlRpcStruct)) { return(null); } XmlRpcStruct data = (XmlRpcStruct)multiCallResultElement; if (!data.ContainsKey("faultCode") || !data.ContainsKey("faultString")) { return(null); } return(new FaultInfo { FaultCode = Convert.ToString(data["faultCode"]), FaultString = Convert.ToString(data["faultString"]) }); }
protected object MapHashtable(IEnumerator <Node> iter, Type valType, MappingStack mappingStack, MappingAction mappingAction, out Type mappedType) { mappedType = null; var xmlRpcStruct = new XmlRpcStruct(); (mappingStack).Push("struct mapped to XmlRpcStruct"); try { while (iter.MoveNext()) { if (iter.Current is StructMember) { string str = (iter.Current as StructMember).Value; if (xmlRpcStruct.ContainsKey(str) && !IgnoreDuplicateMembers) { throw new XmlRpcInvalidXmlRpcException(mappingStack.MappingType + " contains struct value with duplicate member " + str + " " + StackDump(mappingStack)); } else { iter.MoveNext(); object obj = OnStack(string.Format("member {0}", str), mappingStack, (() => MapValueNode(iter, null, mappingStack, mappingAction))); if (!xmlRpcStruct.ContainsKey(str)) { xmlRpcStruct[str] = obj; } } } else { break; } } } finally { mappingStack.Pop(); } return(xmlRpcStruct); }
private static void verifyKeys(XmlRpcStruct m, String[] keys) { foreach (String key in keys) { if (m.ContainsKey(key) == false) { throw new BoaException("Invalid response from server: response does not contain key '" + key + "'."); } } }
protected static char ToChar(XmlRpcStruct data, string name) { if (data.ContainsKey(name) && data[name] is string) { var s = (string)data[name]; return(s[0]); } return('\x00'); }
internal TestPlanTotal(XmlRpcStruct data) { Total_tc = toInt(data, "total_tc"); if (data.ContainsKey("type")) { Type = (string)data["type"]; } if (data.ContainsKey("name")) { Name = (string)data["name"]; } XmlRpcStruct xdetails = data["details"] as XmlRpcStruct; foreach (string key in xdetails.Keys) { XmlRpcStruct val = xdetails[key] as XmlRpcStruct; int qty = toInt(val, "qty"); Details.Add(key, qty); } }
public static DedimaniaWarningsAndTTRElement Parse(object multiCallResultElement) { if (multiCallResultElement == null || multiCallResultElement.GetType() != typeof(XmlRpcStruct)) { return(null); } XmlRpcStruct warningsStruct = (XmlRpcStruct)multiCallResultElement; if (!warningsStruct.ContainsKey("errors") || !warningsStruct.ContainsKey("methodName") || !warningsStruct.ContainsKey("TTR")) { return(null); } return(new DedimaniaWarningsAndTTRElement { Error = Convert.ToString(warningsStruct["errors"]), MethodName = Convert.ToString(warningsStruct["methodName"]), TTR = Convert.ToDouble(warningsStruct["TTR"], new CultureInfo("en-us")) }); }
private IEnumerable <SearchResult> ParseResponse(XmlRpcStruct response) { var results = new List <SearchResult>(); var ok = ParseStatus(response); if (ok && response.ContainsKey("data") && !(response["data"] is bool)) { results.AddRange(ParseEntry(response["data"] as Array)); } return(results); }
/// <summary> /// 将rpc信息转换为种子信息名称 /// </summary> /// <param name="rpcStruct"></param> /// <returns></returns> public static string ConvertToBittorrentInfoName(XmlRpcStruct rpcStruct) { List <string> keyList = rpcStruct.Keys as List <string>; List <object> valueList = rpcStruct.Values as List <object>; if (rpcStruct.ContainsKey("name")) { string value = valueList[0] as string; return(value); } return(string.Empty); }
/// <summary> /// robust convert a date string /// </summary> /// <param name="data">key value dictionary</param> /// <param name="name">name of field to use</param> /// <returns></returns> internal DateTime toDate(XmlRpcStruct data, string name) { if (data.ContainsKey(name)) { DateTime n; bool good = DateTime.TryParse((string)data[name], out n); if (good) { return(n); } } return(DateTime.MinValue); }
/// <summary> /// Constructor. /// </summary> /// <param name="output">The output from the server request.</param> protected Output(XmlRpcStruct output) { if (output.ContainsKey("status")) { this.StatusString = ( string )output["status"]; } else { this.StatusString = "200 OK"; } this.Status = ConvertStatusToStatusCode(StatusString); this.Seconds = ( double )output["seconds"]; }
/// <summary> /// robust convert a data bit to a bool /// </summary> /// <param name="data"></param> /// <param name="name"></param> /// <returns></returns> internal bool?toBool(XmlRpcStruct data, string name) { if (data.ContainsKey(name)) { object val = data[name]; if (val is string) { bool result; bool good = bool.TryParse(val as string, out result); return(result); } return(data[name] as bool?); } return(null); }
internal static TestCaseFromTestPlan ToTestCaseFromTestPlan(XmlRpcStruct data) { var item = new TestCaseFromTestPlan(); if (data.ContainsKey("active")) { item.active = int.Parse((string)data["active"]) == 1; } item.name = (string)data["name"]; item.tsuite_name = (string)data["tsuite_name"]; item.z = ToInt(data, "z"); item.type = (string)data["type"]; item.execution_order = ToInt(data, "execution_order"); item.exec_id = ToInt(data, "exec_id"); item.tc_id = ToInt(data, "tc_id"); item.tcversion_number = ToInt(data, "tcversion_number"); item.status = (string)data["status"]; item.external_id = (string)data["external_id"]; item.exec_status = (string)data["exec_status"]; item.exec_on_tplan = ToInt(data, "exec_on_tplan"); item.executed = ToInt(data, "executed"); item.feature_id = ToInt(data, "feature_id"); item.assigner_id = ToInt(data, "assigner_id"); item.user_id = ToInt(data, "user_id"); item.active = ToInt(data, "active") == 1; item.version = ToInt(data, "version"); item.testsuite_id = ToInt(data, "testsuite_id"); item.tcversion_id = ToInt(data, "tcversion_id"); //steps = (string)data["steps"]; //expected_results = (string)data["expected_results"]; item.summary = (string)data["summary"]; item.execution_type = ToInt(data, "execution_type"); item.platform_id = ToInt(data, "platform_id"); item.platform_name = (string)data["platform_name"]; item.linked_ts = ToDate(data, "linked_ts"); item.linked_by = ToInt(data, "linked_by"); item.importance = ToInt(data, "importance"); item.execution_run_type = (string)data["execution_run_type"]; item.execution_ts = (string)data["execution_ts"]; item.tester_id = ToInt(data, "tester_id"); item.execution_notes = (string)data["execution_notes"]; item.exec_on_build = ToInt(data, "exec_on_build"); item.assigned_build_id = ToInt(data, "assigned_build_id"); item.urgency = ToInt(data, "urgency"); item.priority = ToInt(data, "priority"); return(item); }
protected static bool?ToBool(XmlRpcStruct data, string name) { if (data.ContainsKey(name)) { var val = data[name]; if (val is string) { bool.TryParse(val as string, out var result); return(result); } return(data[name] as bool?); } return(null); }
internal GeneralResult(XmlRpcStruct data) { operation = (string)data["operation"]; status = (bool)(data["status"]); id = toInt(data, "id"); message = (string)data["message"]; if ((data.ContainsKey("additionalInfo") && (data["additionalInfo"] is XmlRpcStruct))) { additionalInfo = new AdditionalInfo(data["additionalInfo"] as XmlRpcStruct); } else { additionalInfo = null; } }
public static T MapToObject <T>(XmlRpcStruct obj) where T : class { T instance = Activator.CreateInstance <T>(); var destinationType = typeof(T); var members = destinationType.GetFields(); foreach (var member in members) { if (obj.ContainsKey(member.Name)) { member.SetValue(instance, obj[member.Name]); } } return(instance); }
public static T ToObject <T>(this XmlRpcStruct source) where T : class, new() { try { T someObject = new T(); Type someObjectType = someObject.GetType(); foreach (var propertyInfo in someObjectType.GetProperties()) { var xmlRpcAtt = propertyInfo.CustomAttributes.SingleOrDefault(att => att.AttributeType == typeof(CookComputing.XmlRpc.XmlRpcMemberAttribute)); if (xmlRpcAtt == null || !xmlRpcAtt.ConstructorArguments.Any()) { continue; } string xmlRpcAttName = xmlRpcAtt.ConstructorArguments[0].Value.ToString(); if (!source.ContainsKey(xmlRpcAttName)) { continue; } var childStruct = source[xmlRpcAttName] as XmlRpcStruct; if (childStruct != null) { var method = typeof(ParsingExtensions).GetMethod("ToObject"); var genericMethod = method.MakeGenericMethod(propertyInfo.PropertyType); var convertedChild = genericMethod.Invoke(null, new object[] { childStruct }); propertyInfo.SetValue(someObject, convertedChild, null); } else { propertyInfo.SetValue(someObject, source[xmlRpcAttName], null); } } return(someObject); } catch (Exception) { return(null); } }
public static DedimaniaChallengeRaceTimesReply Parse(object multiCallResultElement) { if (multiCallResultElement == null || !multiCallResultElement.GetType().IsArray) { return(null); } object[] rootElements = (object[])multiCallResultElement; if (rootElements.Length != 1 || rootElements[0].GetType() != typeof(XmlRpcStruct)) { return(null); } XmlRpcStruct replyStruct = (XmlRpcStruct)rootElements[0]; if (!replyStruct.ContainsKey("Uid") || !replyStruct.ContainsKey("TotalRaces") || !replyStruct.ContainsKey("TotalPlayers") || !replyStruct.ContainsKey("TimeAttackRaces") || !replyStruct.ContainsKey("TimeAttackPlayers") || !replyStruct.ContainsKey("TimeAttackPlayers") || !replyStruct.ContainsKey("NumberOfChecks") || !replyStruct.ContainsKey("ServerMaxRecords") || !replyStruct.ContainsKey("Records")) { return(null); } return(new DedimaniaChallengeRaceTimesReply { Uid = Convert.ToString(replyStruct["Uid"]), TotalRaces = Convert.ToInt32(replyStruct["TotalRaces"]), TotalPlayers = Convert.ToInt32(replyStruct["TotalPlayers"]), TimeAttackRaces = Convert.ToInt32(replyStruct["TimeAttackRaces"]), TimeAttackPlayers = Convert.ToInt32(replyStruct["TimeAttackPlayers"]), NumberOfChecks = Convert.ToInt32(replyStruct["NumberOfChecks"]), ServerMaxRecords = Convert.ToInt32(replyStruct["ServerMaxRecords"]), Records = ParseRecords(replyStruct["Records"]) }); }
public static T Cast <T>(this object input, Type t = null) { if (input == null) { return(default(T)); } Type target = typeof(T); if (target == typeof(object) && t != null) { target = t; } var result = Activator.CreateInstance(target, false); XmlRpcStruct st = (XmlRpcStruct)input; var d = from source in target.GetMembers().ToList() where source.MemberType == MemberTypes.Property select source; PropertyInfo propertyInfo; foreach (MemberInfo memberInfo in d.ToList()) { if (st.ContainsKey(memberInfo.Name)) { propertyInfo = target.GetProperty(memberInfo.Name); object val = st[memberInfo.Name]; if (st[memberInfo.Name].GetType() == typeof(XmlRpcStruct)) { //if ( == typeof(Person)) val = Cast <object>(val, propertyInfo.PropertyType); } propertyInfo.SetValue(result, val, null); } } return((T)result); }
internal static GeneralResult ToGeneralResult(XmlRpcStruct data) { var item = new GeneralResult(); item.operation = (string)data["operation"]; item.status = (bool)data["status"]; item.id = ToInt(data, "id"); item.message = (string)data["message"]; if (data.ContainsKey("additionalInfo") && data["additionalInfo"] is XmlRpcStruct) { item.additionalInfo = ToAdditionalInfo(data["additionalInfo"] as XmlRpcStruct); } else { item.additionalInfo = null; } return(item); }