Пример #1
0
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="url">Die Url</param>
        public UriAbsolute(string url)
        {
            if (url == null)
            {
                return;
            }

            var match = Regex.Match(url, Pattern);

            try
            {
                Scheme = (UriScheme)Enum.Parse(typeof(UriScheme), match.Groups[1].Value, true);
            }
            catch
            {
                Scheme = UriScheme.Http;
            }

            Authority = new UriAuthority()
            {
                User = match.Groups[2].Value,
                Host = match.Groups[3].Value,
                Port = !string.IsNullOrWhiteSpace(match.Groups[4].Value) ? Convert.ToInt32(match.Groups[4].Value) : null
            };

            var uri = new UriRelative(match.Groups[5].Value);

            (Path as List <IUriPathSegment>).AddRange(uri.Path.Select(x => new UriPathSegment(x.Value, x.Tag) as IUriPathSegment));
            (Query as List <UriQuerry>).AddRange(uri.Query.Select(x => new UriQuerry(x.Key, x.Value)));
            Fragment = uri.Fragment;
        }
Пример #2
0
        /// <summary>
        /// Liefere eine verkürzte Uri indem die ersten n-Elemente enthalten sind
        /// count > 0 es sind count-Elemente enthalten
        /// count < 0 es werden count-Elemente abgeshnitten
        /// count = 0 es wird eine leere Uri zurückgegeben
        /// </summary>
        /// <param name="count">Die Anzahl</param>
        /// <returns>Die Teiluri</returns>
        public virtual IUri Take(int count)
        {
            var copy = new UriRelative(this);
            var path = copy.Path.ToList();

            copy.Path.Clear();

            if (count == 0)
            {
                return(new UriRelative());
            }
            else if (count > 0)
            {
                (copy.Path as List <IUriPathSegment>).AddRange(path.Take(count));
            }
            else if (count < 0 && Math.Abs(count) < path.Count)
            {
                (copy.Path as List <IUriPathSegment>).AddRange(path.Take(path.Count + count));
            }
            else
            {
                return(null);
            }

            return(copy);
        }
Пример #3
0
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="context">Der Kontext des Moduls</param>
        /// <param name="url">Die eigentliche Uri, welche vom Webbrowser aufgerufen wurde</param>
        /// <param name="node">Der Knoten der Sitemap</param>
        internal UriResource(IModuleContext context, string url, SearchResult node, CultureInfo culture)
            : this(context.ContextPath, new UriRelative())
        {
            var uri      = new UriRelative(url.Substring(context.ContextPath.ToString().Length));
            var uriPath  = uri.Path as List <IUriPathSegment>;
            var nodePath = node.Path as List <SitemapNode>;

            for (var i = 0; i < uriPath.Count; i++)
            {
                var u = uriPath[i];

                if (i < nodePath.Count)
                {
                    var item = new UriPathSegment(u.Value, u.Tag)
                    {
                        Display = nodePath[i]?.PathSegment?.GetDisplay(u.ToString(), context.ModuleID, culture)
                    };
                    Uri.Path.Add(item);
                }
                else
                {
                    var item = new UriPathSegment(u.Value, u.Tag);
                    Uri.Path.Add(item);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Verknüft die angegebenen uris zu einer relaiven Uri
        /// </summary>
        /// <param name="uris">Die zu verknüpfenden Uris</param>
        /// <returns>Eine kombinierte Uri</returns>
        public static UriRelative Combine(params IUri[] uris)
        {
            var uri = new UriRelative();

            (uri.Path as List <IUriPathSegment>).AddRange(uris.Where(x => x != null).SelectMany(x => x.Path));

            return(uri);
        }
Пример #5
0
        /// <summary>
        /// Verknüft die angegebenen uris zu einer relaiven Uri
        /// </summary>
        /// <param name="uri">Eine Uri</param>
        /// <param name="uris">Die zu verknüpfenden Uris</param>
        /// <returns>Eine kombinierte Uri</returns>
        public static UriRelative Combine(IUri uri, params string[] uris)
        {
            var copy = new UriRelative(uri as UriRelative);

            (copy.Path as List <IUriPathSegment>).AddRange(uris.Where(x => !string.IsNullOrWhiteSpace(x))
                                                           .SelectMany(x => x.Split('/', StringSplitOptions.RemoveEmptyEntries))
                                                           .Select(x => new UriPathSegment(x) as IUriPathSegment));


            return(copy);
        }
Пример #6
0
        /// <summary>
        /// Verknüft die angegebenen uris zu einer relaiven Uri
        /// </summary>
        /// <param name="uris">Die zu verknüpfenden Uris</param>
        /// <returns>Eine kombinierte Uri</returns>
        public static UriRelative Combine(params string[] uris)
        {
            var uri = new UriRelative();

            uri.Path.Add(new UriPathSegment(null, "root"));
            (uri.Path as List <IUriPathSegment>).AddRange(uris.Where(x => !string.IsNullOrWhiteSpace(x))
                                                          .SelectMany(x => x.Split('/', StringSplitOptions.RemoveEmptyEntries))
                                                          .Select(x => new UriPathSegment(x) as IUriPathSegment));

            return(uri);
        }
Пример #7
0
        /// <summary>
        /// Fügt ein Pfad hinzu
        /// </summary>
        /// <param name="path">Der anzufügende Pfad</param>
        /// <returns>Der erweiterte Pfad</returns>
        public virtual IUri Append(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(this);
            }

            var copy = new UriRelative(this);

            foreach (var p in path.Split('/', StringSplitOptions.RemoveEmptyEntries))
            {
                copy.Path.Add(new UriPathSegment(p));
            }

            return(copy);
        }
Пример #8
0
        /// <summary>
        /// Liefere eine verkürzte Uri indem die ersten n-Elemente nicht enthalten sind
        /// count > 0 es werden count-Elemente übersprungen
        /// count <= 0 es wird eine leere Uri zurückgegeben
        /// </summary>
        /// <param name="count">Die Anzahl</param>
        /// <returns>Die Teiluri oder null</returns>
        public IUri Skip(int count)
        {
            if (count >= Path.Count)
            {
                return(null);
            }
            if (count > 0)
            {
                var copy = new UriRelative(this);
                var path = copy.Path.ToList();
                copy.Path.Clear();
                (copy.Path as List <IUriPathSegment>).AddRange(path.Skip(count));

                return(copy);
            }

            return(new UriRelative(this));
        }
Пример #9
0
 /// <summary>
 /// Copy-Konstruktor
 /// </summary>
 /// <param name="uri">Die zu kopierende Uir</param>
 public UriRelative(UriRelative uri)
 {
     Path     = uri.Path.Select(x => new UriPathSegment(x) as IUriPathSegment).ToList();
     Query    = uri.Query.Select(x => new UriQuerry(x.Key, x.Value)).ToList();
     Fragment = uri.Fragment;
 }
Пример #10
0
 /// <summary>
 /// Fügt ein Pfad hinzu
 /// </summary>
 /// <param name="path">Der anzufügende Pfad</param>
 public IUri Append(string path)
 {
     return(new UriResource(ContextPath, UriRelative.Combine(Uri, path)));
 }