Skip to content

Commit e05fcf7

Browse files
committed
More installer WIP
1 parent 80a4ad4 commit e05fcf7

File tree

12 files changed

+402
-9
lines changed

12 files changed

+402
-9
lines changed

build/transforms/web.config.install.xdt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?xml version="1.0"?>
22
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
3+
<appSettings>
4+
<add key="AzureBlobFileSystem.ContainerName:media" value="media" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
5+
<add key="AzureBlobFileSystem.RootUrl:media" value="https://[myAccountName].blob.core.windows.net/" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing"/>
6+
<add key="AzureBlobFileSystem.ConnectionString:media" value="DefaultEndpointsProtocol=https;AccountName=[myAccountName];AccountKey=[myAccountKey]" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing"/>
7+
<add key="AzureBlobFileSystem.MaxDays:media" value="365" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing"/>
8+
<add key="AzureBlobFileSystem.UseDefaultRoute:media" value="true" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing"/>
9+
<add key="AzureBlobFileSystem.UsePrivateContainer:media" value="false" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing"/>
10+
</appSettings>
11+
312
<location path="media" xdt:Locator="Match(path)" xdt:Transform="InsertIfMissing">
413
<system.webServer xdt:Transform="InsertIfMissing">
514
<handlers xdt:Transform="InsertIfMissing">

build/transforms/web.config.uninstall.xdt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?xml version="1.0"?>
22
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
3+
<appSettings>
4+
<add key="AzureBlobFileSystem.ContainerName:media" xdt:Locator="Match(key)" xdt:Transform="Remove" />
5+
<add key="AzureBlobFileSystem.RootUrl:media" xdt:Locator="Match(key)" xdt:Transform="Remove"/>
6+
<add key="AzureBlobFileSystem.ConnectionString:media" xdt:Locator="Match(key)" xdt:Transform="Remove"/>
7+
<add key="AzureBlobFileSystem.MaxDays:media" xdt:Locator="Match(key)" xdt:Transform="Remove"/>
8+
<add key="AzureBlobFileSystem.UseDefaultRoute:media" xdt:Locator="Match(key)" xdt:Transform="Remove"/>
9+
<add key="AzureBlobFileSystem.UsePrivateContainer:media" xdt:Locator="Match(key)" xdt:Transform="Remove"/>
10+
</appSettings>
11+
312
<location path="media" xdt:Locator="Match(path)">
413
<system.webServer>
514
<handlers>

src/UmbracoFileSystemProviders.Azure.Installer/Configurator/Views/Configure.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<form name="paramForm" class="form-horizontal" role="form">
1616
<div ng-repeat="param in parameters" class="control-group">
1717
<ng-form name="form">
18-
<label class="control-label" for="param.key">{{ capitalizeFirstLetter(param.key) }}</label>
18+
<label class="control-label" for="{{param.key}}" style="width:160px">{{ capitalizeFirstLetter(param.key) }}</label>
1919
<div class="controls">
2020
<span ng-if="getInputType(param.key) === 'checkbox'" ng-include="'/App_Plugins/UmbracoFileSystemProviders/Azure/Install/Configurator/Views/checkbox.htm'"></span>
2121
<span ng-if="getInputType(param.key) === 'text'" ng-include="'/App_Plugins/UmbracoFileSystemProviders/Azure/Install/Configurator/Views/textfield.htm'"></span>

src/UmbracoFileSystemProviders.Azure.Installer/Configurator/Views/checkbox.htm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<input class="input-block-level"
2-
dynamic-name="param.key"
2+
style="width:80%"
3+
name="{{param.key}}"
34
type="checkbox"
45
ng-model="param.value"
56
ng-true-value="true"

src/UmbracoFileSystemProviders.Azure.Installer/Configurator/Views/textfield.htm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<input class="input-block-level"
2+
style="width:80%"
23
dynamic-name="param.key"
34
type="text"
45
ng-model="param.value"

