TestWinGetConfigurationCmdlet.cs (2510B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="TestWinGetConfigurationCmdlet.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.WinGet.Configuration.Cmdlets 8 { 9 using System.Management.Automation; 10 using Microsoft.WinGet.Configuration.Engine.Commands; 11 using Microsoft.WinGet.Configuration.Engine.PSObjects; 12 13 /// <summary> 14 /// Test-WinGetConfiguration 15 /// Tests configuration. 16 /// </summary> 17 [Cmdlet(VerbsDiagnostic.Test, "WinGetConfiguration")] 18 [Alias("twgc")] 19 public class TestWinGetConfigurationCmdlet : PSCmdlet 20 { 21 private bool acceptedAgreements = false; 22 private ConfigurationCommand runningCommand = null; 23 24 /// <summary> 25 /// Gets or sets the configuration set. 26 /// </summary> 27 [Parameter( 28 Position = 0, 29 Mandatory = true, 30 ValueFromPipeline = true, 31 ValueFromPipelineByPropertyName = true)] 32 public PSConfigurationSet Set { get; set; } 33 34 /// <summary> 35 /// Gets or sets a value indicating whether to accept the configuration agreements. 36 /// </summary> 37 [Parameter(ValueFromPipelineByPropertyName = true)] 38 public SwitchParameter AcceptConfigurationAgreements { get; set; } 39 40 /// <summary> 41 /// Pre-processing operations. 42 /// </summary> 43 protected override void BeginProcessing() 44 { 45 this.acceptedAgreements = ConfigurationCommand.ConfirmConfigurationProcessing(this, this.AcceptConfigurationAgreements.ToBool(), false); 46 } 47 48 /// <summary> 49 /// Test configuration. 50 /// </summary> 51 protected override void ProcessRecord() 52 { 53 if (this.acceptedAgreements) 54 { 55 this.runningCommand = new ConfigurationCommand(this); 56 this.runningCommand.Test(this.Set); 57 } 58 } 59 60 /// <summary> 61 /// Interrupts currently running code within the command. 62 /// </summary> 63 protected override void StopProcessing() 64 { 65 if (this.runningCommand != null) 66 { 67 this.runningCommand.Cancel(); 68 } 69 } 70 } 71 }