Exemplo n.º 1
0
 public static bool CheckUriEquality(Uri thisUri, Uri otherUri)
 {
     if (thisUri == (Uri)null && otherUri == (Uri)null)
     {
         return(true);
     }
     if (thisUri == (Uri)null ^ otherUri == (Uri)null)
     {
         return(false);
     }
     if (object.Equals((object)thisUri, (object)otherUri))
     {
         return(true);
     }
     if (UriHelperUtility.IsSdkUri(thisUri) && UriHelperUtility.IsSdkUri(otherUri))
     {
         return(UriHelperUtility.CheckSdkUriEquality(thisUri, otherUri));
     }
     if (thisUri.IsAbsoluteUri && otherUri.IsAbsoluteUri)
     {
         return(Uri.Compare(thisUri, otherUri, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.OrdinalIgnoreCase) == 0);
     }
     if (!thisUri.IsAbsoluteUri && !otherUri.IsAbsoluteUri)
     {
         return(string.Compare(thisUri.ToString(), otherUri.ToString(), StringComparison.OrdinalIgnoreCase) == 0);
     }
     return(false);
 }
Exemplo n.º 2
0
 public static bool IsUriWithin(Uri first, Uri second)
 {
     if (first == (Uri)null || second == (Uri)null)
     {
         return(false);
     }
     if (second.IsAbsoluteUri)
     {
         if (first.IsAbsoluteUri)
         {
             return(first.AbsoluteUri.StartsWith(second.AbsoluteUri, StringComparison.OrdinalIgnoreCase));
         }
         return(false);
     }
     if (!UriHelperUtility.IsSdkUri(first))
     {
         return(PathHelper.IsPathWithin(first.ToString(), second.ToString()));
     }
     if ((int)second.ToString()[second.ToString().Length - 1] != (int)Path.AltDirectorySeparatorChar)
     {
         second = new Uri(second.ToString() + (object)Path.AltDirectorySeparatorChar, UriKind.Relative);
     }
     return(first.ToString().StartsWith(second.ToString(), StringComparison.OrdinalIgnoreCase));
 }
Exemplo n.º 3
0
        public static bool TryCombineUris(Uri rootUri, Uri relativeUri, out Uri combinedUri)
        {
            combinedUri = (Uri)null;
            if (rootUri == (Uri)null && relativeUri == (Uri)null)
            {
                return(false);
            }
            if (relativeUri == (Uri)null)
            {
                combinedUri = rootUri;
                return(true);
            }
            if (relativeUri.IsAbsoluteUri || UriHelperUtility.IsSdkUri(relativeUri))
            {
                return(false);
            }
            if (rootUri == (Uri)null)
            {
                combinedUri = relativeUri;
                return(true);
            }
            if (UriHelperUtility.IsSdkUri(rootUri))
            {
                return(UriHelperUtility.TryCombineSdkUris(rootUri, relativeUri, out combinedUri));
            }
            rootUri = UriHelperUtility.EnsureUriEndsWithDirectorySeperator(rootUri);
            string originalString = relativeUri.OriginalString;

            if (Path.IsPathRooted(originalString))
            {
                string pathRoot = Path.GetPathRoot(originalString);
                relativeUri = new Uri(originalString.Substring(pathRoot.Length), UriKind.Relative);
            }
            if (rootUri.IsAbsoluteUri)
            {
                return(Uri.TryCreate(rootUri, relativeUri, out combinedUri));
            }
            string fromPath = "C:\\";
            int    length   = rootUri.OriginalString.Split(new string[1]
            {
                ".."
            }, StringSplitOptions.None).Length;

            while (length-- > 0)
            {
                fromPath = fromPath + (object)"dummy" + (string)(object)Path.DirectorySeparatorChar;
            }
            rootUri = new Uri(fromPath + rootUri.ToString(), UriKind.Absolute);
            if (!UriHelperUtility.TryCombineUris(rootUri, relativeUri, out combinedUri))
            {
                combinedUri = (Uri)null;
                return(false);
            }
            string relativePath = PathHelper.GetRelativePath(fromPath, combinedUri.LocalPath);

            if (string.IsNullOrEmpty(relativePath))
            {
                combinedUri = (Uri)null;
                return(false);
            }
            combinedUri = new Uri(relativePath, UriKind.Relative);
            return(true);
        }