public static DataTypeDefinition Import(XmlNode xmlData) { string _name = xmlData.Attributes["Name"].Value; string _id = xmlData.Attributes["Id"].Value; string _def = xmlData.Attributes["Definition"].Value; //Make sure that the dtd is not already present if (!CMSNode.IsNode(new Guid(_def)) ) { BusinessLogic.User u = umbraco.BusinessLogic.User.GetCurrent(); if (u == null) { u = BusinessLogic.User.GetUser(0); } cms.businesslogic.datatype.controls.Factory f = new umbraco.cms.businesslogic.datatype.controls.Factory(); DataTypeDefinition dtd = MakeNew(u, _name, new Guid(_def)); var dataType = f.DataType(new Guid(_id)); if (dataType == null) { throw new NullReferenceException("Could not resolve a data type with id " + _id); } dtd.DataType = dataType; dtd.Save(); //add prevalues foreach (XmlNode xmlPv in xmlData.SelectNodes("PreValues/PreValue")) { XmlAttribute val = xmlPv.Attributes["Value"]; if (val != null) { PreValue p = new PreValue(0, 0, val.Value); p.DataTypeId = dtd.Id; p.Save(); } } return(dtd); } return(null); }
public static DataTypeDefinition Import(XmlNode xmlData) { string _name = xmlData.Attributes["Name"].Value; string _id = xmlData.Attributes["Id"].Value; string _def = xmlData.Attributes["Definition"].Value; //Make sure that the dtd is not already present if (!CMSNode.IsNode(new Guid(_def)) ) { BasePages.UmbracoEnsuredPage uep = new umbraco.BasePages.UmbracoEnsuredPage(); BusinessLogic.User u = uep.getUser(); if (u == null) { u = BusinessLogic.User.GetUser(0); } cms.businesslogic.datatype.controls.Factory f = new umbraco.cms.businesslogic.datatype.controls.Factory(); DataTypeDefinition dtd = MakeNew(u, _name, new Guid(_def)); dtd.DataType = f.DataType(new Guid(_id)); dtd.Save(); //add prevalues foreach (XmlNode xmlPv in xmlData.SelectNodes("PreValues/PreValue")) { XmlAttribute val = xmlPv.Attributes["Value"]; if (val != null && !string.IsNullOrEmpty(val.Value)) { PreValue p = new PreValue(0, 0, val.Value); p.DataTypeId = dtd.Id; p.Save(); } } return(dtd); } return(null); }