@@ -115,59 +115,48 @@ protected override void ValidateConfiguration()
115
115
}
116
116
}
117
117
118
- var publicConfigElem = DiagnosticsHelper . GetPublicConfigXElementFromXmlFile ( this . DiagnosticsConfigurationPath ) ;
119
- if ( publicConfigElem == null )
120
- {
121
- throw new ArgumentException ( Resources . DiagnosticsExtensionNullPublicConfig ) ;
122
- }
123
- publicConfigElem . SetAttributeValue ( "xmlns" , XmlNamespace ) ;
124
- PublicConfiguration = publicConfigElem . ToString ( ) ;
125
-
126
118
XmlDocument doc = new XmlDocument ( ) ;
127
119
XmlNamespaceManager ns = new XmlNamespaceManager ( doc . NameTable ) ;
128
120
ns . AddNamespace ( "ns" , XmlNamespace ) ;
129
121
doc . Load ( DiagnosticsConfigurationPath ) ;
130
122
131
- // Make sure the configuration element exist
132
- var configElement = doc . SelectSingleNode ( "//ns:WadCfg" , ns ) ?? doc . SelectSingleNode ( "//ns:WadCfgBlob" , ns ) ;
133
- if ( configElement == null )
123
+ // Make sure the configuration elements exist
124
+ var publicConfigElement = doc . SelectSingleNode ( "//ns:PublicConfig" , ns ) ;
125
+ if ( publicConfigElement == null )
126
+ {
127
+ throw new ArgumentException ( Resources . DiagnosticsExtensionNullPublicConfig ) ;
128
+ }
129
+
130
+ var wadConfigElement = doc . SelectSingleNode ( "//ns:WadCfg" , ns ) ?? doc . SelectSingleNode ( "//ns:WadCfgBlob" , ns ) ;
131
+ if ( wadConfigElement == null )
134
132
{
135
133
throw new ArgumentException ( Resources . DiagnosticsExtensionPaaSConfigElementNotDefined ) ;
136
134
}
137
135
138
136
// The element <StorageAccount> is not meant to be set by the user in the public config.
139
137
// Make sure it matches the storage account in the private config.
140
138
var storageAccountElement = doc . SelectSingleNode ( "//ns:StorageAccount" , ns ) ;
141
- if ( storageAccountElement ! = null )
139
+ if ( storageAccountElement = = null )
142
140
{
143
- // The StorageAccount is empty, we must set it
144
- if ( string . IsNullOrEmpty ( storageAccountElement . InnerText ) )
145
- {
146
- storageAccountElement . InnerText = StorageAccountName ;
147
- PublicConfiguration = doc . OuterXml ;
148
- }
149
- else if ( ! string . IsNullOrEmpty ( storageAccountElement . InnerText ) && string . Compare ( storageAccountElement . InnerText , StorageAccountName , true ) != 0 )
150
- {
151
- throw new ArgumentException ( Resources . DiagnosticsExtensionNoMatchStorageAccount ) ;
152
- }
153
- }
154
- else
155
- {
156
- // The StorageAccount is not there. we must set it
141
+ // The StorageAccount element is not there, we create one
157
142
storageAccountElement = doc . CreateElement ( "StorageAccount" , XmlNamespace ) ;
158
- storageAccountElement . InnerText = StorageAccountName ;
143
+ wadConfigElement . ParentNode . AppendChild ( storageAccountElement ) ;
144
+ }
159
145
160
- // Insert it after <WadCfg> or <WadCfgBlob>
161
- configElement . ParentNode . AppendChild ( storageAccountElement ) ;
162
- PublicConfiguration = doc . OuterXml ;
146
+ if ( ! string . IsNullOrEmpty ( storageAccountElement . InnerText ) && string . Compare ( storageAccountElement . InnerText , StorageAccountName , true ) != 0 )
147
+ {
148
+ WriteWarning ( Resources . DiagnosticsExtensionNoMatchStorageAccount ) ;
163
149
}
164
150
151
+ storageAccountElement . InnerText = StorageAccountName ;
152
+ PublicConfiguration = publicConfigElement . OuterXml ;
153
+
165
154
// Make sure the storage account name in PrivateConfig matches.
166
155
var privateConfigStorageAccountName = DiagnosticsHelper . GetStorageAccountInfoFromPrivateConfig ( this . DiagnosticsConfigurationPath , DiagnosticsHelper . PrivConfNameAttr ) ;
167
156
if ( ! string . IsNullOrEmpty ( privateConfigStorageAccountName )
168
157
&& ! string . Equals ( StorageAccountName , privateConfigStorageAccountName , StringComparison . OrdinalIgnoreCase ) )
169
158
{
170
- throw new ArgumentException ( Resources . DiagnosticsExtensionNoMatchPrivateStorageAccount ) ;
159
+ WriteWarning ( Resources . DiagnosticsExtensionNoMatchPrivateStorageAccount ) ;
171
160
}
172
161
173
162
PrivateConfigurationXml = new XDocument ( PrivateConfigurationXmlTemplate ) ;
0 commit comments