예제 #1
0
        public static UrlMappings GetMappingsFromXml()
        {
            var result = new UrlMappings
            {
                RawLinks                 = new Dictionary <string, string>(),
                RelativeLinks            = new Dictionary <string, string>(),
                RelativeLinksPerHostname = new Dictionary <string, Dictionary <string, string> >()
            };

            if (C1File.Exists(XmlFileName))
            {
                var doc = XDocumentUtils.Load(XmlFileName).Descendants("Mapping");

                foreach (var m in doc)
                {
                    var oldPath = m.Attribute("OldPath").Value;
                    var newPath = m.Attribute("NewPath").Value;

                    if (!result.RawLinks.ContainsKey(oldPath))
                    {
                        result.RawLinks.Add(oldPath, newPath);
                    }

                    if (oldPath.StartsWith("http://") || oldPath.StartsWith("https://") || oldPath.StartsWith("//"))
                    {
                        int hostnameOffset    = oldPath.IndexOf("//") + 2;
                        int hostnameEndOffset = oldPath.IndexOf('/', hostnameOffset);

                        if (hostnameEndOffset > 0)
                        {
                            string hostname    = oldPath.Substring(hostnameOffset, hostnameEndOffset - hostnameOffset);
                            string relativeUrl = oldPath.Substring(hostnameEndOffset);

                            Dictionary <string, string> linksPerHostname;
                            if (!result.RelativeLinksPerHostname.TryGetValue(hostname, out linksPerHostname))
                            {
                                result.RelativeLinksPerHostname.Add(hostname, linksPerHostname = new Dictionary <string, string>());
                            }

                            if (!linksPerHostname.ContainsKey(relativeUrl))
                            {
                                linksPerHostname.Add(relativeUrl, newPath);
                            }
                        }
                    }
                    else
                    {
                        result.RelativeLinks.Add(oldPath, newPath);
                    }
                }
            }
            return(result);
        }
        public static UrlMappings GetMappingsFromXml()
		{
		    var result = new UrlMappings
		    {
		        RawLinks = new Dictionary<string, string>(),
                RelativeLinks = new Dictionary<string, string>(),
                RelativeLinksPerHostname = new Dictionary<string, Dictionary<string, string>>()
		    };

			if (C1File.Exists(XmlFileName))
			{
				var doc = XDocumentUtils.Load(XmlFileName).Descendants("Mapping");

				foreach (var m in doc)
				{
					var oldPath = m.Attribute("OldPath").Value;
					var newPath = m.Attribute("NewPath").Value;

					if (!result.RawLinks.ContainsKey(oldPath))
					{
                        result.RawLinks.Add(oldPath, newPath);
					}

				    if (oldPath.StartsWith("http://") || oldPath.StartsWith("https://") || oldPath.StartsWith("//"))
				    {
				        int hostnameOffset = oldPath.IndexOf("//") + 2;
				        int hostnameEndOffset = oldPath.IndexOf('/', hostnameOffset);

				        if (hostnameEndOffset > 0)
				        {
				            string hostname = oldPath.Substring(hostnameOffset, hostnameEndOffset - hostnameOffset);
				            string relativeUrl = oldPath.Substring(hostnameEndOffset);

				            Dictionary<string, string> linksPerHostname;
				            if (!result.RelativeLinksPerHostname.TryGetValue(hostname, out linksPerHostname))
				            {
				                result.RelativeLinksPerHostname.Add(hostname, linksPerHostname = new Dictionary<string, string>());
				            }

				            if (!linksPerHostname.ContainsKey(relativeUrl))
				            {
				                linksPerHostname.Add(relativeUrl, newPath);
				            }
				        }
				    }
                    else
                    {
                        result.RelativeLinks.Add(oldPath, newPath);
                    }
                }
			}
            return result;
		}
예제 #3
0
파일: Map.cs 프로젝트: chakrit/plumber
 public static Pipe Urls(UrlMappings mappings, Pipe on404)
 {
     return Custom(mappings, Pipes.Produce(ctx => ctx.Request.Path), on404);
 }
예제 #4
0
파일: Map.cs 프로젝트: chakrit/plumber
 public static Pipe Custom(UrlMappings mappings,
     Produce<string> pathFunc, Pipe on404)
 {
     return (c0, next) => pathFunc(c0, (ctx, path) =>
     mappings.FindMapping(path, ifNotFound: on404)(ctx, next));
 }
예제 #5
0
파일: Map.cs 프로젝트: chakrit/plumber
 public static Pipe Urls(UrlMappings mappings)
 {
     return Urls(mappings, HttpErrors.NotFound());
 }