Skip to content

Commit f455827

Browse files
committed
v0.10.3
1 parent 779b676 commit f455827

File tree

8 files changed

+45
-18
lines changed

8 files changed

+45
-18
lines changed

azure-pipelines.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ steps:
99
- checkout: self
1010
submodules: true
1111

12-
- task: NuGetAuthenticate@0
13-
condition: ne(variables['Build.Reason'], 'PullRequest')
14-
1512
- task: UseDotNet@2
1613
displayName: Ensure 3.1 SDK
1714
inputs:
1815
version: 3.1.x
19-
performMultiLevelLookup: true
16+
includePreviewVersions: true
2017

2118
- script: |
2219
dotnet build src\MagicScaler -c Dist --version-suffix ci$(Build.BuildNumber)
2320
dotnet build src\WebRSize -c Dist --version-suffix ci$(Build.BuildNumber)
2421
displayName: Build
2522

23+
- task: NuGetAuthenticate@0
24+
condition: ne(variables['Build.Reason'], 'PullRequest')
25+
2626
- script: |
2727
dotnet nuget push --api-key AzureArtifacts --source https://pkgs.dev.azure.com/saucecontrol/PhotoSauce/_packaging/photosauce_ci/nuget/v3/index.json out\bin\MagicScaler\Dist\PhotoSauce.MagicScaler.*.nupkg
2828
dotnet nuget push --api-key AzureArtifacts --source https://pkgs.dev.azure.com/saucecontrol/PhotoSauce/_packaging/photosauce_ci/nuget/v3/index.json out\bin\WebRSize\Dist\PhotoSauce.WebRSize.*.nupkg

src/MagicScaler/Core/ImageFileInfo.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ public ImageFileInfo(int width, int height)
5656
ContainerType = FileFormat.Unknown;
5757
}
5858

