예제 #1
0
        internal Configuration FindLocationConfiguration(string relativePath, Configuration defaultConfiguration)
        {
            Configuration parentConfig = defaultConfiguration;

            if (!String.IsNullOrEmpty(LocationConfigPath))
            {
                Configuration parentFile = GetParentWithFile();
                if (parentFile != null)
                {
                    string parentRelativePath = system.Host.GetConfigPathFromLocationSubPath(configPath, relativePath);
                    parentConfig = parentFile.FindLocationConfiguration(parentRelativePath, defaultConfiguration);
                }
            }

            string relConfigPath = configPath.Substring(1) + "/";

            if (relativePath.StartsWith(relConfigPath, StringComparison.Ordinal))
            {
                relativePath = relativePath.Substring(relConfigPath.Length);
            }

            ConfigurationLocation loc = Locations.FindBest(relativePath);

            if (loc == null)
            {
                return(parentConfig);
            }

            loc.SetParentConfiguration(parentConfig);
            return(loc.OpenConfiguration());
        }
예제 #2
0
        internal ConfigurationLocation FindBest(string location)
        {
            if (String.IsNullOrEmpty(location))
            {
                return(null);
            }

            ConfigurationLocation bestMatch = null;
            int locationlen  = location.Length;
            int bestmatchlen = 0;

            foreach (ConfigurationLocation loc in InnerList)
            {
                string lpath = loc.Path;
                if (String.IsNullOrEmpty(lpath))
                {
                    continue;
                }

                int lpathlen = lpath.Length;
                if (location.StartsWith(lpath, StringComparison.OrdinalIgnoreCase))
                {
                    // Exact match always takes precedence
                    if (locationlen == lpathlen)
                    {
                        return(loc);
                    }

                    // ensure path based comparisons consider full directory names (i.e. so 'admin' does not match an 'administration' path)
                    if (locationlen > lpathlen && location [lpathlen] != '/')
                    {
                        continue;
                    }

                    if (bestMatch == null)
                    {
                        bestMatch = loc;
                    }
                    else if (bestmatchlen < lpathlen)
                    {
                        bestMatch    = loc;
                        bestmatchlen = lpathlen;
                    }
                }
            }

            return(bestMatch);
        }
예제 #3
0
        internal Configuration FindLocationConfiguration(string relativePath, Configuration defaultConfiguration)
        {
            ConfigurationLocation loc = Locations.Find(relativePath);

            Configuration parentConfig = defaultConfiguration;

            if (LocationConfigPath != null)
            {
                Configuration parentFile = GetParentWithFile();
                if (parentFile != null)
                {
                    string parentRelativePath = system.Host.GetConfigPathFromLocationSubPath(LocationConfigPath, relativePath);
                    parentConfig = parentFile.FindLocationConfiguration(parentRelativePath, defaultConfiguration);
                }
            }

            if (loc == null)
            {
                return(parentConfig);
            }

            loc.SetParentConfiguration(parentConfig);
            return(loc.OpenConfiguration());
        }
예제 #4
0
        private void ReadContent(XmlReader reader, Configuration config, bool overrideAllowed, bool root)
        {
            while (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Skip();
                    continue;
                }

                if (reader.LocalName == "dllmap")
                {
                    reader.Skip();
                    continue;
                }

                if (reader.LocalName == "location")
                {
                    if (!root)
                    {
                        ThrowException("<location> elements are only allowed in <configuration> elements.", reader);
                    }

                    string allowOverrideAttr = reader.GetAttribute("allowOverride");
                    var    allowOverride     = string.IsNullOrEmpty(allowOverrideAttr) ||
                                               bool.Parse(allowOverrideAttr);
                    string path = reader.GetAttribute("path");
                    if (!string.IsNullOrEmpty(path) && path[0] != '.')
                    {
                        string xml      = reader.ReadOuterXml();
                        var    pathList = path.Split(',');
                        foreach (var p in pathList)
                        {
                            var tpath = p.Trim();
                            if (config.Locations.Find(tpath) != null)
                            {
                                ThrowException("Sections must only appear once per config file.", reader);
                            }

                            var loc = new ConfigurationLocation(tpath, xml, config, allowOverride);
                            config.Locations.Add(loc);
                        }
                    }
                    else
                    {
                        ReadData(config, reader, allowOverride);
                    }
                    continue;
                }

                var data = GetConfigInfo(reader, this);
                if (data != null)
                {
                    data.ReadData(config, reader, overrideAllowed);
                }
                else
                {
                    ThrowException("Unrecognized configuration section <" + reader.LocalName + ">", reader);
                }
            }
        }
		void ReadContent (XmlReader reader, Configuration config, bool overrideAllowed, bool root)
		{
			while (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None) {
				if (reader.NodeType != XmlNodeType.Element) {
					reader.Skip ();
					continue;
				}

				if (reader.LocalName == "dllmap") {
					reader.Skip ();
					continue;
				}

				if (reader.LocalName == "location") {
					if (!root)
						ThrowException ("<location> elements are only allowed in <configuration> elements.", reader);

					string allowOverrideAttr = reader.GetAttribute ("allowOverride");
					bool allowOverride = allowOverrideAttr == null || allowOverrideAttr.Length == 0 || bool.Parse (allowOverrideAttr);
					string path = reader.GetAttribute ("path");
					if (path != null && path.Length > 0) {
						string xml = reader.ReadOuterXml ();
						string[] pathList = path.Split (',');
						string tpath;
						foreach (string p in pathList) {
							tpath = p.Trim ();
							if (config.Locations.Find (tpath) != null)
								ThrowException ("Sections must only appear once per config file.", reader);
							
							ConfigurationLocation loc = new ConfigurationLocation (tpath, xml, config, allowOverride);
							config.Locations.Add (loc);
						}
					} else {
						ReadData (config, reader, allowOverride);
					}
					continue;
				}
			
				ConfigInfo data = GetConfigInfo (reader, this);
				if (data != null)
					data.ReadData (config, reader, overrideAllowed);
				else
					ThrowException ("Unrecognized configuration section <" + reader.LocalName + ">", reader);
			}
		}
		internal void Add (ConfigurationLocation loc)
		{
			InnerList.Add (loc);
		}
예제 #7
0
 internal void Add(ConfigurationLocation loc)
 {
     InnerList.Add(loc);
 }