public Object get_record(String clazz, String opaqueRef, bool makeResponse) { Db.Table table = db.Tables[clazz]; Type type = table.XapiType; if (!table.Rows.ContainsKey(opaqueRef)) { if (makeResponse) { return(typeof(Response <>).MakeGenericType(type).GetConstructor(new Type[] { typeof(bool), typeof(String[]) }) .Invoke(new Object[] { true, new String[] { Failure.OBJECT_NO_LONGER_EXISTS, opaqueRef } })); } throw new Exception(Failure.OBJECT_NO_LONGER_EXISTS); } Db.Row row = table.Rows[opaqueRef]; Object result = Activator.CreateInstance(type); foreach (string propName in row.Props.Keys) { FieldInfo info = type.GetField(propName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); info.SetValue(result, row.Props[propName].XapiObjectValue); } if (makeResponse) { return(typeof(Response <>).MakeGenericType(type).GetConstructor(new Type[] { type }).Invoke(new Object[] { result })); } return(result); }
public Object get_health_check_config(String clazz, String opaqueRef, bool makeResponse) { Db.Table table = db.Tables[clazz]; if (!table.Rows.ContainsKey(opaqueRef)) { if (makeResponse) { return(new object()); } throw new Exception(Failure.OBJECT_NO_LONGER_EXISTS); } return(table.Rows[opaqueRef].Props["health_check_config"].XapiObjectValue); }
/// <summary> /// Populates the specified Db with the specified XML document. /// </summary> /// <param name="db">The <see cref="Db"/> to be populated.</param> /// <param name="doc">The <see cref="XmlDocument"/> to be read.</param> public void PopulateDbFromXml(Db db, XmlDocument doc) { Util.ThrowIfParameterNull(db, "db"); Util.ThrowIfParameterNull(doc, "doc"); if (db.Tables.Keys.Count > 0) { throw new ArgumentException("Specified Db should be empty.", "db"); } XmlNode dataBaseNode = GetDatabaseNode(doc); IEnumerable hostNodes = GetHostNodes(dataBaseNode); foreach (XmlNode child in dataBaseNode.ChildNodes) { if (child.Name == "table") { string tableName = child.Attributes["name"].Value.ToLower(); Db.Table table = db.Tables.Add(tableName); foreach (XmlNode node in child.ChildNodes) { Db.Row row = table.Rows.Add(node.Attributes["ref"].Value); foreach (XmlAttribute a in node.Attributes) { string name = ParsePropertyName(a.Name, tableName); if (string.IsNullOrEmpty(name)) { continue; } row.Props.Add(name, SanitizePropertyValue(a.Value)); } } if (tableName == "host_metrics" && child.ChildNodes.Count == 0) // host_metrics table used to be empty: see CA-31223 { foreach (XmlNode host in hostNodes) { string opaque_ref = host.Attributes["metrics"].Value; if (table.Rows.ContainsKey(opaque_ref)) { // This doesn't happen with real databases, but for some of the hand-edited ones, we've got duplicate // metrics opaquerefs. continue; } Db.Row row = table.Rows.Add(opaque_ref); row.Props.Add("live", "true"); row.Props.Add("memory_total", (2L * 1024 * 1024 * 1024).ToString()); row.Props.Add("memory_free", (1L * 1024 * 1024 * 1024).ToString()); } } } } foreach (string xenApiType in SimpleProxyMethodParser.AllTypes) { if (!db.Tables.Keys.Contains(xenApiType)) { db.Tables.Add(xenApiType); } } }