private static bool SafeGetDefault <T>(string key, out T dest, T def = default(T), bool useCache = false) { try { XmlRpcValue v = GetParam(key, useCache); if (v == null || !v.IsEmpty) { if (def == null) { dest = default(T); return(false); } dest = def; return(true); } if (typeof(T) == typeof(int)) { dest = (T)(object)v.GetInt(); } else if (typeof(T) == typeof(string)) { dest = (T)(object)v.GetString(); } else if (typeof(T) == typeof(bool)) { dest = (T)(object)v.GetBool(); } else if (typeof(T) == typeof(int)) { dest = (T)(object)v.GetInt(); } else if (typeof(T) == typeof(XmlRpcValue)) { dest = (T)(object)v; } else { // unsupported type dest = default(T); return(false); } return(true); } catch { dest = default(T); return(false); } }
public void set_param(String key, XmlRpcValue value, Func <Dictionary <String, Tuple <String, XmlRpcValue> >, int> notify_task = null) { if (key == "/") //create root { parameters = new Param(value); } else //add branch { String[] namespaces = key.Split('/'); String value_key = namespaces.Last(); namespaces = namespaces.Take(namespaces.Length - 1).ToArray(); Dictionary <String, Param> d = parameters; foreach (String ns in namespaces) //descend tree to the node we are setting { if (ns != "") { if (!d.ContainsKey(ns)) { Param new_parameters = new Param(); d.Add(ns, new_parameters); d = new_parameters; } else { var val = d[ns]; if (val.isNotANamespace) { d[ns] = val = new Param(); } d = val; } } } if (value.Type == XmlRpcValue.ValueType.TypeString) { d[value_key] = new Param(value.GetString()); } else if (value.Type == XmlRpcValue.ValueType.TypeInt) { d[value_key] = new Param(value.GetInt()); } else if (value.Type == XmlRpcValue.ValueType.TypeDouble) { d[value_key] = new Param(value.GetDouble()); } else { d[value_key] = new Param(value); } } if (notify_task != null) { //Boolean updates = compute_param_updates(reg_manager.param_subscribers, key, value) //if(updates) //notify_task(updates); // TODO : ADD NOTIFY TASK DEALY } }