private static bool TryCombineSdkUris(Uri rootUri, Uri relativeUri, out Uri combinedUri) { rootUri = UriHelperUtility.EnsureUriEndsWithDirectorySeperator(rootUri); if (rootUri.IsAbsoluteUri) { return(Uri.TryCreate(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); } return(Uri.TryCreate((rootUri.ToString() + relativeUri.ToString()).Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), UriKind.Relative, out combinedUri)); }
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); }