Skip to content

Commit fb8a950

Browse files
committed
Started on tidying up the installer project by adding a Constants class, small steps
1 parent 38a7e8e commit fb8a950

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="Constants.cs" company="James Jackson-South">
3+
// Copyright (c) James Jackson-South. All rights reserved.
4+
// Licensed under the Apache License, Version 2.0.
5+
// </copyright>
6+
// <summary>
7+
// Constant strings for use within the application.
8+
// </summary>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
namespace Our.Umbraco.FileSystemProviders.Azure.Installer
11+
{
12+
public static class Constants
13+
{
14+
public const string InstallerPath = "~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/";
15+
public const string FileSystemProvidersConfigFile = "FileSystemProviders.config";
16+
public const string UmbracoConfigPath = "~/Config/";
17+
public const string WebConfigFile = "web.config";
18+
public const string ProviderType = "Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure";
19+
20+
public class ImageProcessor
21+
{
22+
public const string WebAssemblyPath = "~/bin/ImageProcessor.Web.dll";
23+
public const string WebMinRequiredVersion = "4.3.2.0";
24+
public const string ConfigPath = "~/Config/imageprocessor/";
25+
public const string SecurityConfigFile = "security.config";
26+
public const string SecurityServiceType = "ImageProcessor.Web.Services.CloudImageService, ImageProcessor.Web";
27+
public const string SecurityServiceName = "CloudImageService";
28+
29+
}
30+
}
31+
}

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@ namespace Our.Umbraco.FileSystemProviders.Azure.Installer
3535
[PluginController("FileSystemProviders")]
3636
public class InstallerController : UmbracoAuthorizedApiController
3737
{
38-
private const string ProviderType = "Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure";
39-
private static readonly string ImageProcessorWebAssemblyPath = HostingEnvironment.MapPath("~/bin/ImageProcessor.Web.dll");
40-
private static readonly Version ImageProcessorWebMinRequiredVersion = new Version("4.3.2.0");
38+
private static readonly string ImageProcessorWebAssemblyPath = HostingEnvironment.MapPath(Constants.ImageProcessor.WebAssemblyPath);
39+
private static readonly Version ImageProcessorWebMinRequiredVersion = new Version(Constants.ImageProcessor.WebMinRequiredVersion);
4140

42-
private static readonly string ImageProcessorConfigPath = HostingEnvironment.MapPath("~/Config/imageprocessor/");
41+
private static readonly string ImageProcessorConfigPath = HostingEnvironment.MapPath(Constants.ImageProcessor.ConfigPath);
4342

44-
private static readonly string ImageProcessorSecurityConfigPath = HostingEnvironment.MapPath("~/Config/imageprocessor/security.config");
45-
private static readonly string ImageProcessorSecurityDefaultConfigPath = HostingEnvironment.MapPath("~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/security.config");
46-
private static readonly string ImageProcessorSecurityInstallXdtPath = HostingEnvironment.MapPath("~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/security.config.install.xdt");
47-
private static readonly string ImageProcessorSecurityServiceType = "ImageProcessor.Web.Services.CloudImageService, ImageProcessor.Web";
48-
private static readonly string ImageProcessorSecurityServiceName = "CloudImageService";
43+
private static readonly string ImageProcessorSecurityConfigPath = HostingEnvironment.MapPath($"{Constants.ImageProcessor.ConfigPath}{Constants.ImageProcessor.SecurityConfigFile}");
44+
private static readonly string ImageProcessorSecurityDefaultConfigPath = HostingEnvironment.MapPath($"{Constants.InstallerPath}{Constants.ImageProcessor.SecurityConfigFile}");
45+
private static readonly string ImageProcessorSecurityInstallXdtPath = HostingEnvironment.MapPath($"{Constants.InstallerPath}{Constants.ImageProcessor.SecurityConfigFile}.install.xdt");
4946

50-
private readonly string fileSystemProvidersConfigInstallXdtPath = HostingEnvironment.MapPath("~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/FileSystemProviders.config.install.xdt");
51-
private readonly string fileSystemProvidersConfigPath = HostingEnvironment.MapPath("~/Config/FileSystemProviders.config");
47+
private readonly string fileSystemProvidersConfigInstallXdtPath = HostingEnvironment.MapPath($"{Constants.InstallerPath}{Constants.FileSystemProvidersConfigFile}.install.xdt");
48+
private readonly string fileSystemProvidersConfigPath = HostingEnvironment.MapPath($"{Constants.UmbracoConfigPath}{Constants.FileSystemProvidersConfigFile}");
5249

53-
private readonly string webConfigXdtPath = HostingEnvironment.MapPath("~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/web.config.install.xdt");
50+
private readonly string webConfigXdtPath = HostingEnvironment.MapPath($"{Constants.InstallerPath}{Constants.WebConfigFile}.install.xdt");
5451

5552
// /Umbraco/backoffice/FileSystemProviders/Installer/GetParameters
5653
public IEnumerable<Parameter> GetParameters()
@@ -122,7 +119,7 @@ internal static bool SaveParametersToFileSystemProvidersXdt(string xdtPath, IEnu
122119
var strNamespace = "http://schemas.microsoft.com/XML-Document-Transform";
123120
nsMgr.AddNamespace("xdt", strNamespace);
124121

125-
var providerElement = document.SelectSingleNode(string.Format("//Provider[@type = '{0}']", ProviderType));
122+
var providerElement = document.SelectSingleNode($"//Provider[@type = '{Constants.ProviderType}']");
126123
var parametersElement = providerElement.SelectSingleNode("./Parameters");
127124
var parameterRemoveElement = document.CreateNode("element", "Parameters", null);
128125
var tranformAttr = document.CreateAttribute("Transform", strNamespace);
@@ -131,7 +128,7 @@ internal static bool SaveParametersToFileSystemProvidersXdt(string xdtPath, IEnu
131128
parameterRemoveElement.Attributes.Append(tranformAttr);
132129
providerElement.InsertBefore(parameterRemoveElement, parametersElement);
133130

134-
var parameters = document.SelectNodes(string.Format("//Provider[@type = '{0}']/Parameters/add", ProviderType));
131+
var parameters = document.SelectNodes($"//Provider[@type = '{Constants.ProviderType}']/Parameters/add");
135132

136133
if (parameters == null)
137134
{
@@ -213,7 +210,7 @@ internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, str
213210
var document = XmlHelper.OpenAsXmlDocument(xdtPath);
214211

215212
// Set the prefix attribute on both the Remove and InsertIfMissing actions
216-
var rawServices = document.SelectNodes($"//services/service[@name = '{ImageProcessorSecurityServiceName}' and @type = '{ImageProcessorSecurityServiceType}']");
213+
var rawServices = document.SelectNodes($"//services/service[@name = '{Constants.ImageProcessor.SecurityServiceName}' and @type = '{Constants.ImageProcessor.SecurityServiceType}']");
217214
if (rawServices == null)
218215
{
219216
return false;
@@ -225,7 +222,7 @@ internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, str
225222
}
226223

227224
// Set the settings within the InsertIfMissing action
228-
var rawSettings = document.SelectNodes($"//services/service[@prefix = '{prefix}/' and @name = '{ImageProcessorSecurityServiceName}' and @type = '{ImageProcessorSecurityServiceType}']/settings/setting");
225+
var rawSettings = document.SelectNodes($"//services/service[@prefix = '{prefix}/' and @name = '{Constants.ImageProcessor.SecurityServiceName}' and @type = '{Constants.ImageProcessor.SecurityServiceType}']/settings/setting");
229226
if (rawSettings == null)
230227
{
231228
return false;
@@ -280,7 +277,7 @@ internal static IEnumerable<Parameter> GetParametersFromXml(string xmlPath)
280277

281278
var document = XmlHelper.OpenAsXmlDocument(xmlPath);
282279

283-
var parameters = document.SelectNodes(string.Format("//Provider[@type = '{0}']/Parameters/add", ProviderType));
280+
var parameters = document.SelectNodes($"//Provider[@type = '{Constants.ProviderType}']/Parameters/add");
284281

285282
if (parameters == null)
286283
{
@@ -363,7 +360,7 @@ private static bool TestAzureCredentials(string connectionString, string contain
363360
}
364361
catch (Exception e)
365362
{
366-
LogHelper.Error<InstallerController>(string.Format("Error validating Azure storage connection: {0}", e.Message), e);
363+
LogHelper.Error<InstallerController>($"Error validating Azure storage connection: {e.Message}", e);
367364
return false;
368365
}
369366

src/UmbracoFileSystemProviders.Azure.Installer/UmbracoFileSystemProviders.Azure.Installer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
</Reference>
254254
</ItemGroup>
255255
<ItemGroup>
256+
<Compile Include="Constants.cs" />
256257
<Compile Include="Enums\InstallerStatus.cs" />
257258
<Compile Include="Helpers.cs" />
258259
<Compile Include="Properties\AssemblyInfo.cs" />

0 commit comments

Comments
 (0)