forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWinGetIntegrityException.cs
More file actions
75 lines (68 loc) · 3.22 KB
/
WinGetIntegrityException.cs
File metadata and controls
75 lines (68 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// -----------------------------------------------------------------------------
// <copyright file="WinGetIntegrityException.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------
namespace Microsoft.WinGet.Client.Engine.Exceptions
{
using System;
using System.Management.Automation;
using Microsoft.WinGet.Client.Engine.Common;
using Microsoft.WinGet.Client.Engine.Helpers;
using Microsoft.WinGet.Resources;
/// <summary>
/// WinGet Integrity exception.
/// </summary>
public class WinGetIntegrityException : RuntimeException
{
/// <summary>
/// Initializes a new instance of the <see cref="WinGetIntegrityException"/> class.
/// </summary>
/// <param name="category">Category failure.</param>
public WinGetIntegrityException(IntegrityCategory category)
: base(GetMessage(category))
{
this.Category = category;
}
/// <summary>
/// Initializes a new instance of the <see cref="WinGetIntegrityException"/> class.
/// </summary>
/// <param name="category">Category failure.</param>
/// <param name="inner">Inner exception.</param>
public WinGetIntegrityException(IntegrityCategory category, Exception inner)
: base(GetMessage(category), inner)
{
this.Category = category;
}
/// <summary>
/// Initializes a new instance of the <see cref="WinGetIntegrityException"/> class.
/// </summary>
/// <param name="category">Category failure.</param>
/// <param name="message">Message.</param>
public WinGetIntegrityException(IntegrityCategory category, string message)
: base(message)
{
this.Category = category;
}
/// <summary>
/// Gets the category of the integrity failure.
/// </summary>
public IntegrityCategory Category { get; }
/// <summary>
/// Gets or sets the installed version.
/// </summary>
internal WinGetVersion? InstalledVersion { get; set; }
private static string GetMessage(IntegrityCategory category) => category switch
{
IntegrityCategory.Failure => Resources.IntegrityFailureMessage,
IntegrityCategory.NotInPath => Resources.IntegrityNotInPathMessage,
IntegrityCategory.AppExecutionAliasDisabled => Resources.IntegrityAppExecutionAliasDisabledMessage,
IntegrityCategory.OsNotSupported => Resources.IntegrityOsNotSupportedMessage,
IntegrityCategory.AppInstallerNotInstalled => Resources.IntegrityAppInstallerNotInstalledMessage,
IntegrityCategory.AppInstallerNotRegistered => Resources.IntegrityAppInstallerNotRegisteredMessage,
IntegrityCategory.AppInstallerNotSupported => Resources.IntegrityAppInstallerNotSupportedMessage,
IntegrityCategory.AppInstallerNoLicense => Resources.IntegrityAppInstallerLicense,
_ => Resources.IntegrityUnknownMessage,
};
}
}