InvokeWinGetConfigurationCmdlet.cs (2623B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="InvokeWinGetConfigurationCmdlet.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; 10 using System.Management.Automation; 11 using Microsoft.WinGet.Configuration.Engine.Commands; 12 using Microsoft.WinGet.Configuration.Engine.PSObjects; 13 14 /// <summary> 15 /// Invoke-WinGetConfiguration. 16 /// Applies the configuration. 17 /// Wait for completion. 18 /// </summary> 19 [Cmdlet(VerbsLifecycle.Invoke, "WinGetConfiguration")] 20 [Alias("iwgc")] 21 public sealed class InvokeWinGetConfigurationCmdlet : PSCmdlet 22 { 23 private bool acceptedAgreements = false; 24 private ConfigurationCommand runningCommand = null; 25 26 /// <summary> 27 /// Gets or sets the configuration set. 28 /// </summary> 29 [Parameter( 30 Position = 0, 31 Mandatory = true, 32 ValueFromPipeline = true, 33 ValueFromPipelineByPropertyName = true)] 34 public PSConfigurationSet Set { get; set; } 35 36 /// <summary> 37 /// Gets or sets a value indicating whether to accept the configuration agreements. 38 /// </summary> 39 [Parameter(ValueFromPipelineByPropertyName = true)] 40 public SwitchParameter AcceptConfigurationAgreements { get; set; } 41 42 /// <summary> 43 /// Pre-processing operations. 44 /// </summary> 45 protected override void BeginProcessing() 46 { 47 this.acceptedAgreements = ConfigurationCommand.ConfirmConfigurationProcessing(this, this.AcceptConfigurationAgreements.ToBool(), true); 48 } 49 50 /// <summary> 51 /// Starts to apply the configuration and wait for it to complete. 52 /// </summary> 53 protected override void ProcessRecord() 54 { 55 if (this.acceptedAgreements) 56 { 57 this.runningCommand = new ConfigurationCommand(this); 58 this.runningCommand.Apply(this.Set); 59 } 60 } 61 62 /// <summary> 63 /// Interrupts currently running code within the command. 64 /// </summary> 65 protected override void StopProcessing() 66 { 67 if (this.runningCommand != null) 68 { 69 this.runningCommand.Cancel(); 70 } 71 } 72 } 73 }