WinGetRepairPackageException.cs (3490B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="WinGetRepairPackageException.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.WinGet.Client.Engine.Exceptions 8 { 9 using System; 10 using System.Management.Automation; 11 using Microsoft.WinGet.Client.Engine.Common; 12 using Microsoft.WinGet.Resources; 13 14 /// <summary> 15 /// WinGetRepairPackageException. 16 /// </summary> 17 [Serializable] 18 public class WinGetRepairPackageException : RuntimeException 19 { 20 /// <summary> 21 /// Initializes a new instance of the <see cref="WinGetRepairPackageException"/> class. 22 /// </summary> 23 /// <param name="hresult">Repair operation ExtendedErrorCode Hresult.</param> 24 public WinGetRepairPackageException(int hresult) 25 : base(GetMessage(hresult)) 26 { 27 } 28 29 /// <summary> 30 /// Initializes a new instance of the <see cref="WinGetRepairPackageException"/> class. 31 /// </summary> 32 /// <param name="hresult">Repair operation ExtendedErrorCode Hresult.</param> 33 /// <param name="repairerExitCode">Repairer exit code.</param> 34 public WinGetRepairPackageException(int hresult, uint repairerExitCode) 35 : base(GetMessage(hresult, repairerExitCode)) 36 { 37 } 38 39 /// <summary> 40 /// Initializes a new instance of the <see cref="WinGetRepairPackageException"/> class. 41 /// </summary> 42 /// <param name="hresult">Repair operation ExtendedErrorCode Hresult.</param> 43 /// <param name="innerException">InnerException.</param> 44 public WinGetRepairPackageException(int hresult, Exception innerException) 45 : base(GetMessage(hresult), innerException) 46 { 47 } 48 49 /// <summary> 50 /// Initializes a new instance of the <see cref="WinGetRepairPackageException"/> class. 51 /// </summary> 52 /// <param name="hresult">Repair operation ExtendedErrorCode Hresult.</param> 53 /// <param name="repairerExitCode">Repairer exit code.</param> 54 /// <param name="innerException">InnerException.</param> 55 public WinGetRepairPackageException(int hresult, uint repairerExitCode, Exception innerException) 56 : base(GetMessage(hresult, repairerExitCode), innerException) 57 { 58 } 59 60 private static string GetMessage(int hresult, uint repairerExitCode = 0) 61 { 62 switch (hresult) 63 { 64 case ErrorCode.NoRepairInfoFound: 65 return Resources.NoRepairInfoFound; 66 case ErrorCode.RepairerFailure: 67 return string.Format(Resources.RepairerFailure, repairerExitCode); 68 case ErrorCode.RepairNotSupported: 69 return Resources.RepairOperationNotSupported; 70 case ErrorCode.RepairNotApplicable: 71 return Resources.RepairDifferentInstallTechnology; 72 case ErrorCode.AdminContextRepairProhibited: 73 return Resources.NoAdminRepairForUserScopePackage; 74 default: 75 return string.Format(Resources.UnknownRepairFailure, hresult); 76 } 77 } 78 } 79 }