22// Copyright (c) James Jackson-South, Jeavon Leopold, and contributors. All rights reserved.
33// Licensed under the Apache License, Version 2.0.
44// </copyright>
5+
56namespace Our . Umbraco . FileSystemProviders . Azure . Installer
67{
78 using System ;
89 using System . Web ;
910 using System . Xml ;
10- using global ::Umbraco . Core . _Legacy . PackageActions ;
11+ using System . Xml . Linq ;
12+
1113 using global ::Umbraco . Core . Composing ;
1214 using global ::Umbraco . Core . Logging ;
13- using global ::Umbraco . Web . _Legacy . PackageActions ;
15+ using global ::Umbraco . Core . PackageActions ;
16+ using global ::Umbraco . Core ;
17+
1418 using Microsoft . Web . XmlTransform ;
1519
1620 /// <summary>
@@ -30,7 +34,7 @@ public string Alias()
3034 }
3135
3236 /// <inheritdoc/>
33- public bool Execute ( string packageName , XmlNode xmlData )
37+ public bool Execute ( string packageName , XElement xmlData )
3438 {
3539 return this . Transform ( packageName , xmlData ) ;
3640 }
@@ -47,7 +51,7 @@ public XmlNode SampleXml()
4751 }
4852
4953 /// <inheritdoc/>
50- public bool Undo ( string packageName , XmlNode xmlData )
54+ public bool Undo ( string packageName , XElement xmlData )
5155 {
5256 return this . Transform ( packageName , xmlData , true ) ;
5357 }
@@ -59,12 +63,12 @@ public bool Undo(string packageName, XmlNode xmlData)
5963 /// <param name="xmlData">The XML data</param>
6064 /// <param name="uninstall">Whether to uninstall.</param>
6165 /// <returns><c>true</c> if the transform is sucessful.</returns>
62- private bool Transform ( string packageName , XmlNode xmlData , bool uninstall = false )
66+ private bool Transform ( string packageName , XElement xmlData , bool uninstall = false )
6367 {
6468 // The config file we want to modify
65- if ( xmlData . Attributes != null )
69+ if ( xmlData . Attributes ( ) != null )
6670 {
67- string file = xmlData . Attributes . GetNamedItem ( "file" ) . Value ;
71+ var file = AttributeValue < string > ( xmlData , "file" ) ;
6872
6973 string sourceDocFileName = VirtualPathUtility . ToAbsolute ( file ) ;
7074
@@ -74,8 +78,8 @@ private bool Transform(string packageName, XmlNode xmlData, bool uninstall = fal
7478 {
7579 fileEnd = $ "un{ fileEnd } ";
7680 }
77-
78- string xdtfile = $ "{ xmlData . Attributes . GetNamedItem ( "xdtfile" ) . Value } .{ fileEnd } ";
81+
82+ string xdtfile = $ "{ AttributeValue < string > ( xmlData , "xdtfile" ) } .{ fileEnd } ";
7983 string xdtFileName = VirtualPathUtility . ToAbsolute ( xdtfile ) ;
8084
8185 // The translation at-hand
@@ -108,6 +112,22 @@ private bool Transform(string packageName, XmlNode xmlData, bool uninstall = fal
108112
109113 return true ;
110114 }
115+
116+ public static T AttributeValue < T > ( XElement xml , string attributeName )
117+ {
118+ if ( xml == null ) throw new ArgumentNullException ( "xml" ) ;
119+ if ( xml . HasAttributes == false ) return default ( T ) ;
120+
121+ if ( xml . Attribute ( attributeName ) == null )
122+ return default ( T ) ;
123+
124+ var val = xml . Attribute ( attributeName ) . Value ;
125+ var result = val . TryConvertTo < T > ( ) ;
126+ if ( result . Success )
127+ return result . Result ;
128+
129+ return default ( T ) ;
130+ }
111131 }
112132 }
113133}
0 commit comments