PSDownloadResult.cs (3468B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="PSDownloadResult.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.WinGet.Client.Engine.PSObjects 8 { 9 using System; 10 using Microsoft.Management.Deployment; 11 using Microsoft.WinGet.Client.Engine.Extensions; 12 13 /// <summary> 14 /// PSDownloadResult. 15 /// </summary> 16 public sealed class PSDownloadResult 17 { 18 private readonly DownloadResult downloadResult; 19 private readonly CatalogPackage catalogPackage; 20 21 /// <summary> 22 /// Initializes a new instance of the <see cref="PSDownloadResult"/> class. 23 /// </summary> 24 /// <param name="downloadResult">The download result COM object.</param> 25 /// <param name="catalogPackage">The catalog package COM object.</param> 26 internal PSDownloadResult(DownloadResult downloadResult, CatalogPackage catalogPackage) 27 { 28 this.downloadResult = downloadResult; 29 this.catalogPackage = catalogPackage; 30 } 31 32 /// <summary> 33 /// Gets the id of the downloaded package. 34 /// </summary> 35 public string Id 36 { 37 get 38 { 39 return this.catalogPackage.Id; 40 } 41 } 42 43 /// <summary> 44 /// Gets the name of the downloaded package. 45 /// </summary> 46 public string Name 47 { 48 get 49 { 50 return this.catalogPackage.Name; 51 } 52 } 53 54 /// <summary> 55 /// Gets the source name of the downloaded package. 56 /// </summary> 57 public string? Source 58 { 59 get 60 { 61 return this.catalogPackage.GetSourceName(); 62 } 63 } 64 65 /// <summary> 66 /// Gets the correlation data of the downloaded result. 67 /// </summary> 68 public string CorrelationData 69 { 70 get 71 { 72 return this.downloadResult.CorrelationData; 73 } 74 } 75 76 /// <summary> 77 /// Gets the extended error code exception of the failed download result. 78 /// </summary> 79 public Exception ExtendedErrorCode 80 { 81 get 82 { 83 return this.downloadResult.ExtendedErrorCode; 84 } 85 } 86 87 /// <summary> 88 /// Gets the status of the download. 89 /// </summary> 90 public string Status 91 { 92 get 93 { 94 return this.downloadResult.Status.ToString(); 95 } 96 } 97 98 /// <summary> 99 /// If the download succeeded. 100 /// </summary> 101 /// <returns>True if installation succeeded.</returns> 102 public bool Succeeded() 103 { 104 return this.downloadResult.Status == DownloadResultStatus.Ok; 105 } 106 107 /// <summary> 108 /// Message with error information. 109 /// </summary> 110 /// <returns>Error message.</returns> 111 public string ErrorMessage() 112 { 113 return $"DownloadStatus '{this.Status}' ExtendedError '{this.ExtendedErrorCode.HResult}'"; 114 } 115 } 116 }