@@ -35,6 +35,7 @@ public class SetAzureRmDiagnosticSettingCommand : ManagementCmdletBase
35
35
public const string StorageAccountIdParamName = "StorageAccountId" ;
36
36
public const string ServiceBusRuleIdParamName = "ServiceBusRuleId" ;
37
37
public const string WorkspacetIdParamName = "WorkspaceId" ;
38
+ public const string EnabledParamName = "EnabledParamName" ;
38
39
39
40
#region Parameters declarations
40
41
@@ -62,7 +63,7 @@ public class SetAzureRmDiagnosticSettingCommand : ManagementCmdletBase
62
63
/// </summary>
63
64
[ Parameter ( Mandatory = false , ValueFromPipelineByPropertyName = true , HelpMessage = "The value indicating whether the diagnostics should be enabled or disabled" ) ]
64
65
[ ValidateNotNullOrEmpty ]
65
- public bool ? Enabled { get ; set ; }
66
+ public bool Enabled { get ; set ; }
66
67
67
68
/// <summary>
68
69
/// Gets or sets the categories parameter of the cmdlet
@@ -105,18 +106,21 @@ public class SetAzureRmDiagnosticSettingCommand : ManagementCmdletBase
105
106
106
107
private bool isWorkspaceParamPresent ;
107
108
109
+ private bool isEnbledParameterPresent ;
110
+
108
111
protected override void ProcessRecordInternal ( )
109
112
{
110
113
HashSet < string > usedParams = new HashSet < string > ( this . MyInvocation . BoundParameters . Keys , StringComparer . OrdinalIgnoreCase ) ;
111
114
112
115
this . isStorageParamPresent = usedParams . Contains ( StorageAccountIdParamName ) ;
113
116
this . isServiceBusParamPresent = usedParams . Contains ( ServiceBusRuleIdParamName ) ;
114
117
this . isWorkspaceParamPresent = usedParams . Contains ( WorkspacetIdParamName ) ;
118
+ this . isEnbledParameterPresent = usedParams . Contains ( EnabledParamName ) ;
115
119
116
120
if ( ! this . isStorageParamPresent &&
117
121
! this . isServiceBusParamPresent &&
118
122
! this . isWorkspaceParamPresent &&
119
- ! this . Enabled . HasValue )
123
+ ! this . isEnbledParameterPresent )
120
124
{
121
125
throw new ArgumentException ( "No operation is specified" ) ;
122
126
}
@@ -197,7 +201,7 @@ private void SetRetention(ServiceDiagnosticSettingsResource properties)
197
201
198
202
private void SetSelectedTimegrains ( ServiceDiagnosticSettingsResource properties )
199
203
{
200
- if ( ! this . Enabled . HasValue )
204
+ if ( ! this . isEnbledParameterPresent )
201
205
{
202
206
throw new ArgumentException ( "Parameter 'Enabled' is required by 'Timegrains' parameter." ) ;
203
207
}
@@ -211,13 +215,13 @@ private void SetSelectedTimegrains(ServiceDiagnosticSettingsResource properties)
211
215
{
212
216
throw new ArgumentException ( string . Format ( CultureInfo . InvariantCulture , "Metric timegrain '{0}' is not available" , timegrainString ) ) ;
213
217
}
214
- metricSettings . Enabled = this . Enabled . Value ;
218
+ metricSettings . Enabled = this . Enabled ;
215
219
}
216
220
}
217
221
218
222
private void SetSelectedCategories ( ServiceDiagnosticSettingsResource properties )
219
223
{
220
- if ( ! this . Enabled . HasValue )
224
+ if ( ! this . isEnbledParameterPresent )
221
225
{
222
226
throw new ArgumentException ( "Parameter 'Enabled' is required by 'Categories' parameter." ) ;
223
227
}
@@ -231,25 +235,25 @@ private void SetSelectedCategories(ServiceDiagnosticSettingsResource properties)
231
235
throw new ArgumentException ( string . Format ( CultureInfo . InvariantCulture , "Log category '{0}' is not available" , category ) ) ;
232
236
}
233
237
234
- logSettings . Enabled = this . Enabled . Value ;
238
+ logSettings . Enabled = this . Enabled ;
235
239
}
236
240
}
237
241
238
242
private void SetAllCategoriesAndTimegrains ( ServiceDiagnosticSettingsResource properties )
239
243
{
240
- if ( ! this . Enabled . HasValue )
244
+ if ( ! this . isEnbledParameterPresent )
241
245
{
242
246
return ;
243
247
}
244
248
245
249
foreach ( var log in properties . Logs )
246
250
{
247
- log . Enabled = this . Enabled . Value ;
251
+ log . Enabled = this . Enabled ;
248
252
}
249
253
250
254
foreach ( var metric in properties . Metrics )
251
255
{
252
- metric . Enabled = this . Enabled . Value ;
256
+ metric . Enabled = this . Enabled ;
253
257
}
254
258
}
255
259
0 commit comments