@@ -304,101 +304,106 @@ public class SetAzureActionRule : AlertsManagementBaseCmdlet
304
304
protected override void ProcessRecordInternal ( )
305
305
{
306
306
PSActionRule actionRule = new PSActionRule ( ) ;
307
- switch ( ParameterSetName )
307
+ if ( ShouldProcess (
308
+ target : string . Format ( "Create new Action Rule" ) ,
309
+ action : "Create the action rule" ) )
308
310
{
309
- case BySimplifiedFormatActionGroupActionRuleParameterSet :
310
- if ( ActionRuleType != "ActionGroup" )
311
- {
312
- throw new PSInvalidOperationException ( "Incorrect Action Rule Type for given set of parameters. +" +
313
- "Use ActionGroup type for this parameter set." ) ;
314
- }
315
-
316
- // Create Action Rule
317
- ActionRule actionGroupAR = new ActionRule (
318
- location : "Global" ,
319
- tags : new Dictionary < string , string > ( ) ,
320
- properties : new ActionGroup (
321
- scope : ParseScope ( ) ,
322
- conditions : ParseConditions ( ) ,
323
- actionGroupId : ActionGroupId ,
324
- description : Description ,
325
- status : Status
326
- )
327
- ) ;
328
-
329
- actionRule = new PSActionRule ( this . AlertsManagementClient . ActionRules . CreateUpdateWithHttpMessagesAsync (
330
- resourceGroupName : ResourceGroupName , actionRuleName : Name , actionRule : actionGroupAR ) . Result . Body ) ;
331
- break ;
332
-
333
- case BySimplifiedFormatSuppressionActionRuleParameterSet :
334
-
335
- if ( ActionRuleType != "Suppression" )
336
- {
337
- throw new PSInvalidOperationException ( "Incorrect Action Rule Type for given set of parameters. +" +
338
- "Use Suppression type for this parameter set." ) ;
339
- }
340
-
341
- SuppressionConfig config = new SuppressionConfig ( recurrenceType : ReccurenceType ) ;
342
- if ( ReccurenceType != "Always" )
343
- {
344
- config . Schedule = new SuppressionSchedule (
345
- startDate : SuppressionStartTime . Split ( ' ' ) [ 0 ] ,
346
- endDate : SuppressionEndTime . Split ( ' ' ) [ 0 ] ,
347
- startTime : SuppressionStartTime . Split ( ' ' ) [ 1 ] ,
348
- endTime : SuppressionEndTime . Split ( ' ' ) [ 1 ]
349
- ) ;
350
-
351
- if ( ReccurentValue . Length > 0 )
311
+ switch ( ParameterSetName )
312
+ {
313
+ case BySimplifiedFormatActionGroupActionRuleParameterSet :
314
+ if ( ActionRuleType != "ActionGroup" )
352
315
{
353
- //config.Schedule.RecurrenceValues = new List<int?>(ReccurentValue.ToList<int?>());
316
+ throw new PSInvalidOperationException ( "Incorrect Action Rule Type for given set of parameters. +" +
317
+ "Use ActionGroup type for this parameter set." ) ;
318
+ }
319
+
320
+ // Create Action Rule
321
+ ActionRule actionGroupAR = new ActionRule (
322
+ location : "Global" ,
323
+ tags : new Dictionary < string , string > ( ) ,
324
+ properties : new ActionGroup (
325
+ scope : ParseScope ( ) ,
326
+ conditions : ParseConditions ( ) ,
327
+ actionGroupId : ActionGroupId ,
328
+ description : Description ,
329
+ status : Status
330
+ )
331
+ ) ;
332
+
333
+ actionRule = new PSActionRule ( this . AlertsManagementClient . ActionRules . CreateUpdateWithHttpMessagesAsync (
334
+ resourceGroupName : ResourceGroupName , actionRuleName : Name , actionRule : actionGroupAR ) . Result . Body ) ;
335
+ break ;
336
+
337
+ case BySimplifiedFormatSuppressionActionRuleParameterSet :
338
+
339
+ if ( ActionRuleType != "Suppression" )
340
+ {
341
+ throw new PSInvalidOperationException ( "Incorrect Action Rule Type for given set of parameters. +" +
342
+ "Use Suppression type for this parameter set." ) ;
354
343
}
355
- }
356
-
357
- // Create Action Rule
358
- ActionRule suppressionAR = new ActionRule (
359
- location : "Global" ,
360
- tags : new Dictionary < string , string > ( ) ,
361
- properties : new Suppression (
362
- scope : ParseScope ( ) ,
363
- conditions : ParseConditions ( ) ,
364
- description : Description ,
365
- status : Status ,
366
- suppressionConfig : config
367
- )
368
- ) ;
369
-
370
- actionRule = new PSActionRule ( this . AlertsManagementClient . ActionRules . CreateUpdateWithHttpMessagesAsync (
371
- resourceGroupName : ResourceGroupName , actionRuleName : Name , actionRule : suppressionAR ) . Result . Body ) ;
372
- break ;
373
-
374
- case BySimplifiedFormatDiagnosticsActionRuleParameterSet :
375
- if ( ActionRuleType != "Diagnostics" )
376
- {
377
- throw new PSInvalidOperationException ( "Incorrect Action Rule Type for given set of parameters. +" +
378
- "Use Diagnostics type for this parameter set." ) ;
379
- }
380
-
381
- // Create Action Rule
382
- ActionRule diagnosticsAR = new ActionRule (
383
- location : "Global" ,
384
- tags : new Dictionary < string , string > ( ) ,
385
- properties : new Diagnostics (
386
- scope : ParseScope ( ) ,
387
- conditions : ParseConditions ( ) ,
388
- description : Description ,
389
- status : Status
390
- )
391
- ) ;
392
-
393
- actionRule = new PSActionRule ( this . AlertsManagementClient . ActionRules . CreateUpdateWithHttpMessagesAsync (
394
- resourceGroupName : ResourceGroupName , actionRuleName : Name , actionRule : diagnosticsAR ) . Result . Body ) ;
395
-
396
- break ;
397
- case ByInputObjectParameterSet :
398
- break ;
399
- }
400
344
401
- WriteObject ( sendToPipeline : actionRule ) ;
345
+ SuppressionConfig config = new SuppressionConfig ( recurrenceType : ReccurenceType ) ;
346
+ if ( ReccurenceType != "Always" )
347
+ {
348
+ config . Schedule = new SuppressionSchedule (
349
+ startDate : SuppressionStartTime . Split ( ' ' ) [ 0 ] ,
350
+ endDate : SuppressionEndTime . Split ( ' ' ) [ 0 ] ,
351
+ startTime : SuppressionStartTime . Split ( ' ' ) [ 1 ] ,
352
+ endTime : SuppressionEndTime . Split ( ' ' ) [ 1 ]
353
+ ) ;
354
+
355
+ if ( ReccurentValue . Length > 0 )
356
+ {
357
+ config . Schedule . RecurrenceValues = ReccurentValue . OfType < int ? > ( ) . ToList ( ) ;
358
+ }
359
+ }
360
+
361
+ // Create Action Rule
362
+ ActionRule suppressionAR = new ActionRule (
363
+ location : "Global" ,
364
+ tags : new Dictionary < string , string > ( ) ,
365
+ properties : new Suppression (
366
+ scope : ParseScope ( ) ,
367
+ conditions : ParseConditions ( ) ,
368
+ description : Description ,
369
+ status : Status ,
370
+ suppressionConfig : config
371
+ )
372
+ ) ;
373
+
374
+ actionRule = new PSActionRule ( this . AlertsManagementClient . ActionRules . CreateUpdateWithHttpMessagesAsync (
375
+ resourceGroupName : ResourceGroupName , actionRuleName : Name , actionRule : suppressionAR ) . Result . Body ) ;
376
+ break ;
377
+
378
+ case BySimplifiedFormatDiagnosticsActionRuleParameterSet :
379
+ if ( ActionRuleType != "Diagnostics" )
380
+ {
381
+ throw new PSInvalidOperationException ( "Incorrect Action Rule Type for given set of parameters. +" +
382
+ "Use Diagnostics type for this parameter set." ) ;
383
+ }
384
+
385
+ // Create Action Rule
386
+ ActionRule diagnosticsAR = new ActionRule (
387
+ location : "Global" ,
388
+ tags : new Dictionary < string , string > ( ) ,
389
+ properties : new Diagnostics (
390
+ scope : ParseScope ( ) ,
391
+ conditions : ParseConditions ( ) ,
392
+ description : Description ,
393
+ status : Status
394
+ )
395
+ ) ;
396
+
397
+ actionRule = new PSActionRule ( this . AlertsManagementClient . ActionRules . CreateUpdateWithHttpMessagesAsync (
398
+ resourceGroupName : ResourceGroupName , actionRuleName : Name , actionRule : diagnosticsAR ) . Result . Body ) ;
399
+
400
+ break ;
401
+ case ByInputObjectParameterSet :
402
+ break ;
403
+ }
404
+
405
+ WriteObject ( sendToPipeline : actionRule ) ;
406
+ }
402
407
}
403
408
404
409
private Conditions ParseConditions ( )
0 commit comments