src/UmbracoFileSystemProviders.Azure.Installer/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Our.Umbraco.FileSystemProviders.Azure.Installer
1010
/// </summary>
1111
public static class Constants
1212
{
13+
public const string MediaProviderPostFix = "media";
1314
/// <summary>
1415
/// The installer path for the plugin.
1516
/// </summary>

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,16 @@ public class InstallerController : UmbracoAuthorizedApiController
4545
private readonly string fileSystemProvidersConfigPath = HostingEnvironment.MapPath($"{Constants.UmbracoConfigPath}{Constants.FileSystemProvidersConfigFile}");
4646

4747
private readonly string webConfigXdtPath = HostingEnvironment.MapPath($"{Constants.InstallerPath}{Constants.WebConfigFile}.install.xdt");
48+
private readonly string webConfigPath = HostingEnvironment.MapPath($"/{Constants.WebConfigFile}");
49+
4850

4951
private readonly string mediaWebConfigXdtPath = HostingEnvironment.MapPath($"{Constants.InstallerPath}{Constants.MediaWebConfigXdtFile}.install.xdt");
5052

53+
public InstallerController()
54+
{
55+
56+
}
57+
5158
/// <summary>
5259
/// Gets the parameters from the XDT transform file.
5360
/// </summary>
@@ -57,7 +64,7 @@ public class InstallerController : UmbracoAuthorizedApiController
5764
/// <returns>The <see cref="IEnumerable{Parameter}"/></returns>
5865
public IEnumerable<Parameter> GetParameters()
5966
{
60-
return GetParametersFromXdt(this.fileSystemProvidersConfigInstallXdtPath, this.fileSystemProvidersConfigPath);
67+
return GetParametersFromXdt(this.webConfigXdtPath, this.webConfigPath);
6168
}
6269

6370
/// <summary>
@@ -304,9 +311,9 @@ internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, str
304311
/// <returns>The <see cref="IEnumerable{Parameter}"/>.</returns>
305312
internal static IEnumerable<Parameter> GetParametersFromXdt(string xdtPath, string configPath)
306313
{
307-
// For package upgrades check for configured values in existing FileSystemProviders.config and merge with the Parameters from the XDT file (there could be new ones)
308-
List<Parameter> xdtParameters = GetParametersFromXml(xdtPath).ToList();
309-
List<Parameter> currentConfigParameters = GetParametersFromXml(configPath).ToList();
314+
// For package upgrades check for configured values in existing Web.Config and merge with the settings from the XDT file (there could be new ones)
315+
List<Parameter> xdtParameters = GetAppSettingsFromConfig(xdtPath).ToList();
316+
List<Parameter> currentConfigParameters = GetAppSettingsFromConfig(configPath).ToList();
310317

311318
foreach (Parameter parameter in xdtParameters)
312319
{
@@ -320,9 +327,48 @@ internal static IEnumerable<Parameter> GetParametersFromXdt(string xdtPath, stri
320327
}
321328
}
322329

330+
foreach (var setting in xdtParameters)
331+
{
332+
setting.Key = setting.Key.TrimEnd(":media");
333+
setting.Key = setting.Key.TrimStart($"{Azure.Constants.Configuration.ConfigrationSettingPrefix}.");
334+
}
335+
323336
return xdtParameters;
324337
}
325338

339+
/// <summary>
340+
/// Gets the parameter collection from the XML file.
341+
/// </summary>
342+
/// <param name="xmlPath">The file path</param>
343+
/// <returns>The <see cref="IEnumerable{Parameter}"/>.</returns>
344+
internal static IEnumerable<Parameter> GetAppSettingsFromConfig(string xmlPath)
345+
{
346+
List<Parameter> settings = new List<Parameter>();
347+
348+
XmlDocument document = XmlHelper.OpenAsXmlDocument(xmlPath);
349+
350+
XmlNodeList parameters = document.SelectNodes($"//appSettings/add");
351+
352+
if (parameters == null)
353+
{
354+
return settings;
355+
}
356+
357+
foreach (XmlElement parameter in parameters)
358+
{
359+
if (parameter.GetAttribute("key").StartsWith(Azure.Constants.Configuration.ConfigrationSettingPrefix) && parameter.GetAttribute("key").EndsWith($":{Constants.MediaProviderPostFix}"))
360+
{
361+
settings.Add(new Parameter
362+
{
363+
Key = parameter.GetAttribute("key"),
364+
Value = parameter.GetAttribute("value")
365+
});
366+
}
367+
}
368+
369+
return settings;
370+
}
371+
326372
/// <summary>
327373
/// Gets the parameter collection from the XML file.
328374
/// </summary>

src/UmbracoFileSystemProviders.Azure.Tests/InstallerTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ public void CheckUpgradeRootUrlParameter()
5353
[Test]
5454
public void CheckNewInstallDefaultConfig()
5555
{
56-
IEnumerable<Parameter> parameters = InstallerController.GetParametersFromXdt("..\\..\\build\\transforms\\FileSystemProviders.config.install.xdt", "FileSystemProviders.default.config");
57-
Assert.AreEqual("http://[myAccountName].blob.core.windows.net/", parameters.Single(k => k.Key == "rootUrl").Value);
56+
IEnumerable<Parameter> parameters = InstallerController.GetParametersFromXdt("..\\..\\build\\transforms\\web.config.install.xdt", "web.default.config");
57+
Assert.AreEqual("https://[myAccountName].blob.core.windows.net/", parameters.Single(k => k.Key == "RootUrl").Value);
58+
}
59+
60+
[Test]
61+
public void CheckGetAppSettingsFromXDT()
62+
{
63+
IEnumerable<Parameter> settings = InstallerController.GetAppSettingsFromConfig("..\\..\\build\\transforms\\web.config.install.xdt");
64+
Assert.AreEqual(6, settings.Count());
5865
}
5966
}
6067
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@
314314
<None Include="FileSystemProviders.upgrade.config" />
315315
<None Include="packages.config" />
316316
<AdditionalFiles Include="stylecop.json" />
317+
<None Include="web.default.config" />
317318
</ItemGroup>
318319
<ItemGroup>
319320
<ProjectReference Include="..\UmbracoFileSystemProviders.Azure.Installer\UmbracoFileSystemProviders.Azure.Installer.csproj">

0 commit comments

Comments
 (0)