ApplyConfigurationException.cs (1767B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ApplyConfigurationException.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.WinGet.Configuration.Engine.Exceptions 8 { 9 using System; 10 using System.Collections.Generic; 11 using Microsoft.Management.Configuration; 12 using Microsoft.WinGet.Configuration.Engine.PSObjects; 13 using Microsoft.WinGet.Resources; 14 15 /// <summary> 16 /// Exception thrown when there's an error when configuration is applied. 17 /// </summary> 18 public class ApplyConfigurationException : Exception 19 { 20 /// <summary> 21 /// Initializes a new instance of the <see cref="ApplyConfigurationException"/> class. 22 /// </summary> 23 /// <param name="applyResult">Apply Result.</param> 24 internal ApplyConfigurationException(ApplyConfigurationSetResult applyResult) 25 : base(Resources.ConfigurationFailedToApply) 26 { 27 this.HResult = applyResult.ResultCode?.HResult ?? ErrorCodes.WingetConfigErrorSetApplyFailed; 28 29 var results = new List<PSApplyConfigurationUnitResult>(); 30 foreach (var unitResult in applyResult.UnitResults) 31 { 32 results.Add(new PSApplyConfigurationUnitResult(unitResult)); 33 } 34 35 this.UnitResults = results; 36 } 37 38 /// <summary> 39 /// Gets the result of the units. 40 /// </summary> 41 public IReadOnlyList<PSApplyConfigurationUnitResult> UnitResults { get; private init; } 42 } 43 }