public static Uri Create(Uri packageUri, Uri partUri, string fragment) { Check.PackageUri(packageUri); Check.PackageUriIsValid(packageUri); if (partUri != null) { Check.PartUriIsValid(partUri); } if (fragment != null && (fragment.Length == 0 || fragment[0] != '#')) { throw new ArgumentException("Fragment", "Fragment must not be empty and must start with '#'"); } // FIXME: Validate that partUri is a valid one? Must be relative, must start with '/' // First replace the slashes, then escape the special characters string orig = packageUri.OriginalString.Replace('/', ','); if (partUri != null) { orig += partUri.OriginalString; } // if (sb[sb.Length - 1] != '/') // sb.Append ('/'); if (fragment != null) { orig += fragment; } return(new Uri("pack://" + orig)); }
public static Uri GetRelationshipPartUri(Uri partUri) { Check.PartUri(partUri); Check.PartUriIsValid(partUri); int index = partUri.OriginalString.LastIndexOf("/"); string s = partUri.OriginalString.Substring(0, index); s += "/_rels" + partUri.OriginalString.Substring(index) + ".rels"; return(new Uri(s, UriKind.Relative)); }
public static Uri ResolvePartUri(Uri sourcePartUri, Uri targetUri) { Check.SourcePartUri(sourcePartUri); Check.TargetUri(targetUri); Check.PartUriIsValid(sourcePartUri); if (targetUri.IsAbsoluteUri) { throw new ArgumentException("targetUri", "Absolute URIs are not supported"); } // Need to trim first 7 chars as they are: "file://" return(new Uri(new Uri(sourcePartUri, targetUri).OriginalString.Substring(7), UriKind.Relative)); }
public static int ComparePartUri(Uri firstPartUri, Uri secondPartUri) { if (firstPartUri == null) { return(secondPartUri == null ? 0 : -1); } if (secondPartUri == null) { return(1); } Check.PartUriIsValid(firstPartUri); Check.PartUriIsValid(secondPartUri); return(firstPartUri.OriginalString.CompareTo(secondPartUri.OriginalString)); }
public static Uri Create(Uri packageUri, Uri partUri, string fragment) { Check.PackageUri(packageUri); Check.PackageUriIsValid(packageUri); if (partUri != null) { Check.PartUriIsValid(partUri); } if (fragment != null && (fragment.Length == 0 || fragment[0] != '#')) { throw new ArgumentException("Fragment", "Fragment must not be empty and must start with '#'"); } // FIXME: Validate that partUri is a valid one? Must be relative, must start with '/' // First replace the slashes, then escape the special characters //string orig = packageUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped); string orig = packageUri.OriginalString; foreach (var ch in _escapedChars) { orig = !orig.Contains(ch.ToString()) ? orig : orig.Replace(ch.ToString(), Uri.HexEscape(ch)); } orig = orig.Replace('/', ','); if (partUri != null) { orig += partUri.OriginalString; } if ((fragment == null && partUri == null) && orig[orig.Length - 1] != '/') { orig += '/'; } if (fragment != null) { orig += fragment; } return(new Uri("pack://" + orig)); }
public static Uri ResolvePartUri(Uri sourcePartUri, Uri targetUri) { Check.SourcePartUri(sourcePartUri); Check.TargetUri(targetUri); Check.PartUriIsValid(sourcePartUri); // commented out because on Android they are absolute file:/// // if (targetUri.IsAbsoluteUri) // throw new ArgumentException("targetUri", "Absolute URIs are not supported"); Uri uri = new Uri("http://fake.com"); uri = new Uri(uri, sourcePartUri); uri = new Uri(uri, targetUri); // Trim out 'http://fake.com' return(new Uri(uri.OriginalString.Substring(15), UriKind.Relative)); }