Skip to content

Commit a121412

Browse files
author
Warren Buckley
committed
Refactor based from Lars comment
1 parent 493cafb commit a121412

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

src/UmbracoFileSystemProviders.Azure/AzureBlobFileSystem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ public class AzureBlobFileSystem : IFileSystem
4747
/// </summary>
4848
private const string UsePrivateContainerKey = Constants.Configuration.UsePrivateContainer;
4949

50+
51+
private AzureBlobFileSystemConfig config;
52+
53+
public AzureBlobFileSystem(AzureBlobFileSystemConfig config)
54+
{
55+
this.config = config;
56+
this.FileSystem = AzureFileSystem.GetInstance(config.ContainerName, config.RootUrl, config.ConnectionString, config.MaxDays, config.UseDefaultRoute, config.UsePrivateContainer);
57+
}
58+
5059
/// <summary>
5160
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
5261
/// </summary>

src/UmbracoFileSystemProviders.Azure/AzureFileSystemComponent.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,25 @@
55

66
namespace Our.Umbraco.FileSystemProviders.Azure
77
{
8-
using System;
9-
using System.Configuration;
108
using global::Umbraco.Core.Components;
119
using global::Umbraco.Core.IO;
1210

1311
public class AzureFileSystemComponent : IComponent
1412
{
15-
/// <summary>
16-
/// The configuration key for disabling the virtual path provider.
17-
/// </summary>
18-
private const string DisableVirtualPathProviderKey = Constants.Configuration.DisableVirtualPathProviderKey;
13+
1914
private readonly SupportingFileSystems supportingFileSystems;
15+
private readonly AzureBlobFileSystemConfig config;
2016

21-
public AzureFileSystemComponent(SupportingFileSystems supportingFileSystems)
17+
public AzureFileSystemComponent(SupportingFileSystems supportingFileSystems, AzureBlobFileSystemConfig config)
2218
{
2319
this.supportingFileSystems = supportingFileSystems;
20+
this.config = config;
2421
}
2522

2623
public void Initialize()
2724
{
28-
bool disable = ConfigurationManager.AppSettings[DisableVirtualPathProviderKey] != null
29-
&& ConfigurationManager.AppSettings[DisableVirtualPathProviderKey]
30-
.Equals("true", StringComparison.InvariantCultureIgnoreCase);
31-
3225
var azureFs = this.supportingFileSystems.For<IMediaFileSystem>() as AzureBlobFileSystem;
33-
if (!disable && azureFs != null)
26+
if (!this.config.DisableVirtualPathProvider && azureFs != null)
3427
{
3528
AzureFileSystem azureFileSystem = azureFs.FileSystem;
3629

src/UmbracoFileSystemProviders.Azure/AzureFileSystemComposer.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,34 @@
44
using System.Configuration;
55
using global::Umbraco.Core;
66
using global::Umbraco.Core.Components;
7+
using global::Umbraco.Core.Composing;
78
using global::Umbraco.Core.Exceptions;
8-
using global::Umbraco.Core.IO;
99

1010
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
1111
public class AzureFileSystemComposer : IComposer
1212
{
1313
public void Compose(Composition composition)
14+
{
15+
//Configuration
16+
var config = CreateConfiguration();
17+
18+
//Reads config from AppSetting keys
19+
composition.RegisterUnique(config);
20+
21+
//Set the Media FS to use our Azure FS with our config from AppSettings
22+
composition.SetMediaFileSystem(_ => new AzureBlobFileSystem(config));
23+
24+
//Register component that deals with the VirtualPathProvider
25+
composition.Components().Append<AzureFileSystemComponent>();
26+
}
27+
28+
private AzureBlobFileSystemConfig CreateConfiguration()
1429
{
1530
var containerName = ConfigurationManager.AppSettings[Constants.Configuration.ContainerNameKey];
1631
var rootUrl = ConfigurationManager.AppSettings[Constants.Configuration.RootUrlKey];
1732
var connectionString = ConfigurationManager.AppSettings[Constants.Configuration.ConnectionStringKey];
1833
var maxDays = ConfigurationManager.AppSettings[Constants.Configuration.MaxDaysKey];
19-
var useDefaultRoute = ConfigurationManager.AppSettings[Constants.Configuration.UseDefaultRouteKey];
34+
var useDefaultRoute = ConfigurationManager.AppSettings[Constants.Configuration.UseDefaultRouteKey];
2035
var usePrivateContainer = ConfigurationManager.AppSettings[Constants.Configuration.UsePrivateContainer];
2136

2237
//Check we have all values set - otherwise make sure Umbraco does NOT boot so it can be configured correctly
@@ -38,8 +53,21 @@ public void Compose(Composition composition)
3853
if (string.IsNullOrEmpty(usePrivateContainer))
3954
throw new ArgumentNullOrEmptyException("usePrivateContainer", $"The Azure File System is missing the value '{Constants.Configuration.UsePrivateContainer}' from AppSettings");
4055

41-
composition.SetMediaFileSystem(_ => new AzureBlobFileSystem(containerName, rootUrl, connectionString, maxDays, useDefaultRoute, usePrivateContainer));
42-
composition.Components().Append<AzureFileSystemComponent>();
56+
bool disableVirtualPathProvider = ConfigurationManager.AppSettings[Constants.Configuration.DisableVirtualPathProviderKey] != null
57+
&& ConfigurationManager.AppSettings[Constants.Configuration.DisableVirtualPathProviderKey]
58+
.Equals("true", StringComparison.InvariantCultureIgnoreCase);
59+
60+
return new AzureBlobFileSystemConfig
61+
{
62+
DisableVirtualPathProvider = disableVirtualPathProvider,
63+
ContainerName = containerName,
64+
RootUrl = rootUrl,
65+
ConnectionString = connectionString,
66+
MaxDays = maxDays,
67+
UseDefaultRoute = useDefaultRoute,
68+
UsePrivateContainer = usePrivateContainer
69+
};
4370
}
71+
4472
}
4573
}

src/UmbracoFileSystemProviders.Azure/UmbracoFileSystemProviders.Azure.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
</ItemGroup>
275275
<ItemGroup>
276276
<Compile Include="AzureBlobFileSystem.cs" />
277+
<Compile Include="AzureBlobFileSystemConfig.cs" />
277278
<Compile Include="AzureFileSystem.cs" />
278279
<Compile Include="AzureFileSystemComponent.cs" />
279280
<Compile Include="AzureFileSystemComposer.cs" />

0 commit comments

Comments
 (0)