Skip to content

Commit 6f6f478

Browse files
Merge pull request #33 from KennethJakobsen/CDN
Added Cdn & fixed tests accordingly
2 parents e48d775 + df70ca8 commit 6f6f478

File tree

9 files changed

+61
-18
lines changed

9 files changed

+61
-18
lines changed

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
6565
var connection = parameters.SingleOrDefault(k => k.Key == "connectionString").Value;
6666
var containerName = parameters.SingleOrDefault(k => k.Key == "containerName").Value;
6767
var rootUrl = parameters.SingleOrDefault(k => k.Key == "rootUrl").Value;
68+
var cdnUrl = parameters.SingleOrDefault(k => k.Key == "cdnUrl").Value;
6869

6970
if (!TestAzureCredentials(connection, containerName))
7071
{

src/UmbracoFileSystemProviders.Azure.Installer/Properties/VersionInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515
// You can specify all the values or you can default the Build and Revision Numbers
1616
// by using the '*' as shown below:
17-
// [assembly: AssemblyVersion("0.5.0.10")]
18-
[assembly: AssemblyVersion("0.5.0.0")]
19-
[assembly: AssemblyFileVersion("0.5.0.0")]
20-
[assembly: AssemblyInformationalVersion("0.5.0")]
17+
// [assembly: AssemblyVersion("0.5.2.1")]
18+
[assembly: AssemblyVersion("0.5.2.1")]
19+
[assembly: AssemblyFileVersion("0.5.2.1")]
20+
[assembly: AssemblyInformationalVersion("0.5.2-alpha")]

src/UmbracoFileSystemProviders.Azure.Tests/FileSystemProviders.config.install.xdt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</Provider>
99

1010
<Provider alias="media" type="Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure" xdt:Locator="Match(type)" xdt:Transform="InsertIfMissing">
11-
<Parameters xdt:Transform="InsertIfMissing">
11+
<Parameters xdt:Transform="InsertIfMissing">
1212
<add key="containerName" value="media" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
1313
<add key="rootUrl" value="http://[myAccountName].blob.core.windows.net/" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
1414
<add key="connectionString" value="DefaultEndpointsProtocol=https;AccountName=[myAccountName];AccountKey=[myAccountKey]" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
@@ -17,6 +17,7 @@
1717
Defaults to 365 days.
1818
-->
1919
<add key="maxDays" value="365" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
20+
<add key="cdnUrl" value="[myCDN].azureedge.net" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
2021
</Parameters>
2122
</Provider>
2223
<!--

src/UmbracoFileSystemProviders.Azure.Tests/FileSystemProviders.upgrade.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Defaults to 365 days.
1414
-->
1515
<add key="maxDays" value="365"/>
16+
<add key="cdnUrl" value="[myCDN].azureedge.net" />
1617
</Parameters>
1718
</Provider>
1819

src/UmbracoFileSystemProviders.Azure.Tests/InstallerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void CheckXdtFirstParameterKey()
2525
public void CheckXdtNumberOfParameters()
2626
{
2727
var parameters = InstallerController.GetParametersFromXml("FileSystemProviders.config.install.xdt");
28-
Assert.AreEqual(4, parameters.Count());
28+
Assert.AreEqual(5, parameters.Count());
2929
}
3030

3131
[Test]

src/UmbracoFileSystemProviders.Azure.Tests/UmbracoFileSystemProviders.Azure.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@
276276
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0-beta014\analyzers\dotnet\cs\Newtonsoft.Json.dll" />
277277
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0-beta014\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
278278
</ItemGroup>
279+
<ItemGroup>
280+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
281+
</ItemGroup>
279282
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
280283
<Import Project="..\packages\StyleCop.Analyzers.1.0.0-beta014\build\StyleCop.Analyzers.targets" Condition="Exists('..\packages\StyleCop.Analyzers.1.0.0-beta014\build\StyleCop.Analyzers.targets')" />
281284
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

src/UmbracoFileSystemProviders.Azure/AzureBlobFileSystem.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class AzureBlobFileSystem : IFileSystem
2424
/// <param name="containerName">The container name.</param>
2525
/// <param name="rootUrl">The root url.</param>
2626
/// <param name="connectionString">The connection string.</param>
27-
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString) :
28-
this(containerName, rootUrl, connectionString, "365")
27+
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString)
28+
: this(containerName, rootUrl, connectionString, "365", string.Empty)
2929
{
3030
}
3131

