/// <inheritdoc />
        public MappedResourceInfo?MapUrlPath(string urlPath, IMimeTypeProvider mimeTypeProvider)
        {
            var resourceName = PathPrefix + urlPath.Replace('/', '.');

            long size;

            try
            {
                using var stream = Assembly.GetManifestResourceStream(resourceName);
                if (stream == null || stream == Stream.Null)
                {
                    return(null);
                }

                size = stream.Length;
            }
            catch (FileNotFoundException)
            {
                return(null);
            }

            var lastSlashPos = urlPath.LastIndexOf('/');
            var name         = urlPath.Substring(lastSlashPos + 1);

            return(MappedResourceInfo.ForFile(
                       resourceName,
                       name,
                       _fileTime,
                       size,
                       mimeTypeProvider.GetMimeType(Path.GetExtension(name))));
        }
Exemple #2
0
 private static MappedResourceInfo GetMappedFileInfo(IMimeTypeProvider mimeTypeProvider, FileInfo info)
 => MappedResourceInfo.ForFile(
     info.FullName,
     info.Name,
     info.LastWriteTimeUtc,
     info.Length,
     mimeTypeProvider.GetMimeType(info.Extension));
Exemple #3
0
        /// <inheritdoc />
        public MappedResourceInfo?MapUrlPath(string path, IMimeTypeProvider mimeTypeProvider)
        {
            if (Validate.UrlPath(nameof(path), path, false).Length == 1)
            {
                return(null);
            }

            Validate.NotNull(nameof(mimeTypeProvider), mimeTypeProvider);

            path = Uri.UnescapeDataString(path);

            var entry = _zipArchive.GetEntry(path.Substring(1));

            if (entry == null)
            {
                return(null);
            }

            return(MappedResourceInfo.ForFile(
                       entry.FullName,
                       entry.Name,
                       entry.LastWriteTime.DateTime,
                       entry.Length,
                       mimeTypeProvider.GetMimeType(Path.GetExtension(entry.Name))));
        }
        /// <inheritdoc />
        public MappedResourceInfo?MapUrlPath(string urlPath, IMimeTypeProvider mimeTypeProvider)
        {
            if (urlPath.Length == 1)
            {
                return(null);
            }

            var entry = _zipArchive.GetEntry(urlPath.Substring(1));

            if (entry == null)
            {
                return(null);
            }

            return(MappedResourceInfo.ForFile(
                       entry.FullName,
                       entry.Name,
                       entry.LastWriteTime.DateTime,
                       entry.Length,
                       mimeTypeProvider.GetMimeType(Path.GetExtension(entry.Name))));
        }