1
1
// --------------------------------------------------------------------------------------------------------------------
2
2
// <copyright file="InstallerController.cs" company="James Jackson-South">
3
- // Copyright (c) James Jackson-South. All rights reserved. Licensed under the Apache License, Version 2.0.
3
+ // Copyright (c) James Jackson-South. All rights reserved.
4
+ // Licensed under the Apache License, Version 2.0.
4
5
// </copyright>
5
6
// --------------------------------------------------------------------------------------------------------------------
6
7
7
- using System . Configuration ;
8
8
using System . Runtime . CompilerServices ;
9
- using Microsoft . WindowsAzure . Storage ;
10
- using Microsoft . WindowsAzure . Storage . Blob ;
11
- using Our . Umbraco . FileSystemProviders . Azure . Installer . Enums ;
12
9
10
+ // ReSharper disable InconsistentNaming
13
11
[ assembly: InternalsVisibleTo ( "Our.Umbraco.FileSystemProviders.Azure.Tests" ) ]
14
12
namespace Our . Umbraco . FileSystemProviders . Azure . Installer
15
13
{
16
14
using System ;
17
15
using System . Collections . Generic ;
16
+ using System . Configuration ;
18
17
using System . Linq ;
19
18
using System . Web . Hosting ;
20
19
using System . Web . Http ;
21
20
using System . Xml ;
22
21
22
+ using Microsoft . WindowsAzure . Storage ;
23
+
23
24
using global ::Umbraco . Core ;
24
25
using global ::Umbraco . Core . Logging ;
25
26
using global ::Umbraco . Web . Mvc ;
26
27
using global ::Umbraco . Web . WebApi ;
27
28
using umbraco . cms . businesslogic . packager . standardPackageActions ;
28
29
30
+ using Enums ;
29
31
using Models ;
30
32
31
33
[ PluginController ( "FileSystemProviders" ) ]
32
34
public class InstallerController : UmbracoAuthorizedApiController
33
35
{
34
36
private const string ProviderType = "Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure" ;
35
- private readonly string _fileSystemProvidersConfigInstallXdtPath = HostingEnvironment . MapPath ( "~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/FileSystemProviders.config.install.xdt" ) ;
36
- private readonly string _fileSystemProvidersConfigPath = HostingEnvironment . MapPath ( "~/Config/FileSystemProviders.config" ) ;
37
+ private readonly string fileSystemProvidersConfigInstallXdtPath = HostingEnvironment . MapPath ( "~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/FileSystemProviders.config.install.xdt" ) ;
38
+ private readonly string fileSystemProvidersConfigPath = HostingEnvironment . MapPath ( "~/Config/FileSystemProviders.config" ) ;
37
39
38
40
39
41
// /Umbraco/backoffice/FileSystemProviders/Installer/GetParameters
40
42
public IEnumerable < Parameter > GetParameters ( )
41
43
{
42
- return GetParametersFromXdt ( _fileSystemProvidersConfigInstallXdtPath , _fileSystemProvidersConfigPath ) ;
44
+ return GetParametersFromXdt ( this . fileSystemProvidersConfigInstallXdtPath , this . fileSystemProvidersConfigPath ) ;
43
45
}
44
46
45
47
// /Umbraco/backoffice/FileSystemProviders/Installer/PostParameters
@@ -49,12 +51,12 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
49
51
var connection = parameters . SingleOrDefault ( k => k . Key == "connectionString" ) . Value ;
50
52
var containerName = parameters . SingleOrDefault ( k => k . Key == "containerName" ) . Value ;
51
53
52
- if ( ! this . TestAzureCredentials ( connection , containerName ) )
54
+ if ( ! TestAzureCredentials ( connection , containerName ) )
53
55
{
54
56
return InstallerStatus . ConnectionError ;
55
57
}
56
58
57
- if ( SaveParametersToXdt ( _fileSystemProvidersConfigInstallXdtPath , parameters ) )
59
+ if ( SaveParametersToXdt ( this . fileSystemProvidersConfigInstallXdtPath , parameters ) )
58
60
{
59
61
if ( ! ExecuteFileSystemConfigTransform ( ) || ! ExecuteWebConfigTransform ( ) )
60
62
{
@@ -164,22 +166,32 @@ internal static IEnumerable<Parameter> GetParametersFromXml(string xmlPath)
164
166
return settings ;
165
167
}
166
168
167
- private bool TestAzureCredentials ( string connectionString , string containerName )
169
+ private static bool ExecuteFileSystemConfigTransform ( )
170
+ {
171
+ var transFormConfigAction = helper . parseStringToXmlNode ( "<Action runat=\" install\" undo=\" true\" alias=\" UmbracoFileSystemProviders.Azure.TransformConfig\" file=\" ~/Config/FileSystemProviders.config\" xdtfile=\" ~/app_plugins/UmbracoFileSystemProviders/Azure/install/FileSystemProviders.config\" >" +
172
+ "</Action>" ) . FirstChild ;
173
+
174
+ var transformConfig = new PackageActions . TransformConfig ( ) ;
175
+ return transformConfig . Execute ( "UmbracoFileSystemProviders.Azure" , transFormConfigAction ) ;
176
+ }
177
+
178
+ private static bool ExecuteWebConfigTransform ( )
179
+ {
180
+ var transFormConfigAction = helper . parseStringToXmlNode ( "<Action runat=\" install\" undo=\" true\" alias=\" UmbracoFileSystemProviders.Azure.TransformConfig\" file=\" ~/web.config\" xdtfile=\" ~/app_plugins/UmbracoFileSystemProviders/Azure/install/web.config\" >" +
181
+ "</Action>" ) . FirstChild ;
182
+
183
+ var transformConfig = new PackageActions . TransformConfig ( ) ;
184
+ return transformConfig . Execute ( "UmbracoFileSystemProviders.Azure" , transFormConfigAction ) ;
185
+ }
186
+
187
+ private static bool TestAzureCredentials ( string connectionString , string containerName )
168
188
{
169
189
var useEmulator = ConfigurationManager . AppSettings [ Azure . Constants . Configuration . UseStorageEmulatorKey ] != null
170
190
&& ConfigurationManager . AppSettings [ Azure . Constants . Configuration . UseStorageEmulatorKey ]
171
191
. Equals ( "true" , StringComparison . InvariantCultureIgnoreCase ) ;
172
192
try
173
193
{
174
- CloudStorageAccount cloudStorageAccount ;
175
- if ( useEmulator )
176
- {
177
- cloudStorageAccount = CloudStorageAccount . DevelopmentStorageAccount ;
178
- }
179
- else
180
- {
181
- cloudStorageAccount = CloudStorageAccount . Parse ( connectionString ) ;
182
- }
194
+ var cloudStorageAccount = useEmulator ? CloudStorageAccount . DevelopmentStorageAccount : CloudStorageAccount . Parse ( connectionString ) ;
183
195
184
196
var cloudBlobClient = cloudStorageAccount . CreateCloudBlobClient ( ) ;
185
197
var blobContainer = cloudBlobClient . GetContainerReference ( containerName ) ;
@@ -195,23 +207,5 @@ private bool TestAzureCredentials(string connectionString, string containerName)
195
207
196
208
return true ;
197
209
}
198
-
199
- private static bool ExecuteFileSystemConfigTransform ( )
200
- {
201
- var transFormConfigAction = helper . parseStringToXmlNode ( "<Action runat=\" install\" undo=\" true\" alias=\" UmbracoFileSystemProviders.Azure.TransformConfig\" file=\" ~/Config/FileSystemProviders.config\" xdtfile=\" ~/app_plugins/UmbracoFileSystemProviders/Azure/install/FileSystemProviders.config\" >" +
202
- "</Action>" ) . FirstChild ;
203
-
204
- var transformConfig = new PackageActions . TransformConfig ( ) ;
205
- return transformConfig . Execute ( "UmbracoFileSystemProviders.Azure" , transFormConfigAction ) ;
206
- }
207
-
208
- private static bool ExecuteWebConfigTransform ( )
209
- {
210
- var transFormConfigAction = helper . parseStringToXmlNode ( "<Action runat=\" install\" undo=\" true\" alias=\" UmbracoFileSystemProviders.Azure.TransformConfig\" file=\" ~/web.config\" xdtfile=\" ~/app_plugins/UmbracoFileSystemProviders/Azure/install/web.config\" >" +
211
- "</Action>" ) . FirstChild ;
212
-
213
- var transformConfig = new PackageActions . TransformConfig ( ) ;
214
- return transformConfig . Execute ( "UmbracoFileSystemProviders.Azure" , transFormConfigAction ) ;
215
- }
216
210
}
217
211
}
0 commit comments