@@ -197,59 +197,62 @@ public void ExecuteCommand()
197
197
198
198
private List < ExtensionConfigurationInput > GetConfigurations ( )
199
199
{
200
- var initConfigs = ParameterSetName == SetExtensionUsingDiagnosticsConfigurationParameterSetName
201
- ? DiagnosticsConfiguration
202
- : new ExtensionConfigurationInput [ ] {
203
- new ExtensionConfigurationInput
204
- {
205
- Id = ExtensionId ,
206
- Version = Version ,
207
- ProviderNameSpace = ProviderNamespace ,
208
- Type = ExtensionName ,
209
- CertificateThumbprint = CertificateThumbprint ,
210
- ThumbprintAlgorithm = ThumbprintAlgorithm ,
211
- X509Certificate = X509Certificate ,
212
- PublicConfiguration = PublicConfiguration ,
213
- PrivateConfiguration = PrivateConfiguration ,
214
- Roles = new ExtensionRoleList ( Role != null && Role . Any ( )
215
- ? Role . Select ( r => new ExtensionRole ( r ) )
216
- : Enumerable . Repeat ( new ExtensionRole ( ) , 1 ) )
217
- }
218
- } ;
219
-
220
- // Remove duplicate configuration for the same role.
221
- // This not only improve the efficieny, one more important reason is current InstallExtension() implementation assumes
222
- // we call change deployment directly after installation. Calling InstallExtension() multiple times for the same role
223
- // may result in removing the extension which is still working.
224
200
var result = new List < ExtensionConfigurationInput > ( ) ;
225
- for ( var i = 0 ; i < initConfigs . Length ; i ++ )
201
+
202
+ if ( ParameterSetName == SetExtensionUsingDiagnosticsConfigurationParameterSetName )
226
203
{
227
- var currentConfig = initConfigs [ i ] ;
228
- for ( var j = i + 1 ; j < initConfigs . Length && currentConfig . Roles . Any ( ) ; j ++ )
204
+ // If user specified multiple configurations for the same role, we only take the later configuration for that role.
205
+ // This not only improve the efficieny, one more important reason is current InstallExtension() implementation assumes
206
+ // we call change deployment directly after installation. Calling InstallExtension() multiple times for the same role
207
+ // may result in removing the extension which is still working.
208
+ for ( var i = 0 ; i < DiagnosticsConfiguration . Length ; i ++ )
229
209
{
230
- var followingConfig = initConfigs [ j ] ;
231
-
232
- // If the following configuration is applied to all roles, we simply ingore the whole current config.
233
- if ( followingConfig . Roles . Any ( r => r . Default ) )
210
+ var currentConfig = DiagnosticsConfiguration [ i ] ;
211
+ for ( var j = i + 1 ; j < DiagnosticsConfiguration . Length && currentConfig . Roles . Any ( ) ; j ++ )
234
212
{
235
- currentConfig . Roles . Clear ( ) ;
236
- }
213
+ var followingConfig = DiagnosticsConfiguration [ j ] ;
237
214
238
- // If the role appears in following config, we will take the later one and remove the role from current config.
239
- foreach ( var role in currentConfig . Roles . ToArray ( ) )
240
- {
241
- if ( followingConfig . Roles . Any ( r => r . RoleName == role . RoleName ) )
215
+ // If the following configuration is applied to all roles, we simply ingore the whole current config.
216
+ if ( followingConfig . Roles . Any ( r => r . Default ) )
217
+ {
218
+ currentConfig . Roles . Clear ( ) ;
219
+ }
220
+
221
+ // If the role appears in following config, we will take the later one and remove the role from current config.
222
+ foreach ( var role in currentConfig . Roles . ToArray ( ) )
242
223
{
243
- currentConfig . Roles . Remove ( role ) ;
224
+ if ( followingConfig . Roles . Any ( r => r . RoleName == role . RoleName ) )
225
+ {
226
+ currentConfig . Roles . Remove ( role ) ;
227
+ }
244
228
}
245
229
}
246
- }
247
230
248
- if ( currentConfig . Roles . Any ( ) )
249
- {
250
- result . Add ( currentConfig ) ;
231
+ if ( currentConfig . Roles . Any ( ) )
232
+ {
233
+ result . Add ( currentConfig ) ;
234
+ }
251
235
}
252
236
}
237
+ else
238
+ {
239
+ // If user specified a config file path, then there is only one configuration.
240
+ result . Add ( new ExtensionConfigurationInput
241
+ {
242
+ Id = ExtensionId ,
243
+ Version = Version ,
244
+ ProviderNameSpace = ProviderNamespace ,
245
+ Type = ExtensionName ,
246
+ CertificateThumbprint = CertificateThumbprint ,
247
+ ThumbprintAlgorithm = ThumbprintAlgorithm ,
248
+ X509Certificate = X509Certificate ,
249
+ PublicConfiguration = PublicConfiguration ,
250
+ PrivateConfiguration = PrivateConfiguration ,
251
+ Roles = new ExtensionRoleList ( Role != null && Role . Any ( )
252
+ ? Role . Select ( r => new ExtensionRole ( r ) )
253
+ : Enumerable . Repeat ( new ExtensionRole ( ) , 1 ) )
254
+ } ) ;
255
+ }
253
256
254
257
return result ;
255
258
}
0 commit comments