public void ReadOnlyCollection_AttemptingToModifyCollection_Throws() { var nameValueCollection = new ReadOnlyNameValueCollection(); Assert.Throws<NotSupportedException>(() => nameValueCollection.Add("name", "value")); Assert.Throws<NotSupportedException>(() => nameValueCollection.Set("name", "value")); Assert.Throws<NotSupportedException>(() => nameValueCollection.Remove("name")); Assert.Throws<NotSupportedException>(() => nameValueCollection.Clear()); }
internal static object CreateStatic(object parent, XmlNode section, string keyAttriuteName, string valueAttributeName) { ReadOnlyNameValueCollection result; // start result off as a shallow clone of the parent if (parent == null) result = new ReadOnlyNameValueCollection(StringComparer.OrdinalIgnoreCase); else { ReadOnlyNameValueCollection parentCollection = (ReadOnlyNameValueCollection)parent; result = new ReadOnlyNameValueCollection(parentCollection); } // process XML HandlerBase.CheckForUnrecognizedAttributes(section); foreach (XmlNode child in section.ChildNodes) { // skip whitespace and comments if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child)) continue; // handle <set>, <remove>, <clear> tags if (child.Name == "add") { String key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName); String value = HandlerBase.RemoveRequiredAttribute(child, valueAttributeName, true/*allowEmptyString*/); HandlerBase.CheckForUnrecognizedAttributes(child); result[key] = value; } else if (child.Name == "remove") { String key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName); HandlerBase.CheckForUnrecognizedAttributes(child); result.Remove(key); } else if (child.Name.Equals("clear")) { HandlerBase.CheckForUnrecognizedAttributes(child); result.Clear(); } else { HandlerBase.ThrowUnrecognizedElement(child); } } result.SetReadOnly(); return result; }
internal static object CreateStatic(object parent, XmlNode section, string keyAttriuteName, string valueAttributeName) { ReadOnlyNameValueCollection result; if (parent == null) { result = new ReadOnlyNameValueCollection(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture)); } else { result = new ReadOnlyNameValueCollection((ReadOnlyNameValueCollection)parent); } HandlerBase.CheckForUnrecognizedAttributes(section); foreach(XmlNode child in section.ChildNodes) { if(HandlerBase.IsIgnorableAlsoCheckForNonElement(child)) continue; if (child.Name == "add") { string key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName); string val = HandlerBase.RemoveRequiredAttribute(child, valueAttributeName, true); HandlerBase.CheckForUnrecognizedAttributes(child); result[key] = val; } else if (child.Name == "remove") { string key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName); HandlerBase.CheckForUnrecognizedAttributes(child); result.Remove(key); } else if (child.Name.Equals("clear")) { HandlerBase.CheckForUnrecognizedAttributes(child); result.Clear(); } else { HandlerBase.ThrowUnrecognizedElement(child); } } result.SetReadOnly(); return result; }
internal RenderFormatImpl(OnDemandProcessingContext odpContext) { m_odpContext = odpContext; m_emptyDeviceInfo = new ReadOnlyNameValueCollection(new NameValueCollection(0)); if (m_odpContext.TopLevelContext.ReportContext.RSRequestParameters != null) { NameValueCollection renderingParameters = m_odpContext.TopLevelContext.ReportContext.RSRequestParameters.RenderingParameters; if (renderingParameters != null) { m_deviceInfo = new ReadOnlyNameValueCollection(renderingParameters); } } m_format = NormalizeRenderFormat(m_odpContext.TopLevelContext.ReportContext, out m_isInteractiveFormat); if (m_deviceInfo == null) { m_deviceInfo = m_emptyDeviceInfo; } }
public ReadOnlyNameValueCollection(ReadOnlyNameValueCollection value) : base(value) { }
private SiteMapNode GetNodeFromXmlNode(XmlNode xmlNode, Queue queue) { SiteMapNode node = null; // static nodes string title = null, url = null, description = null, roles = null, resourceKey = null; // Url attribute is NOT required for a xml node. HandlerBase.GetAndRemoveStringAttribute(xmlNode, "url", ref url); HandlerBase.GetAndRemoveStringAttribute(xmlNode, "title", ref title); HandlerBase.GetAndRemoveStringAttribute(xmlNode, "description", ref description); HandlerBase.GetAndRemoveStringAttribute(xmlNode, "roles", ref roles); HandlerBase.GetAndRemoveStringAttribute(xmlNode, "resourceKey", ref resourceKey); // Do not add the resourceKey if the resource is not valid. if (!String.IsNullOrEmpty(resourceKey) && !ValidateResource(ResourceKey, resourceKey + ".title")) { resourceKey = null; } HandlerBase.CheckForbiddenAttribute(xmlNode, _securityTrimmingEnabledAttrName); NameValueCollection resourceKeyCollection = null; bool allowImplicitResourceAttribute = String.IsNullOrEmpty(resourceKey); HandleResourceAttribute(xmlNode, ref resourceKeyCollection, "title", ref title, allowImplicitResourceAttribute); HandleResourceAttribute(xmlNode, ref resourceKeyCollection, "description", ref description, allowImplicitResourceAttribute); ArrayList roleList = new ArrayList(); if (roles != null) { int foundIndex = roles.IndexOf('?'); if (foundIndex != -1) { throw new ConfigurationErrorsException( SR.GetString(SR.Auth_rule_names_cant_contain_char, roles[foundIndex].ToString(CultureInfo.InvariantCulture)), xmlNode); } foreach (string role in roles.Split(_seperators)) { string trimmedRole = role.Trim(); if (trimmedRole.Length > 0) { roleList.Add(trimmedRole); } } } roleList = ArrayList.ReadOnly(roleList); String key = null; // Make urls absolute. if (!String.IsNullOrEmpty(url)) { // URL needs to be trimmed. VSWhidbey 411041 url = url.Trim(); if (!UrlPath.IsAbsolutePhysicalPath(url)) { if (UrlPath.IsRelativeUrl(url)) { url = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, url); } } // VSWhidbey 418056, Reject any suspicious or mal-formed Urls. string decodedUrl = HttpUtility.UrlDecode(url); if (!String.Equals(url, decodedUrl, StringComparison.Ordinal)) { throw new ConfigurationErrorsException( SR.GetString(SR.Property_Had_Malformed_Url, "url", url), xmlNode); } key = url.ToLowerInvariant(); } else { key = Guid.NewGuid().ToString(); } // attribute collection does not contain pre-defined properties like title, url, etc. ReadOnlyNameValueCollection attributeCollection = new ReadOnlyNameValueCollection(); attributeCollection.SetReadOnly(false); foreach (XmlAttribute attribute in xmlNode.Attributes) { string value = attribute.Value; HandleResourceAttribute(xmlNode, ref resourceKeyCollection, attribute.Name, ref value, allowImplicitResourceAttribute); attributeCollection[attribute.Name] = value; } attributeCollection.SetReadOnly(true); node = new SiteMapNode(this, key, url, title, description, roleList, attributeCollection, resourceKeyCollection, resourceKey); node.ReadOnly = true; foreach (XmlNode subNode in xmlNode.ChildNodes) { if (subNode.NodeType != XmlNodeType.Element) { continue; } queue.Enqueue(node); queue.Enqueue(subNode); } return(node); }
internal static Object Create(Object parent, XmlNode section, String keyName, String valueName) { ReadOnlyNameValueCollection coll; String key, value; // Create the name/value collection for the result. if(parent != null) { coll = new ReadOnlyNameValueCollection ((NameValueCollection)parent); } else { coll = new ReadOnlyNameValueCollection(); } // Must not be any attributes remaining on the section node. if(section.Attributes.Count != 0) { throw new ConfigurationException (S._("Config_UnrecognizedAttribute"), section); } // Process the child nodes. foreach(XmlNode node in section.ChildNodes) { // Ignore comments and white space. if(node.NodeType == XmlNodeType.Comment || node.NodeType == XmlNodeType.Whitespace || node.NodeType == XmlNodeType.SignificantWhitespace) { continue; } // Must be an element node. if(node.NodeType != XmlNodeType.Element) { throw new ConfigurationException (S._("Config_MustBeElement"), node); } // Process "add", "remove", and "clear" child tags. if(node.Name == "add") { key = GetRequiredAttribute(node, keyName, 1); value = GetRequiredAttribute(node, valueName, 0); coll[key] = value; } else if(node.Name == "remove") { key = GetRequiredAttribute(node, keyName, 0); coll.Remove(key); } else if(node.Name == "clear") { if(node.Attributes.Count != 0) { throw new ConfigurationException (S._("Config_UnrecognizedAttribute"), node); } coll.Clear(); } else { throw new ConfigurationException (S._("Config_NotRecognized"), node); } } // Make the collection read-only and return it. coll.MakeReadOnly(); return coll; }
internal ReadOnlyNameValueCollection(ReadOnlyNameValueCollection value) : base(value) { }
private SiteMapNode GetNodeFromXmlNode(XmlNode xmlNode, Queue queue) { SiteMapNode node = null; // static nodes string title = null, url = null, description = null, roles = null, resourceKey = null; // Url attribute is NOT required for a xml node. HandlerBase.GetAndRemoveStringAttribute(xmlNode, "url", ref url); HandlerBase.GetAndRemoveStringAttribute(xmlNode, "title", ref title); HandlerBase.GetAndRemoveStringAttribute(xmlNode, "description", ref description); HandlerBase.GetAndRemoveStringAttribute(xmlNode, "roles", ref roles); HandlerBase.GetAndRemoveStringAttribute(xmlNode, "resourceKey", ref resourceKey); // Do not add the resourceKey if the resource is not valid. if (!String.IsNullOrEmpty(resourceKey) && !ValidateResource(ResourceKey, resourceKey + ".title")) { resourceKey = null; } HandlerBase.CheckForbiddenAttribute(xmlNode, _securityTrimmingEnabledAttrName); NameValueCollection resourceKeyCollection = null; bool allowImplicitResourceAttribute = String.IsNullOrEmpty(resourceKey); HandleResourceAttribute(xmlNode, ref resourceKeyCollection, "title", ref title, allowImplicitResourceAttribute); HandleResourceAttribute(xmlNode, ref resourceKeyCollection, "description", ref description, allowImplicitResourceAttribute); ArrayList roleList = new ArrayList(); if (roles != null) { int foundIndex = roles.IndexOf('?'); if (foundIndex != -1) { throw new ConfigurationErrorsException( SR.GetString(SR.Auth_rule_names_cant_contain_char, roles[foundIndex].ToString(CultureInfo.InvariantCulture)), xmlNode); } foreach (string role in roles.Split(_seperators)) { string trimmedRole = role.Trim(); if (trimmedRole.Length > 0) { roleList.Add(trimmedRole); } } } roleList = ArrayList.ReadOnly(roleList); String key = null; // Make urls absolute. if (!String.IsNullOrEmpty(url)) { // URL needs to be trimmed. VSWhidbey 411041 url = url.Trim(); if (!UrlPath.IsAbsolutePhysicalPath(url)) { if (UrlPath.IsRelativeUrl(url)) { url = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, url); } } // VSWhidbey 418056, Reject any suspicious or mal-formed Urls. string decodedUrl = HttpUtility.UrlDecode(url); if (!String.Equals(url, decodedUrl, StringComparison.Ordinal)) { throw new ConfigurationErrorsException( SR.GetString(SR.Property_Had_Malformed_Url, "url", url), xmlNode); } key = url.ToLowerInvariant(); } else { key = Guid.NewGuid().ToString(); } // attribute collection does not contain pre-defined properties like title, url, etc. ReadOnlyNameValueCollection attributeCollection = new ReadOnlyNameValueCollection(); attributeCollection.SetReadOnly(false); foreach (XmlAttribute attribute in xmlNode.Attributes) { string value = attribute.Value; HandleResourceAttribute(xmlNode, ref resourceKeyCollection, attribute.Name, ref value, allowImplicitResourceAttribute); attributeCollection[attribute.Name] = value; } attributeCollection.SetReadOnly(true); node = new SiteMapNode(this, key, url, title, description, roleList, attributeCollection, resourceKeyCollection, resourceKey); node.ReadOnly = true; foreach (XmlNode subNode in xmlNode.ChildNodes) { if (subNode.NodeType != XmlNodeType.Element) continue; queue.Enqueue(node); queue.Enqueue(subNode); } return node; }
private SiteMapNode GetNodeFromXmlNode(XmlNode xmlNode, Queue queue) { SiteMapNode node = null; string val = null; string str2 = null; string str3 = null; string str4 = null; string str5 = null; System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "url", ref str2); System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "title", ref val); System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "description", ref str3); System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "roles", ref str4); System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "resourceKey", ref str5); if (!string.IsNullOrEmpty(str5) && !this.ValidateResource(base.ResourceKey, str5 + ".title")) { str5 = null; } System.Web.Configuration.HandlerBase.CheckForbiddenAttribute(xmlNode, "securityTrimmingEnabled"); NameValueCollection collection = null; bool allowImplicitResource = string.IsNullOrEmpty(str5); this.HandleResourceAttribute(xmlNode, ref collection, "title", ref val, allowImplicitResource); this.HandleResourceAttribute(xmlNode, ref collection, "description", ref str3, allowImplicitResource); ArrayList list = new ArrayList(); if (str4 != null) { int index = str4.IndexOf('?'); if (index != -1) { object[] args = new object[] { str4[index].ToString(CultureInfo.InvariantCulture) }; throw new ConfigurationErrorsException(System.Web.SR.GetString("Auth_rule_names_cant_contain_char", args), xmlNode); } foreach (string str6 in str4.Split(_seperators)) { string str7 = str6.Trim(); if (str7.Length > 0) { list.Add(str7); } } } list = ArrayList.ReadOnly(list); string key = null; if (!string.IsNullOrEmpty(str2)) { str2 = str2.Trim(); if (!System.Web.Util.UrlPath.IsAbsolutePhysicalPath(str2)) { if (System.Web.Util.UrlPath.IsRelativeUrl(str2)) { str2 = System.Web.Util.UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, str2); } if (HttpContext.Current != null) { str2 = HttpContext.Current.Response.ApplyAppPathModifier(str2); } } string b = HttpUtility.UrlDecode(str2); if (!string.Equals(str2, b, StringComparison.Ordinal)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Property_Had_Malformed_Url", new object[] { "url", str2 }), xmlNode); } key = str2.ToLowerInvariant(); } else { key = Guid.NewGuid().ToString(); } ReadOnlyNameValueCollection attributes = new ReadOnlyNameValueCollection(); attributes.SetReadOnly(false); foreach (XmlAttribute attribute in xmlNode.Attributes) { string text = attribute.Value; this.HandleResourceAttribute(xmlNode, ref collection, attribute.Name, ref text, allowImplicitResource); attributes[attribute.Name] = text; } attributes.SetReadOnly(true); node = new SiteMapNode(this, key, str2, val, str3, list, attributes, collection, str5) { ReadOnly = true }; foreach (XmlNode node2 in xmlNode.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { queue.Enqueue(node); queue.Enqueue(node2); } } return(node); }
/// <summary> /// Initialize new instance of the <see cref="DataUri"/> class by using the media type and parameters. /// </summary> /// <param name="mediaType">The media type of the data uri.</param> /// <param name="parameters">The parameters of the data uri.</param> protected DataUri(string mediaType, NameValueCollection parameters) { MediaType = string.IsNullOrEmpty(mediaType) ? DefaultMediaType : mediaType; _parameters = parameters == null ? new ReadOnlyNameValueCollection(StringComparer.CurrentCultureIgnoreCase) : new ReadOnlyNameValueCollection(parameters); _parameters.SetReadOnly(); }
public void Configure(string configFilePath) { string keyAttriuteName = "key", valueAttributeName = "value"; Check.IsNotEmpty(configFilePath, "configFilePath"); configFilePath=Util.GetFullPath(configFilePath); if (!File.Exists(configFilePath)) { throw new FileNotFoundException(String.Format(AppCommon.File_Not_Found, configFilePath)); } ConfigXmlDocument document1 = new ConfigXmlDocument(); try { document1.Load(configFilePath); } catch (XmlException exception1) { throw new ConfigurationErrorsException(exception1.Message, exception1, configFilePath, exception1.LineNumber); } XmlNode section = document1.DocumentElement; _locker.EnterWriteLock(); try { _readonlyCollection = new ReadOnlyNameValueCollection(StringComparer.OrdinalIgnoreCase); HandlerBase.CheckForUnrecognizedAttributes(section); foreach (XmlNode node1 in section.ChildNodes) { if (!HandlerBase.IsIgnorableAlsoCheckForNonElement(node1)) { if (node1.Name == "add") { string text1 = HandlerBase.RemoveRequiredAttribute(node1, keyAttriuteName); string text2 = HandlerBase.RemoveRequiredAttribute(node1, valueAttributeName, true); HandlerBase.CheckForUnrecognizedAttributes(node1); _readonlyCollection[text1] = text2; } else { if (node1.Name == "remove") { string text3 = HandlerBase.RemoveRequiredAttribute(node1, keyAttriuteName); HandlerBase.CheckForUnrecognizedAttributes(node1); _readonlyCollection.Remove(text3); continue; } if (node1.Name.Equals("clear")) { HandlerBase.CheckForUnrecognizedAttributes(node1); _readonlyCollection.Clear(); continue; } HandlerBase.ThrowUnrecognizedElement(node1); } } } _readonlyCollection.SetReadOnly(); } finally { _locker.ExitWriteLock(); } FileWatchHandler fileWatchHandler = new FileWatchHandler(this, new FileInfo(configFilePath)); fileWatchHandler.StartWatching(); }
private SiteMapNode GetNodeFromXmlNode(XmlNode xmlNode, Queue queue) { SiteMapNode node = null; string val = null; string str2 = null; string str3 = null; string str4 = null; string str5 = null; System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "url", ref str2); System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "title", ref val); System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "description", ref str3); System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "roles", ref str4); System.Web.Configuration.HandlerBase.GetAndRemoveStringAttribute(xmlNode, "resourceKey", ref str5); if (!string.IsNullOrEmpty(str5) && !this.ValidateResource(base.ResourceKey, str5 + ".title")) { str5 = null; } System.Web.Configuration.HandlerBase.CheckForbiddenAttribute(xmlNode, "securityTrimmingEnabled"); NameValueCollection collection = null; bool allowImplicitResource = string.IsNullOrEmpty(str5); this.HandleResourceAttribute(xmlNode, ref collection, "title", ref val, allowImplicitResource); this.HandleResourceAttribute(xmlNode, ref collection, "description", ref str3, allowImplicitResource); ArrayList list = new ArrayList(); if (str4 != null) { int index = str4.IndexOf('?'); if (index != -1) { object[] args = new object[] { str4[index].ToString(CultureInfo.InvariantCulture) }; throw new ConfigurationErrorsException(System.Web.SR.GetString("Auth_rule_names_cant_contain_char", args), xmlNode); } foreach (string str6 in str4.Split(_seperators)) { string str7 = str6.Trim(); if (str7.Length > 0) { list.Add(str7); } } } list = ArrayList.ReadOnly(list); string key = null; if (!string.IsNullOrEmpty(str2)) { str2 = str2.Trim(); if (!System.Web.Util.UrlPath.IsAbsolutePhysicalPath(str2)) { if (System.Web.Util.UrlPath.IsRelativeUrl(str2)) { str2 = System.Web.Util.UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, str2); } if (HttpContext.Current != null) { str2 = HttpContext.Current.Response.ApplyAppPathModifier(str2); } } string b = HttpUtility.UrlDecode(str2); if (!string.Equals(str2, b, StringComparison.Ordinal)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Property_Had_Malformed_Url", new object[] { "url", str2 }), xmlNode); } key = str2.ToLowerInvariant(); } else { key = Guid.NewGuid().ToString(); } ReadOnlyNameValueCollection attributes = new ReadOnlyNameValueCollection(); attributes.SetReadOnly(false); foreach (XmlAttribute attribute in xmlNode.Attributes) { string text = attribute.Value; this.HandleResourceAttribute(xmlNode, ref collection, attribute.Name, ref text, allowImplicitResource); attributes[attribute.Name] = text; } attributes.SetReadOnly(true); node = new SiteMapNode(this, key, str2, val, str3, list, attributes, collection, str5) { ReadOnly = true }; foreach (XmlNode node2 in xmlNode.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { queue.Enqueue(node); queue.Enqueue(node2); } } return node; }