public bool Parse(Uri uri, out Uri processedUri) { processedUri = null; var appBaseUri = _context.ApplicationBaseUri.EnsureHasTrailingSlash(); var fakeBaseUri = new Uri("http://localhost/", UriKind.Absolute); var uriRelativeToAppBase = appBaseUri .MakeRelativeUri(uri) .MakeAbsolute(fakeBaseUri); // find the resource type for the uri string lastUriSegment = uriRelativeToAppBase.Segments[uriRelativeToAppBase.Segments.Length - 1]; int lastDot = lastUriSegment.LastIndexOf("."); if (lastDot == -1) { return(false); } var uriWithoutExtension = ChangePath(uriRelativeToAppBase, srcUri => srcUri.AbsolutePath.Substring(0, srcUri.AbsolutePath.LastIndexOf("."))); _resourceMatch = _uris.Match(uriWithoutExtension); if (_resourceMatch == null) { return(false); } string potentialExtension = lastUriSegment.Substring(lastDot + 1); // _codecs. _selectedCodec = _codecs.FindByExtension(_resourceMatch.ResourceKey as IType, potentialExtension); if (_selectedCodec == null) { return(false); } processedUri = fakeBaseUri.MakeRelativeUri(uriWithoutExtension) .MakeAbsolute(appBaseUri); // TODO: Ensure that if the Accept: is not compatible with the overriden value a 406 is returned. return(true); }
public bool Parse(Uri uri, out Uri processedUri) { processedUri = null; var appBaseUri = this.context.ApplicationBaseUri.EnsureHasTrailingSlash(); var fakeBaseUri = new Uri("http://localhost/", UriKind.Absolute); var uriRelativeToAppBase = appBaseUri .MakeRelativeUri(uri) .MakeAbsolute(fakeBaseUri); // find the resource type for the uri string lastUriSegment = uriRelativeToAppBase.GetSegments()[uriRelativeToAppBase.GetSegments().Length - 1]; int lastDot = lastUriSegment.LastIndexOf("."); if (lastDot == -1) { return false; } var uriWithoutExtension = this.ChangePath( uriRelativeToAppBase, srcUri => srcUri.AbsolutePath.Substring(0, srcUri.AbsolutePath.LastIndexOf("."))); this.resourceMatch = this.uris.Match(uriWithoutExtension); if (this.resourceMatch == null) { return false; } string potentialExtension = lastUriSegment.Substring(lastDot + 1); // _codecs. this.selectedCodec = this.codecs.FindByExtension(this.resourceMatch.ResourceKey as IType, potentialExtension); if (this.selectedCodec == null) { return false; } processedUri = fakeBaseUri.MakeRelativeUri(uriWithoutExtension).MakeAbsolute(appBaseUri); // TODO: Ensure that if the Accept: is not compatible with the overriden value a 406 is returned. return true; }
void when_matching_uri(string uri) { matching_result = Resolver.Match(new Uri(uri)); }