コード例 #1
0
        /// <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))));
        }
コード例 #2
0
 private static MappedResourceInfo GetMappedFileInfo(IMimeTypeProvider mimeTypeProvider, FileInfo info)
 => MappedResourceInfo.ForFile(
     info.FullName,
     info.Name,
     info.LastWriteTimeUtc,
     info.Length,
     mimeTypeProvider.GetMimeType(info.Extension));
コード例 #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))));
        }
コード例 #4
0
ファイル: ZipFileProvider.cs プロジェクト: gmattworld/embedio
        /// <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))));
        }