private static FilterMangler LoadMangler(SqlSearchSettings settings, XmlElement element) { if (settings == null) { throw new ArgumentNullException("settings"); } if (element == null) { throw new ArgumentNullException("element"); } // get the type... string manglerId = XmlHelper.GetAttributeString(element, "manglerId", OnNotFound.ThrowException); if (manglerId == null) { throw new InvalidOperationException("'manglerId' is null."); } if (manglerId.Length == 0) { throw new InvalidOperationException("'manglerId' is zero-length."); } // get the type... Type type = XmlHelper.GetAttributeType(element, "type", OnNotFound.ThrowException); if (type == null) { throw new InvalidOperationException("type is null."); } // create... ISqlFilterMangler filter = (ISqlFilterMangler)CreateInstance(type); if (filter == null) { throw new InvalidOperationException("filter is null."); } // get the settings element... XmlElement settingsElement = (XmlElement)element.SelectSingleNode("Settings"); if (settingsElement == null) { throw new InvalidOperationException("settingsElement is null."); } // load... SimpleXmlPropertyBag bag = SimpleXmlPropertyBag.Load(settingsElement, typeof(SimpleXmlPropertyBag)); if (bag == null) { throw new InvalidOperationException("bag is null."); } // Lets deserialize the bag into the control filter.DeserializeSqlSearchSettings(bag); FilterMangler mangler = new FilterMangler(manglerId, bag, filter); // patch... //mangler.DeserializeSqlSearchSettings(bag); // return... return(mangler); }
public static SqlSearchSettings FromXml(XmlDocument doc) { if (doc == null) { throw new ArgumentNullException("doc"); } // root... XmlElement rootElement = (XmlElement)doc.SelectSingleNode(RootElementName); if (rootElement == null) { throw new InvalidOperationException("The root element was not found."); } // create... Type type = XmlHelper.GetAttributeType(rootElement, "type", OnNotFound.ThrowException); if (type == null) { throw new InvalidOperationException("type is null."); } // create one... SqlSearchSettings newSettings = (SqlSearchSettings)CreateInstance(type); if (newSettings == null) { throw new InvalidOperationException("newSettings is null."); } // load the entity type... type = XmlHelper.GetElementType(rootElement, "EntityType", OnNotFound.ThrowException, true); if (type == null) { throw new InvalidOperationException("type is null."); } newSettings._entityType = EntityType.GetEntityType(type, OnNotFound.ThrowException); // load the manglers... foreach (XmlElement manglerElement in rootElement.SelectNodes("Manglers/Mangler")) { FilterMangler mangler = LoadMangler(newSettings, manglerElement); if (mangler == null) { throw new InvalidOperationException("mangler is null."); } // add... newSettings.Manglers.Add(mangler); } // load the settings... XmlElement settingsElement = (XmlElement)rootElement.SelectSingleNode("Settings"); if (settingsElement == null) { throw new InvalidOperationException("settingsElement is null."); } newSettings.LoadSettings(settingsElement); // deser... newSettings.OnAfterXmlDeserialization(); // return... return(newSettings); }