@@ -129,38 +129,37 @@ protected override void ValidateConfiguration()
129
129
doc . Load ( DiagnosticsConfigurationPath ) ;
130
130
131
131
// Make sure the configuration element exist
132
- var config = doc . SelectSingleNode ( "//ns:WadCfg" , ns ) ?? doc . SelectSingleNode ( "//ns:WadCfgBlob" , ns ) ;
133
- if ( config == null )
132
+ var configElement = doc . SelectSingleNode ( "//ns:WadCfg" , ns ) ?? doc . SelectSingleNode ( "//ns:WadCfgBlob" , ns ) ;
133
+ if ( configElement == null )
134
134
{
135
135
throw new ArgumentException ( Resources . DiagnosticsExtensionPaaSConfigElementNotDefined ) ;
136
136
}
137
137
138
138
// The element <StorageAccount> is not meant to be set by the user in the public config.
139
139
// Make sure it matches the storage account in the private config.
140
- var node = doc . SelectSingleNode ( "//ns:StorageAccount" , ns ) ;
141
- if ( node != null )
140
+ var storageAccountElement = doc . SelectSingleNode ( "//ns:StorageAccount" , ns ) ;
141
+ if ( storageAccountElement != null )
142
142
{
143
143
// The StorageAccount is empty, we must set it
144
- if ( string . IsNullOrEmpty ( node . InnerText ) )
144
+ if ( string . IsNullOrEmpty ( storageAccountElement . InnerText ) )
145
145
{
146
- var insertIndex = PublicConfiguration . IndexOf ( "</StorageAccount>" ) ;
147
- PublicConfiguration = PublicConfiguration . Insert ( insertIndex , StorageAccountName ) ;
146
+ storageAccountElement . InnerText = StorageAccountName ;
147
+ PublicConfiguration = doc . OuterXml ;
148
148
}
149
- else if ( ! string . IsNullOrEmpty ( node . InnerText ) && string . Compare ( node . InnerText , StorageAccountName , true ) != 0 )
149
+ else if ( ! string . IsNullOrEmpty ( storageAccountElement . InnerText ) && string . Compare ( storageAccountElement . InnerText , StorageAccountName , true ) != 0 )
150
150
{
151
151
throw new ArgumentException ( Resources . DiagnosticsExtensionNoMatchStorageAccount ) ;
152
152
}
153
153
}
154
154
else
155
155
{
156
- // the StorageAccount is not there. we must set it
157
- string storageAccountElem = "\n <StorageAccount>" + StorageAccountName + "</StorageAccount>\n " ;
158
-
159
- // insert it after </WadCfg> or </WadCfgBlob>
160
- int wadCfgEndIndex = PublicConfiguration . IndexOf ( "</WadCfg>" ) ;
161
- int wadCfgBlobEndIndex = PublicConfiguration . IndexOf ( "</WadCfgBlob>" ) ;
162
- int insertIndex = wadCfgEndIndex >= 0 ? wadCfgEndIndex + "</WadCfg>" . Length : wadCfgBlobEndIndex + "</WadCfgBlob>" . Length ;
163
- PublicConfiguration = PublicConfiguration . Insert ( insertIndex , storageAccountElem ) ;
156
+ // The StorageAccount is not there. we must set it
157
+ storageAccountElement = doc . CreateElement ( "StorageAccount" , XmlNamespace ) ;
158
+ storageAccountElement . InnerText = StorageAccountName ;
159
+
160
+ // Insert it after <WadCfg> or <WadCfgBlob>
161
+ configElement . ParentNode . AppendChild ( storageAccountElement ) ;
162
+ PublicConfiguration = doc . OuterXml ;
164
163
}
165
164
166
165
// Make sure the storage account name in PrivateConfig matches.
0 commit comments