winget-cli

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

DownloadOperationWithProgress.cs (1883B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="DownloadOperationWithProgress.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.WinGet.Client.Engine.Helpers
      8 {
      9     using System.Management.Automation;
     10     using Microsoft.Management.Deployment;
     11     using Microsoft.WinGet.Common.Command;
     12     using Microsoft.WinGet.Resources;
     13     using Windows.Foundation;
     14 
     15     /// <summary>
     16     /// Handler progress for package download.
     17     /// </summary>
     18     internal class DownloadOperationWithProgress : OperationWithProgressBase<DownloadResult, PackageDownloadProgress>
     19     {
     20         /// <summary>
     21         /// Initializes a new instance of the <see cref="DownloadOperationWithProgress"/> class.
     22         /// </summary>
     23         /// <param name="pwshCmdlet">A <see cref="PowerShellCmdlet" /> instance.</param>
     24         /// <param name="activity">Activity.</param>
     25         public DownloadOperationWithProgress(PowerShellCmdlet pwshCmdlet, string activity)
     26             : base(pwshCmdlet, activity)
     27         {
     28         }
     29 
     30         /// <inheritdoc/>
     31         public override void Progress(IAsyncOperationWithProgress<DownloadResult, PackageDownloadProgress> operation, PackageDownloadProgress progress)
     32         {
     33             ProgressRecord record = new (this.ActivityId, this.Activity, progress.State.ToString())
     34             {
     35                 RecordType = ProgressRecordType.Processing,
     36             };
     37             record.StatusDescription = Resources.DownloadingMessage;
     38             record.PercentComplete = (int)(progress.DownloadProgress * 100);
     39             this.PwshCmdlet.Write(StreamType.Progress, record);
     40         }
     41     }
     42 }