Uri InternalizeReference(Uri uri) { if (uri == null) { return(null); } // If it is a reference to another contained resource don not internalize. // BALLOT: this seems very... ad hoc. if (uri.HasFragment()) { return(uri); } if (localhost.IsBaseOf(uri)) { Key key = localhost.UriToKey(uri); return(InternalizeReference(key).ToUri()); } else { return(uri); } }
string InternalizeReference(string uristring) { if (string.IsNullOrWhiteSpace(uristring)) { return(uristring); } Uri uri = new Uri(uristring, UriKind.RelativeOrAbsolute); // If it is a reference to another contained resource do not internalize. // BALLOT: this seems very... ad hoc. if (uri.HasFragment()) { return(uristring); } if (uri.IsTemporaryUri() || localhost.IsBaseOf(uri)) { IKey key = localhost.UriToKey(uri); return(InternalizeReference(key).ToUri().ToString()); } else { return(uristring); } }
public static bool IsLocal(this ILocalhost localhost, IKey key) { if (key.Base == null) { return(true); } return(localhost.IsBaseOf(key.Base)); }
public static Key UriToKey(this ILocalhost localhost, Uri uri) { if (uri.IsAbsoluteUri && uri.IsTemporaryUri() == false) { return(localhost.IsBaseOf(uri) ? localhost.LocalUriToKey(uri) : throw new ArgumentException("Cannot create a key from a foreign Uri")); } if (uri.IsTemporaryUri()) { return(Key.Create(null, uri.ToString())); } var path = uri.ToString(); return(Key.ParseOperationPath(path)); }
public static Key UriToKey(this ILocalhost localhost, Uri uri) { if (uri.IsAbsoluteUri) { if (localhost.IsBaseOf(uri)) { return(localhost.LocalUriToKey(uri)); } else { return(ForeignUriToKey(uri)); } } else { string path = uri.ToString(); return(Key.ParseOperationPath(path)); } }
public static Key UriToKey(this ILocalhost localhost, Uri uri) { if (uri.IsAbsoluteUri) { if (localhost.IsBaseOf(uri)) { return(localhost.LocalUriToKey(uri)); } else { throw new ArgumentException("Cannot create a key from a foreign Uri"); } } else { string path = uri.ToString(); return(Key.ParseOperationPath(path)); } }
public static bool IsBaseOf(this ILocalhost localhost, string uristring) { Uri uri = new Uri(uristring, UriKind.RelativeOrAbsolute); return(localhost.IsBaseOf(uri)); }
public static bool IsLocal(this ILocalhost localhost, IKey key) => key.Base == null || localhost.IsBaseOf(key.Base);