winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

CompleteWinGetConfigurationCmdlet.cs (2041B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="CompleteWinGetConfigurationCmdlet.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     /// Complete-WinGetConfiguration.
     15     /// Completes a configuration previously started by Start-WinGetConfiguration.
     16     /// Waits for completion.
     17     /// </summary>
     18     [Cmdlet(VerbsLifecycle.Complete, "WinGetConfiguration")]
     19     [Alias("cmpwgc")]
     20     public sealed class CompleteWinGetConfigurationCmdlet : PSCmdlet
     21     {
     22         private ConfigurationCommand runningCommand = null;
     23 
     24         /// <summary>
     25         /// Gets or sets the configuration task.
     26         /// </summary>
     27         [Parameter(
     28             Position = 0,
     29             Mandatory = true,
     30             ValueFromPipeline = true,
     31             ValueFromPipelineByPropertyName = true)]
     32         public PSConfigurationJob ConfigurationJob { get; set; }
     33 
     34         /// <summary>
     35         /// Starts to apply the configuration and wait for it to complete.
     36         /// </summary>
     37         protected override void ProcessRecord()
     38         {
     39             this.runningCommand = new ConfigurationCommand(this);
     40             this.runningCommand.Continue(this.ConfigurationJob);
     41         }
     42 
     43         /// <summary>
     44         /// Interrupts currently running code within the command.
     45         /// </summary>
     46         protected override void StopProcessing()
     47         {
     48             if (this.runningCommand != null)
     49             {
     50                 this.runningCommand.Cancel(this.ConfigurationJob);
     51                 this.runningCommand.Cancel();
     52             }
     53         }
     54     }
     55 }