Skip to content

Commit eb3fb29

Browse files
authored
Merge pull request #188 from callumbwhyte/virtual-path-provider
Virtual Path Provider only works on media
2 parents 86cb65f + b8f91c3 commit eb3fb29

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
lines changed

src/UmbracoFileSystemProviders.Azure.Media/AzureMediaFileSystemComponent.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// </copyright>
55
namespace Our.Umbraco.FileSystemProviders.Azure
66
{
7+
using System;
78
using global:: Umbraco.Core.Composing;
89
using global::Umbraco.Core.IO;
910

1011
public class AzureMediaFileSystemComponent : IComponent
1112
{
12-
1313
private readonly SupportingFileSystems supportingFileSystems;
1414
private readonly AzureBlobFileSystemConfig config;
1515

@@ -22,19 +22,14 @@ public AzureMediaFileSystemComponent(SupportingFileSystems supportingFileSystems
2222
public void Initialize()
2323
{
2424
var azureFs = this.supportingFileSystems.For<IMediaFileSystem>() as AzureBlobFileSystem;
25+
2526
if (!this.config.DisableVirtualPathProvider && azureFs != null)
2627
{
2728
AzureFileSystem azureFileSystem = azureFs.FileSystem;
2829

29-
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
30-
if (azureFileSystem.UseDefaultRoute)
31-
{
32-
FileSystemVirtualPathProvider.ConfigureMedia(Constants.DefaultMediaRoute);
33-
}
34-
else
35-
{
36-
FileSystemVirtualPathProvider.ConfigureMedia(azureFileSystem.ContainerName);
37-
}
30+
var route = azureFileSystem.UseDefaultRoute ? Constants.DefaultMediaRoute : azureFileSystem.ContainerName;
31+
32+
FileSystemVirtualPathProvider.Configure(route, new Lazy<IFileSystem>(() => azureFileSystem));
3833
}
3934
}
4035

src/UmbracoFileSystemProviders.Azure.Media/FileSystemVirtualPathProvider.cs renamed to src/UmbracoFileSystemProviders.Azure/FileSystemVirtualPathProvider.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
namespace Our.Umbraco.FileSystemProviders.Azure
77
{
88
using System;
9-
using System.Diagnostics.CodeAnalysis;
109
using System.Reflection;
1110
using System.Web;
1211
using System.Web.Compilation;
1312
using System.Web.Hosting;
14-
using global::Umbraco.Core.Composing;
1513
using global::Umbraco.Core.IO;
1614

1715
/// <summary>
@@ -69,17 +67,19 @@ public FileSystemVirtualPathProvider(string pathPrefix, Lazy<IFileSystem> fileSy
6967
/// <param name="pathPrefix">
7068
/// The path prefix.
7169
/// </param>
70+
/// <param name="fileSystem">
71+
/// The file system.
72+
/// </param>
7273
/// <exception cref="ArgumentNullException">
7374
/// Thrown if <paramref name="pathPrefix"/> is null.
7475
/// </exception>
75-
public static void Configure(string pathPrefix = Constants.DefaultMediaRoute)
76+
public static void Configure(string pathPrefix, Lazy<IFileSystem> fileSystem)
7677
{
7778
if (string.IsNullOrEmpty(pathPrefix))
7879
{
7980
throw new ArgumentNullException(nameof(pathPrefix));
8081
}
8182

82-
Lazy<IFileSystem> fileSystem = new Lazy<IFileSystem>(() => Current.MediaFileSystem.Unwrap());
8383
FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider(pathPrefix, fileSystem);
8484

8585
// The standard HostingEnvironment.RegisterVirtualPathProvider(virtualPathProvider) method is ignored when
@@ -113,18 +113,6 @@ public static void Configure(string pathPrefix = Constants.DefaultMediaRoute)
113113
}
114114
}
115115

116-
/// <summary>
117-
/// Configures the virtual path provider for media.
118-
/// </summary>
119-
/// <param name="pathPrefix">
120-
/// The path prefix.
121-
/// </param>
122-
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1126:PrefixCallsCorrectly", Justification = "Resharper seems drunk.")]
123-
public static void ConfigureMedia(string pathPrefix = Constants.DefaultMediaRoute)
124-
{
125-
Configure(pathPrefix);
126-
}
127-
128116
/// <summary>
129117
/// Gets a value that indicates whether a file exists in the virtual file system.
130118
/// </summary>
@@ -142,6 +130,7 @@ public override bool FileExists(string virtualPath)
142130
}
143131

144132
string fileSystemPath = this.RemovePathPrefix(path);
133+
145134
return this.fileSystem.Value.FileExists(fileSystemPath);
146135
}
147136

@@ -156,6 +145,7 @@ public override bool FileExists(string virtualPath)
156145
public override VirtualFile GetFile(string virtualPath)
157146
{
158147
string path = this.FormatVirtualPath(virtualPath);
148+
159149
if (!path.StartsWith(this.pathPrefix, StringComparison.InvariantCultureIgnoreCase))
160150
{
161151
return base.GetFile(virtualPath);

src/UmbracoFileSystemProviders.Azure/UmbracoFileSystemProviders.Azure.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@
305305
<Compile Include="AzureBlobFileSystemConfig.cs" />
306306
<Compile Include="AzureFileSystem.cs" />
307307
<Compile Include="Constants.cs" />
308+
<Compile Include="FileSystemVirtualFile.cs" />
309+
<Compile Include="FileSystemVirtualPathProvider.cs" />
308310
<Compile Include="Helpers\ConfigurationHelper.cs" />
309311
<Compile Include="Helpers\IMimeTypeResolver.cs" />
310312
<Compile Include="Helpers\MimeTypeResolver.cs" />

0 commit comments

Comments
 (0)