@@ -37,8 +37,21 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
3737
/// <param name="connectionString">The connection string.</param>
3838
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
3939
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays)
40+
: this(containerName, rootUrl, connectionString, maxDays, string.Empty)
4041
{
41-
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays);
42+
}
43+
44+
/// <summary>
45+
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
46+
/// </summary>
47+
/// <param name="containerName">The container name.</param>
48+
/// <param name="rootUrl">The root url.</param>
49+
/// <param name="connectionString">The connection string.</param>
50+
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
51+
/// <param name="cdnUrl">Url to the CDN on which you wish to expose the ressource</param>
52+
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays, string cdnUrl)
53+
{
54+
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, cdnUrl);
4255
}
4356

4457
/// <summary>

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ internal class AzureFileSystem : IFileSystem
6262
/// </summary>
6363
private readonly string rootUrl;
6464

65+
/// <summary>
66+
/// The url of the CDN
67+
/// </summary>
68+
private readonly string cdnUrl;
69+
6570
/// <summary>
6671
/// The cloud media blob container.
6772
/// </summary>
@@ -77,7 +82,7 @@ internal class AzureFileSystem : IFileSystem
7782
/// <exception cref="ArgumentNullException">
7883
/// Thrown if <paramref name="containerName"/> is null or whitespace.
7984
/// </exception>
80-
private AzureFileSystem(string containerName, string rootUrl, string connectionString, int maxDays)
85+
private AzureFileSystem(string containerName, string rootUrl, string connectionString, int maxDays, string cdnUrl)
8186
{
8287
if (string.IsNullOrWhiteSpace(containerName))
8388
{
@@ -111,10 +116,19 @@ private AzureFileSystem(string containerName, string rootUrl, string connectionS
111116
rootUrl = rootUrl.Trim() + "/";
112117
}
113118

119+
if (!string.IsNullOrEmpty(cdnUrl))
120+
{
121+
if (!cdnUrl.Trim().EndsWith("/"))
122+
{
123+
cdnUrl = cdnUrl.Trim() + "/";
124+
}
125+
126+
this.cdnUrl = cdnUrl + containerName + "/";
127+
}
128+
114129
this.rootUrl = rootUrl + containerName + "/";
115130
this.ContainerName = containerName;
116131
this.MaxDays = maxDays;
117-
118132
this.LogHelper = new WrappedLogHelper();
119133
this.MimeTypeResolver = new MimeTypeResolver();
120134
}
@@ -146,8 +160,9 @@ private AzureFileSystem(string containerName, string rootUrl, string connectionS
146160
/// <param name="rootUrl">The root url.</param>
147161
/// <param name="connectionString">The connection string.</param>
148162
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
163+
/// <param name="cdnUrl">Url to the CDN</param>
149164
/// <returns>The <see cref="AzureFileSystem"/></returns>
150-
public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays)
165+
public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays, string cdnUrl)
151166
{
152167
lock (Locker)
153168
{
@@ -159,7 +174,7 @@ public static AzureFileSystem GetInstance(string containerName, string rootUrl,
159174
max = 365;
160175
}
161176

162-
fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max);
177+
fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, cdnUrl);
163178
}
164179

165180
return fileSystem;
@@ -556,7 +571,16 @@ private CloudBlobDirectory GetDirectoryReference(string path)
556571
private string ResolveUrl(string path, bool relative)
557572
{
558573
// First create the full url
559-
Uri url = new Uri(new Uri(this.rootUrl, UriKind.Absolute), this.FixPath(path));
574+
Uri url;
575+
576+
if (!string.IsNullOrEmpty(this.cdnUrl))
577+
{
578+
url = new Uri(new Uri(this.cdnUrl, UriKind.Absolute), this.FixPath(path));
579+
}
580+
else
581+
{
582+
url = new Uri(new Uri(this.rootUrl, UriKind.Absolute), this.FixPath(path));
583+
}
560584

561585
if (!relative)
562586
{

src/UmbracoFileSystemProviders.Azure/Properties/VersionInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515
// You can specify all the values or you can default the Build and Revision Numbers
1616
// by using the '*' as shown below:
17-
// [assembly: AssemblyVersion("0.5.0.10")]
18-
[assembly: AssemblyVersion("0.5.0.0")]
19-
[assembly: AssemblyFileVersion("0.5.0.0")]
20-
[assembly: AssemblyInformationalVersion("0.5.0")]
17+
// [assembly: AssemblyVersion("0.5.2.1")]
18+
[assembly: AssemblyVersion("0.5.2.1")]
19+
[assembly: AssemblyFileVersion("0.5.2.1")]
20+
[assembly: AssemblyInformationalVersion("0.5.2-alpha")]

0 commit comments

Comments
 (0)