Skip to content

Commit 5691546

Browse files
Add project files
1 parent cee3abe commit 5691546

31 files changed

+3204
-0
lines changed

README.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# UmbracoFileSystemProviders.Azure
2+
3+
An [Azure Blob Storage](http://azure.microsoft.com/en-gb/develop/net/) IFileSystem provider for Umbraco 6.25+.
4+
Used to offload static files in the media section to the cloud.
5+
6+
Designed to supersede [UmbracoAzureBlobStorage](https://github.com/idseefeld/UmbracoAzureBlobStorage) by [Dirk SeeField](https://twitter.com/dseefeld65) (With his blessing) this package allows the storage and retrieval of media items using Azure Blob Storage while retaining the relative paths to the files expected in the back office.
7+
8+
## Installation
9+
At present the code is pre-release but when ready it will be available on [Nuget](http://www.nuget.org), also maybe as a package on [Our Umbraco](https://our.umbraco.org/).
10+
11+
In the interim code reviews and pull requests would be most welcome! (Appveyor, MyGet, Nuget config etc..)
12+
13+
## Usage
14+
15+
**Note:** Upon release most of configuration this will be automated.
16+
17+
Update `~/Config/FileSystemProviders.config` replacing the default provider with the following:
18+
19+
```xml
20+
<?xml version="1.0"?>
21+
<FileSystemProviders>
22+
<Provider alias="media" type="Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure">
23+
<Parameters>
24+
<add key="containerName" value="media" />
25+
<add key="rootUrl" value="http://[myAccountName].blob.core.windows.net/" />
26+
<add key="connectionString" value="DefaultEndpointsProtocol=https;AccountName=[myAccountName];AccountKey=[myAccountKey]"/>
27+
<!--
28+
Optional configuration value determining the maximum number of days to cache items in the browser.
29+
Defaults to 365 days.
30+
-->
31+
<add key="maxDays" value="365" />
32+
</Parameters>
33+
</Provider>
34+
</FileSystemProviders>
35+
```
36+
37+
Developmental mode configuration using the [Azure Storage Emulator](https://azure.microsoft.com/en-us/documentation/articles/storage-use-emulator/) for testing is as follows:
38+
39+
```xml
40+
<?xml version="1.0"?>
41+
<FileSystemProviders>
42+
<Provider alias="media" type="Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure">
43+
<Parameters>
44+
<add key="containerName" value="media" />
45+
<add key="rootUrl" value="http://127.0.0.1:10000/devstoreaccount1/" />
46+
<add key="connectionString" value="UseDevelopmentStorage=true"/>
47+
</Parameters>
48+
</Provider>
49+
</FileSystemProviders>
50+
```
51+
52+
Additionally the provider can be further configured with the following application setting in the `web.config`.
53+
54+
```xml
55+
<?xml version="1.0"?>
56+
<configuration>
57+
<appSettings>
58+
<!--Disables the built in Virtual Path Provider which allows for relative paths-->
59+
<add key="AzureBlobFileSystem.DisableVirtualPathProvider" value="true" />
60+
<!--
61+
Enables the development mode for testing. Addition changes to the FileSystemProviders.config are also required
62+
-->
63+
<add key="AzureBlobFileSystem.UseStorageEmulator" value="true" />
64+
</appSettings>
65+
</configuration>
66+
```
67+
68+
## Virtual Path Provider
69+
By default the plugin will serve files transparently from your domain or serve media directly from Azure. This is made possible by using a custom [Virtual Path Provider](https://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider%28v=vs.110%29.aspx) included and automatically initialised upon application startup. This can be disable by adding the configuration setting noted above.
70+
71+
**Note:** Virtual Path Providers may affect performance/caching depending on your setup as the process differs from IIS's [unmanaged handler](http://www.paraesthesia.com/archive/2011/05/02/when-staticfilehandler-is-not-staticfilehandler.aspx/). Virtual files sent via the provider though are correctly cached in the browser so this shouldn't be an issue.
72+
73+
The following configuration is required in your `web.config` to enable static file mapping in IIS Express.
74+
75+
```xml
76+
<?xml version="1.0"?>
77+
<configuration>
78+
<location path="Media">
79+
<system.webServer>
80+
<handlers>
81+
<remove name="StaticFileHandler" />
82+
<add name="StaticFileHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" />
83+
</handlers>
84+
</system.webServer>
85+
</location>
86+
</configuration>
87+
```
88+
89+
## Combining with ImageProcessor
90+
91+
As of ImageProcessor.Web version [4.3.2](https://www.nuget.org/packages/ImageProcessor.Web/4.3.2) a new [`IImageService`](http://imageprocessor.org/imageprocessor-web/extending/#iimageservice) implementation has been available called `CloudImageService`. To enable that service and pull images directly from the cloud simply install the [configuration package](https://www.nuget.org/packages/ImageProcessor.Web.Config/) and replace the `LocalFileImageService`setting with the following:
92+
93+
```xml
94+
<?xml version="1.0"?>
95+
<security>
96+
<services>
97+
<!--Disable the LocalFileImageService and enable this one when using virtual paths. -->
98+
<service name="CloudImageService" type="ImageProcessor.Web.Services.CloudImageService, ImageProcessor.Web">
99+
<settings>
100+
<setting key="MaxBytes" value="8194304"/>
101+
<setting key="Timeout" value="30000"/>
102+
<setting key="Host" value="http://[myAccountName].blob.core.windows.net/"/>
103+
</settings>
104+
</service>
105+
</security>
106+
```
107+
108+
Be sure to install the [AzureBlobCache](http://imageprocessor.org/imageprocessor-web/plugins/azure-blob-cache/) plugin to get the most out of the package.
109+
110+
## Authors
111+
112+
- James Jackson-South
113+
- Dirk Seefield
114+
- Lars Lars-Erik Aabech
115+
116+
## Thanks
117+
- Elijah Glover for writing the [Umbraco S3 Provider](https://github.com/ElijahGlover/Umbraco-S3-Provider) which provided inspiration and some snazzy unit testing code for this project.
118+

src/.nuget/NuGet.Config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<solution>
4+
<add key="disableSourceControlIntegration" value="true" />
5+
</solution>
6+
</configuration>

src/.nuget/NuGet.exe

1.59 MB
Binary file not shown.

src/.nuget/NuGet.targets

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5+
6+
<!-- Enable the restore command to run before builds -->
7+
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
8+
9+
<!-- Property that enables building a package from a project -->
10+
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11+
12+
<!-- Determines if package restore consent is required to restore packages -->
13+
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
14+
15+
<!-- Download NuGet.exe if it does not already exist -->
16+
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
17+
</PropertyGroup>
18+
19+
<ItemGroup Condition=" '$(PackageSources)' == '' ">
20+
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
21+
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
22+
<!--
23+
<PackageSource Include="https://www.nuget.org/api/v2/" />
24+
<PackageSource Include="https://my-nuget-source/nuget/" />
25+
-->
26+
</ItemGroup>
27+
28+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
29+
<!-- Windows specific commands -->
30+
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
31+
</PropertyGroup>
32+
33+
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
34+
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
35+
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
36+
</PropertyGroup>
37+
38+
<PropertyGroup>
39+
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
40+
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
41+
</PropertyGroup>
42+
43+
<PropertyGroup>
44+
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
45+
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
46+
</PropertyGroup>
47+
48+
<PropertyGroup>
49+
<!-- NuGet command -->
50+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
51+
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
52+
53+
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
54+
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>
55+
56+
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
57+
58+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
59+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
60+
61+
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
62+
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
63+
64+
<!-- Commands -->
65+
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
66+
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
67+
68+
<!-- We need to ensure packages are restored prior to assembly resolve -->
69+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
70+
RestorePackages;
71+
$(BuildDependsOn);
72+
</BuildDependsOn>
73+
74+
<!-- Make the build depend on restore packages -->
75+
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
76+
$(BuildDependsOn);
77+
BuildPackage;
78+
</BuildDependsOn>
79+
</PropertyGroup>
80+
81+
<Target Name="CheckPrerequisites">
82+
<!-- Raise an error if we're unable to locate nuget.exe -->
83+
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
84+
<!--
85+
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
86+
This effectively acts as a lock that makes sure that the download operation will only happen once and all
87+
parallel builds will have to wait for it to complete.
88+
-->
89+
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
90+
</Target>
91+
92+
<Target Name="_DownloadNuGet">
93+
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
94+
</Target>
95+
96+
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
97+
<Exec Command="$(RestoreCommand)"
98+
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
99+
100+
<Exec Command="$(RestoreCommand)"
101+
LogStandardErrorAsError="true"
102+
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
103+
</Target>
104+
105+
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
106+
<Exec Command="$(BuildCommand)"
107+
Condition=" '$(OS)' != 'Windows_NT' " />
108+
109+
<Exec Command="$(BuildCommand)"
110+
LogStandardErrorAsError="true"
111+
Condition=" '$(OS)' == 'Windows_NT' " />
112+
</Target>
113+
114+
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
115+
<ParameterGroup>
116+
<OutputFilename ParameterType="System.String" Required="true" />
117+
</ParameterGroup>
118+
<Task>
119+
<Reference Include="System.Core" />
120+
<Using Namespace="System" />
121+
<Using Namespace="System.IO" />
122+
<Using Namespace="System.Net" />
123+
<Using Namespace="Microsoft.Build.Framework" />
124+
<Using Namespace="Microsoft.Build.Utilities" />
125+
<Code Type="Fragment" Language="cs">
126+
<![CDATA[
127+
try {
128+
OutputFilename = Path.GetFullPath(OutputFilename);
129+
130+
Log.LogMessage("Downloading latest version of NuGet.exe...");
131+
WebClient webClient = new WebClient();
132+
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
133+
134+
return true;
135+
}
136+
catch (Exception ex) {
137+
Log.LogErrorFromException(ex);
138+
return false;
139+
}
140+
]]>
141+
</Code>
142+
</Task>
143+
</UsingTask>
144+
</Project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="AzureBlobFileSystemAbsoluteTests.cs" company="James Jackson-South">
3+
// Copyright (c) James Jackson-South and contributors.
4+
// Licensed under the Apache License, Version 2.0.
5+
// </copyright>
6+
// <summary>
7+
// The <see cref="AzureBlobFileSystem" /> absolute tests.
8+
// </summary>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
11+
namespace Our.Umbraco.FileSystemProviders.Azure.Tests
12+
{
13+
using NUnit.Framework;
14+
15+
/// <summary>
16+
/// The <see cref="AzureBlobFileSystem"/> absolute tests.
17+
/// </summary>
18+
[TestFixture]
19+
public class AzureBlobFileSystemAbsoluteTests : AzureBlobFileSystemTestsBase
20+
{
21+
/// <summary>
22+
/// Asserts that the file system correctly resolves the url.
23+
/// </summary>
24+
[Test]
25+
public void ResolveUrl()
26+
{
27+
// Arrange
28+
AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem(true);
29+
30+
// Act
31+
string actual = provider.GetUrl("1010/media.jpg");
32+
33+
// Assert
34+
Assert.AreEqual("http://127.0.0.1:10000/devstoreaccount1/media/1010/media.jpg", actual);
35+
}
36+
37+
/// <summary>
38+
/// Asserts that the file system correctly resolves the url
39+
/// when the input has been prefixed.
40+
/// </summary>
41+
[Test]
42+
public void ResolveUrlPrefixed()
43+
{
44+
// Arrange
45+
AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem(true);
46+
47+
// Act
48+
string actual = provider.GetUrl("media/1010/media.jpg");
49+
50+
// Assert
51+
Assert.AreEqual("http://127.0.0.1:10000/devstoreaccount1/media/1010/media.jpg", actual);
52+
}
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="AzureBlobFileSystemRelativeTests.cs" company="James Jackson-South">
3+
// Copyright (c) James Jackson-South and contributors.
4+
// Licensed under the Apache License, Version 2.0.
5+
// </copyright>
6+
// <summary>
7+
// The <see cref="AzureBlobFileSystem" /> relative tests.
8+
// </summary>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
11+
namespace Our.Umbraco.FileSystemProviders.Azure.Tests
12+
{
13+
using NUnit.Framework;
14+
15+
/// <summary>
16+
/// The <see cref="AzureBlobFileSystem"/> relative tests.
17+
/// </summary>
18+
[TestFixture]
19+
public class AzureBlobFileSystemRelativeTests : AzureBlobFileSystemTestsBase
20+
{
21+
/// <summary>
22+
/// Asserts that the file system correctly resolves the url.
23+
/// </summary>
24+
[Test]
25+
public void ResolveUrl()
26+
{
27+
// Arrange
28+
AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();
29+
30+
// Act
31+
string actual = provider.GetUrl("1010/media.jpg");
32+
33+
// Assert
34+
Assert.AreEqual("/media/1010/media.jpg", actual);
35+
}
36+
37+
/// <summary>
38+
/// Asserts that the file system correctly resolves the url
39+
/// when the input has been prefixed.
40+
/// </summary>
41+
[Test]
42+
public void ResolveUrlPrefixed()
43+
{
44+
// Arrange
45+
AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();
46+
47+
// Act
48+
string actual = provider.GetUrl("media/1010/media.jpg");
49+
50+
// Assert
51+
Assert.AreEqual("/media/1010/media.jpg", actual);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)