private Resource LoadResource(System.Xml.XmlNode node, Resource parent) { System.Diagnostics.Debug.Assert(node.Name == "resource"); /// get resource type string resourceTypeName = node.Attributes["type"].Value; SNAP.Resources.ResourceType resourceType = _resourceTypes[resourceTypeName]; /// get resource name string resourceName = node.Attributes["name"].Value; /// get resource id /// if the id is not available (for instance when importing an externallay generated resource) /// generate a new one instead Guid guid = (node.Attributes["id"] != null) ? (new Guid(node.Attributes["id"].Value)) : (Guid.NewGuid()); /// create the new resource Resource resource = new Resource(guid, resourceType, resourceName); /// add field values foreach (System.Xml.XmlNode fieldNode in node.SelectNodes("field")) { string fieldName = fieldNode.Attributes["name"].Value; FieldType fieldType = resource.ResourceType.Fields[fieldName]; FieldValueList fieldValue = null; if (!resource.Fields.ContainsKey(fieldName)) { fieldValue = new FieldValueList(fieldType); resource.Fields.Add(fieldName, fieldValue); } else { fieldValue = resource.Fields[fieldName]; } IScriptableValue value = null; switch (fieldType.Type) { case "internal_ref": value = new InternalRefValue(fieldNode.InnerText); break; case "external_ref": value = new ExternalRefValue(fieldNode.InnerText); break; case "text": value = new TextValue(fieldNode.InnerText); break; default: System.Diagnostics.Debug.Fail(fieldType.Type + " is not a recognized field type"); break; } fieldValue.Values.Add(value); } /// add this node to it's parent if (parent == null) { string family = node["family"].InnerText; parent = _resourceList[family]; } parent.Children.Add(resource); return(resource); }
private Resource LoadResource(System.Xml.XmlNode node, Resource parent) { System.Diagnostics.Debug.Assert(node.Name == "resource"); /// get resource type string resourceTypeName = node.Attributes["type"].Value; SNAP.Resources.ResourceType resourceType = _resourceTypes[resourceTypeName]; /// get resource name string resourceName = node.Attributes["name"].Value; /// get resource id /// if the id is not available (for instance when importing an externallay generated resource) /// generate a new one instead Guid guid = (node.Attributes["id"] != null) ? (new Guid(node.Attributes["id"].Value)) : (Guid.NewGuid()); /// create the new resource Resource resource = new Resource(guid, resourceType, resourceName); /// add field values foreach (System.Xml.XmlNode fieldNode in node.SelectNodes("field")) { string fieldName = fieldNode.Attributes["name"].Value; FieldType fieldType = resource.ResourceType.Fields[fieldName]; FieldValueList fieldValue = null; if (!resource.Fields.ContainsKey(fieldName)) { fieldValue = new FieldValueList(fieldType); resource.Fields.Add(fieldName, fieldValue); } else { fieldValue = resource.Fields[fieldName]; } IScriptableValue value = null; switch (fieldType.Type) { case "internal_ref": value = new InternalRefValue (fieldNode.InnerText); break; case "external_ref": value = new ExternalRefValue (fieldNode.InnerText); break; case "text": value = new TextValue (fieldNode.InnerText); break; default: System.Diagnostics.Debug.Fail (fieldType.Type + " is not a recognized field type"); break; } fieldValue.Values.Add(value); } /// add this node to it's parent if (parent == null) { string family = node["family"].InnerText; parent = _resourceList[family]; } parent.Children.Add(resource); return resource; }