internal void EnsureSystemWebSectionIsPresent() { if (!IsSystemWebSectionPresent()) { Debug.Assert(Document != null); XmlNode configSection = Document.SelectSingleNode("configuration"); if (configSection == null) { throw new Exception(SR.GetString(SR.WebConfig_FileLoadException)); } if (configSection.SelectSingleNode("system.web") == null) { XmlElement newWebSection = Document.CreateElement("system.web"); configSection.AppendChild(newWebSection); } XmlNode webSection = Document.SelectSingleNode("configuration/system.web"); if (webSection.SelectSingleNode("deviceFilters") == null) { XmlElement newFilters = Document.CreateElement("deviceFilters"); webSection.AppendChild(newFilters); } } }
// Cause the DeviceFilterNode to display correctly when inserted // in a combo box. public override String ToString() { if (Name == null || Name.Length == 0) { return(SR.GetString(SR.DeviceFilter_DefaultChoice)); } return(Name); }
internal DeviceFilterNode(WebConfigManager webConfig) : base() { _webConfig = webConfig; _xmlNode = webConfig.Document.CreateElement("filter"); Name = SR.GetString(SR.DeviceFilterNode_DefaultFilterName); Mode = DeviceFilterMode.Compare; }
internal void EnsureWebConfigIsPresent() { if (!File.Exists(_path)) { // We throw our own exception type so we can easily tell // between a corrupt web.config and a missing one. throw new FileNotFoundException( SR.GetString(SR.WebConfig_FileNotFoundException) ); } }
private void LoadDocument() { try { Document.Load(_path); } catch (Exception ex) { Debug.Fail(ex.ToString()); throw new Exception(SR.GetString(SR.WebConfig_FileLoadException)); } }
internal XmlElement FindFilterSection(XmlDocument document, bool createIfNotExists) { XmlNode configSection = FindXmlNode(document, "configuration"); if (configSection == null) { if (createIfNotExists) { throw new Exception(SR.GetString(SR.WebConfig_FileLoadException)); } return(null); } XmlElement webSection = FindXmlNode(configSection, "system.web"); if (webSection == null) { if (createIfNotExists) { webSection = Document.CreateElement("system.web"); configSection.AppendChild(webSection); } return(null); } XmlElement filters = FindXmlNode(webSection, "deviceFilters"); if (filters == null) { if (createIfNotExists) { filters = Document.CreateElement("deviceFilters"); webSection.AppendChild(filters); } return(null); } return(filters); }
internal ArrayList ReadDeviceFilters() { EnsureWebConfigIsPresent(); // Reload the document everytime we read filters LoadDocument(); XmlNode filters = FindFilterSection(Document, false); ArrayList DeviceFilterList = new ArrayList(); if (filters != null) { Hashtable filterTable = new Hashtable(); foreach (XmlNode childNode in filters.ChildNodes) { if (childNode.Name != null && childNode.Name.Equals("filter")) { // Ignore the empty filter. if (childNode.Attributes["name"] == null || childNode.Attributes["name"].Value == null || childNode.Attributes["name"].Value.Length == 0) { continue; } String filterName = childNode.Attributes["name"].Value; if (filterTable[filterName] != null) { throw new Exception(SR.GetString(SR.DeviceFilterEditorDialog_DuplicateNames)); } DeviceFilterNode node = new DeviceFilterNode(this, childNode); DeviceFilterList.Add(node); filterTable[filterName] = true; } } } return(DeviceFilterList); }