59-
private ImageFileInfo(FileFormat containerType, IReadOnlyList<FrameInfo> frames, long fileSize, DateTime fileDate)
59+
/// <summary>Constructs a new <see cref="ImageFileInfo" /> instance the specified values.</summary>
60+
/// <param name="containerType">The <see cref="FileFormat" /> of the image container.</param>
61+
/// <param name="frames">A list containing one <see cref="FrameInfo" /> per image frame in the container.</param>
62+
/// <param name="fileSize">The size in bytes of the image file.</param>
63+
/// <param name="fileDate">The last modified date of the image file.</param>
64+
public ImageFileInfo(FileFormat containerType, IReadOnlyList<FrameInfo> frames, long fileSize, DateTime fileDate)
6065
{
6166
ContainerType = containerType;
6267
Frames = frames;

src/MagicScaler/MagicScaler.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup Condition="!$(DefineConstants.Contains('BUILTIN_SPAN'))">
24-
<PackageReference Include="System.Buffers" Version="4.5.0" />
24+
<PackageReference Include="System.Buffers" Version="4.4.0" />
2525
<PackageReference Include="System.Memory" Version="4.5.3" />
26-
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
26+
<PackageReference Include="System.Numerics.Vectors" Version="4.4.0" />
27+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
2728
</ItemGroup>
2829

2930
<ItemGroup Condition="$(DefineConstants.Contains('SYSTEM_DRAWING')) And !$(DefineConstants.Contains('NETFRAMEWORK'))">
3031
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
3132
</ItemGroup>
3233

33-
<ItemGroup Condition="'$(TargetFramework)'!='netcoreapp3.0'">
34+
<ItemGroup Condition="$(DefineConstants.Contains('BUILTIN_SPAN')) And '$(TargetFramework)'!='netcoreapp3.0'">
3435
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
3536
</ItemGroup>
3637

src/WebRSize/CacheHelper.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ public static Task<T> GetOrAddAsync<T>(string cacheKey, Func<Task<T>> getValue =
4242
return val;
4343
}
4444

45-
public static Task<ImageFileInfo> GetImageInfoAsync(string path)
45+
public static Task<ImageFileInfo> GetImageInfoAsync(VirtualPathProvider vpp, string path)
4646
{
47-
return GetOrAddAsync(string.Concat("wrfi_", path), async () => {
48-
var vpp = HostingEnvironment.VirtualPathProvider;
49-
47+
return GetOrAddAsync(string.Concat("wsvppfi_", path), async () => {
5048
var file = vpp is CachingAsyncVirtualPathProvider vppAsync ? await vppAsync.GetFileAsync(path).ConfigureAwait(false) : vpp.GetFile(path);
5149
var afile = file as AsyncVirtualFile;
50+
5251
using var stream = afile != null ? await afile.OpenAsync().ConfigureAwait(false) : file.Open();
5352
return ImageFileInfo.Load(stream, afile != null ? afile.LastModified : DateTime.MinValue);
5453
}, () => MakeVirtualPathDependency(path));

src/WebRSize/CachingAsyncVirtualPathProvider.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Collections;
77
using System.Threading.Tasks;
88

9+
using PhotoSauce.MagicScaler;
10+
911
namespace PhotoSauce.WebRSize
1012
{
1113
/// <summary>A base <see cref="VirtualPathProvider"/> that adds memory caching and async operation.</summary>
@@ -58,6 +60,9 @@ protected virtual CacheDependency GetCacheDependencyInternal(string virtualPath,
5860
/// <inheritdoc cref="GetDirectory(string)" />
5961
protected virtual Task<VirtualDirectory> GetDirectoryAsyncInternal(string virtualDir) => CacheHelper.CompletedTask<VirtualDirectory>.Default;
6062

63+
/// <inheritdoc cref="GetImageInfoAsync(string)" />
64+
protected virtual Task<ImageFileInfo> GetImageInfoAsyncInternal(string virtualPath) => CacheHelper.GetImageInfoAsync(this, virtualPath);
65+
6166
/// <inheritdoc />
6267
public override bool FileExists(string virtualPath) => IsPathCaptured(virtualPath) ? FileExistsInternal(virtualPath) : Previous.FileExists(virtualPath);
6368

@@ -114,6 +119,17 @@ public virtual Task<VirtualDirectory> GetDirectoryAsync(string virtualDir)
114119

115120
return AsyncPrevious?.GetDirectoryAsync(virtualDir) ?? Task.FromResult(Previous.GetDirectory(virtualDir));
116121
}
122+
123+
/// <summary>Get the basic metadata associated with an image file at the given <paramref name="virtualPath" />.</summary>
124+
/// <param name="virtualPath">The virtual path of the image file.</param>
125+
/// <returns>The <see cref="ImageFileInfo" />.</returns>
126+
public virtual Task<ImageFileInfo> GetImageInfoAsync(string virtualPath)
127+
{
128+
if (IsPathCaptured(virtualPath))
129+
return CacheHelper.GetOrAddAsync(string.Concat("wsvppfi_", virtualPath), () => GetImageInfoAsyncInternal(virtualPath));
130+
131+
return AsyncPrevious?.GetImageInfoAsync(virtualPath) ?? CacheHelper.GetImageInfoAsync(Previous, virtualPath);
132+
}
117133
}
118134

119135
/// <inheritdoc />

src/WebRSize/WebRSize.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>0.5.0</VersionPrefix>
4+
<VersionPrefix>0.5.1</VersionPrefix>
55
<TargetFrameworks>net46;net472</TargetFrameworks>
66
</PropertyGroup>
77

src/WebRSize/WebRSizeHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ namespace PhotoSauce.WebRSize
1515
/// <summary>An <see cref="IHttpHandler" /> implementation that performs a dynamic image processing operation, returns the result to the client, and queues caching the result.</summary>
1616
public class WebRSizeHandler : HttpTaskAsyncHandler
1717
{
18+
internal static WebRSizeHandler Instance = new WebRSizeHandler();
19+
1820
private struct QueueReleaser : IDisposable { public void Dispose() => sem.Release(); }
1921

22+
private static readonly bool diskCacheEnabled = WebRSizeConfig.Current.DiskCache.Enabled;
2023
private static readonly SemaphoreSlim sem = new SemaphoreSlim(Environment.ProcessorCount, Environment.ProcessorCount);
2124
private static readonly ConcurrentDictionary<string, Task<ArraySegment<byte>>> tdic = new ConcurrentDictionary<string, Task<ArraySegment<byte>>>();
2225
private static readonly Lazy<Type> mpbvfType = new Lazy<Type>(() => Assembly.GetAssembly(typeof(HostingEnvironment)).GetType("System.Web.Hosting.MapPathBasedVirtualFile", true));
@@ -32,6 +35,9 @@ private static void saveResult(TaskCompletionSource<ArraySegment<byte>> tcs, Mem
3235
oimg.TryGetBuffer(out var bytes);
3336
tcs.SetResult(bytes);
3437

38+
if (!diskCacheEnabled)
39+
return;
40+
3541
HostingEnvironment.QueueBackgroundWorkItem(async __ => { try {
3642
var fi = new FileInfo(cachePath);
3743
if (!fi.Exists)

src/WebRSize/WebRSizeModule.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class WebRSizeModule : IHttpModule
1616
internal const string CachePathKey = "wscachepath";
1717
internal const string NotFoundPath = "/404/notfound.png";
1818

19-
private static readonly WebRSizeHandler handler = new WebRSizeHandler();
19+
private static readonly bool diskCacheEnabled = WebRSizeConfig.Current.DiskCache.Enabled;
2020
private static readonly ImageFolder[] imageFolders = WebRSizeConfig.Current.ImageFolders.OfType<ImageFolder>().ToArray();
2121
private static readonly Lazy<ICacheFileNamingStrategy> namingStrategy = new Lazy<ICacheFileNamingStrategy>(() => (ICacheFileNamingStrategy)Activator.CreateInstance(WebRSizeConfig.Current.DiskCache.NamingStrategy));
2222

@@ -26,7 +26,7 @@ private async Task mapRequest(object sender, EventArgs e)
2626
var vpp = HostingEnvironment.VirtualPathProvider;
2727

2828
string path = ctx.Request.Path;
29-
bool exists = vpp is CachingAsyncVirtualPathProvider vppAsync ? await vppAsync.FileExistsAsync(path) : vpp.FileExists(path);
29+
bool exists = vpp is CachingAsyncVirtualPathProvider vppAE ? await vppAE.FileExistsAsync(path).ConfigureAwait(false) : vpp.FileExists(path);
3030

3131
var folderConfig = imageFolders.FirstOrDefault(f => ctx.Request.Path.StartsWith(f.Path, StringComparison.OrdinalIgnoreCase));
3232
if (folderConfig is null)
@@ -63,7 +63,7 @@ private async Task mapRequest(object sender, EventArgs e)
6363
s.SaveFormat = FileFormat.Png;
6464
}
6565

66-
ifi ??= await CacheHelper.GetImageInfoAsync(path);
66+
ifi = vpp is CachingAsyncVirtualPathProvider vppAF ? await vppAF.GetImageInfoAsync(path).ConfigureAwait(false) : await CacheHelper.GetImageInfoAsync(vpp, path).ConfigureAwait(false);
6767
s.NormalizeFrom(ifi);
6868

6969
if (!folderConfig.AllowEnlarge && s.ResizeMode != CropScaleMode.Max)
@@ -99,7 +99,7 @@ private async Task mapRequest(object sender, EventArgs e)
9999
string cacheVPath = namingStrategy.Value.GetCacheFilePath(path, s);
100100
string cachePath = HostingEnvironment.MapPath(cacheVPath);
101101

102-
if (File.Exists(cachePath))
102+
if (diskCacheEnabled && File.Exists(cachePath))
103103
{
104104
ctx.RewritePath(cacheVPath, null, string.Empty, false);
105105
return;
@@ -110,7 +110,7 @@ private async Task mapRequest(object sender, EventArgs e)
110110

111111
ctx.Items[ProcessImageSettingsKey] = s;
112112
ctx.Items[CachePathKey] = cachePath;
113-
ctx.RemapHandler(handler);
113+
ctx.RemapHandler(WebRSizeHandler.Instance);
114114
}
115115

116116
/// <inheritdoc />

0 commit comments

Comments
 (0)