winget-cli

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

WinGetIntegrityException.cs (3089B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="WinGetIntegrityException.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     /// WinGet Integrity exception.
     16     /// </summary>
     17     public class WinGetIntegrityException : RuntimeException
     18     {
     19         /// <summary>
     20         /// Initializes a new instance of the <see cref="WinGetIntegrityException"/> class.
     21         /// </summary>
     22         /// <param name="category">Category failure.</param>
     23         public WinGetIntegrityException(IntegrityCategory category)
     24             : base(GetMessage(category))
     25         {
     26             this.Category = category;
     27         }
     28 
     29         /// <summary>
     30         /// Initializes a new instance of the <see cref="WinGetIntegrityException"/> class.
     31         /// </summary>
     32         /// <param name="category">Category failure.</param>
     33         /// <param name="inner">Inner exception.</param>
     34         public WinGetIntegrityException(IntegrityCategory category, Exception inner)
     35             : base(GetMessage(category), inner)
     36         {
     37             this.Category = category;
     38         }
     39 
     40         /// <summary>
     41         /// Initializes a new instance of the <see cref="WinGetIntegrityException"/> class.
     42         /// </summary>
     43         /// <param name="category">Category failure.</param>
     44         /// <param name="message">Message.</param>
     45         public WinGetIntegrityException(IntegrityCategory category, string message)
     46             : base(message)
     47         {
     48             this.Category = category;
     49         }
     50 
     51         /// <summary>
     52         /// Gets the category of the integrity failure.
     53         /// </summary>
     54         public IntegrityCategory Category { get; }
     55 
     56         private static string GetMessage(IntegrityCategory category) => category switch
     57         {
     58             IntegrityCategory.Failure => Resources.IntegrityFailureMessage,
     59             IntegrityCategory.NotInPath => Resources.IntegrityNotInPathMessage,
     60             IntegrityCategory.AppExecutionAliasDisabled => Resources.IntegrityAppExecutionAliasDisabledMessage,
     61             IntegrityCategory.OsNotSupported => Resources.IntegrityOsNotSupportedMessage,
     62             IntegrityCategory.AppInstallerNotInstalled => Resources.IntegrityAppInstallerNotInstalledMessage,
     63             IntegrityCategory.AppInstallerNotRegistered => Resources.IntegrityAppInstallerNotRegisteredMessage,
     64             IntegrityCategory.AppInstallerNotSupported => Resources.IntegrityAppInstallerNotSupportedMessage,
     65             IntegrityCategory.AppInstallerNoLicense => Resources.IntegrityAppInstallerLicense,
     66             _ => Resources.IntegrityUnknownMessage,
     67         };
     68     }
     69 }