StartWinGetConfigurationCmdlet.cs (2242B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="StartWinGetConfigurationCmdlet.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 /// Start-WinGetConfiguration. 15 /// Start to apply the configuration. 16 /// Does not wait for completion. 17 /// </summary> 18 [Cmdlet(VerbsLifecycle.Start, "WinGetConfiguration")] 19 [Alias("sawgc")] 20 public sealed class StartWinGetConfigurationCmdlet : PSCmdlet 21 { 22 private bool acceptedAgreements = false; 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(), true); 46 } 47 48 /// <summary> 49 /// Starts to apply the configuration and wait for it to complete. 50 /// </summary> 51 protected override void ProcessRecord() 52 { 53 if (this.acceptedAgreements) 54 { 55 var configCommand = new ConfigurationCommand(this); 56 configCommand.StartApply(this.Set); 57 } 58 } 59 } 60 }