-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hyper-V extension: Check guest OS version before apply configuration. (…
- Loading branch information
Showing
9 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...s/HyperVExtension/src/HyperVExtension/Exceptions/GuestOsOperationNotSupportedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using HyperVExtension.Common; | ||
using Windows.Win32.Foundation; | ||
|
||
namespace HyperVExtension.Exceptions; | ||
|
||
internal sealed class GuestOsOperationNotSupportedException : GuestOsVersionException | ||
{ | ||
public GuestOsOperationNotSupportedException(IStringResource stringResource, Dictionary<string, string>? guestOsProperties) | ||
: base(stringResource.GetLocalized("GuestOsOperationNotSupported", $"Windows {Constants.MinWindowsVersionForApplyConfiguration}"), guestOsProperties) | ||
{ | ||
HResult = HRESULT.E_NOTSUPPORTED; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
extensions/HyperVExtension/src/HyperVExtension/Exceptions/GuestOsVersionException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Globalization; | ||
using System.Management.Automation; | ||
using System.Text; | ||
using HyperVExtension.Common; | ||
using HyperVExtension.Helpers; | ||
|
||
namespace HyperVExtension.Exceptions; | ||
|
||
internal class GuestOsVersionException : Exception | ||
{ | ||
public GuestOsVersionException(IStringResource stringResource, Exception innerException, Dictionary<string, string>? guestOsProperties) | ||
: base(stringResource.GetLocalized("FailedToDetermineGuestOsVersion", $"Windows {Constants.MinWindowsVersionForApplyConfiguration}"), innerException) | ||
{ | ||
HResult = innerException.HResult; | ||
GuestOsProperties = guestOsProperties; | ||
} | ||
|
||
protected GuestOsVersionException(string message, Dictionary<string, string>? guestOsProperties) | ||
: base(message) | ||
{ | ||
GuestOsProperties = guestOsProperties; | ||
} | ||
|
||
public Dictionary<string, string>? GuestOsProperties { get; } | ||
|
||
public override string ToString() | ||
{ | ||
StringBuilder message = new(); | ||
message.Append(CultureInfo.InvariantCulture, $"{Message}."); | ||
if (InnerException != null) | ||
{ | ||
message.Append(CultureInfo.InvariantCulture, $" {InnerException}."); | ||
} | ||
|
||
if (GuestOsProperties != null) | ||
{ | ||
GuestOsProperties.TryGetValue(HyperVStrings.OSPlatformId, out var osPlatformId); | ||
GuestOsProperties.TryGetValue(HyperVStrings.OSVersion, out var osVersion); | ||
GuestOsProperties.TryGetValue(HyperVStrings.OSName, out var osName); | ||
if ((osPlatformId != null) || | ||
(osVersion != null) || | ||
(osName != null)) | ||
{ | ||
message.Append(" ("); | ||
if (osPlatformId != null) | ||
{ | ||
message.Append(CultureInfo.InvariantCulture, $"{HyperVStrings.OSPlatformId} = {osPlatformId}"); | ||
} | ||
|
||
if (osVersion != null) | ||
{ | ||
message.Append(CultureInfo.InvariantCulture, $", {HyperVStrings.OSVersion} = {osVersion}"); | ||
} | ||
|
||
if (osName != null) | ||
{ | ||
message.Append(CultureInfo.InvariantCulture, $", {HyperVStrings.OSName} = {osName}"); | ||
} | ||
|
||
message.Append(')'); | ||
} | ||
} | ||
|
||
if (InnerException != null) | ||
{ | ||
message.Append(CultureInfo.InvariantCulture, $"{Environment.NewLine}{InnerException}."); | ||
} | ||
|
||
return message.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
extensions/HyperVExtension/src/HyperVExtension/NativeMethods.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
GetCurrentPackageFullName | ||
WIN32_ERROR | ||
E_UNEXPECTED | ||
E_NOTSUPPORTED | ||
E_FAIL | ||
E_ABORT | ||
S_OK | ||
MAX_PATH | ||
SFBS_FLAGS | ||
StrFormatByteSizeEx | ||
SetForegroundWindow | ||
GetDiskFreeSpaceEx | ||
GetDiskFreeSpaceEx | ||
VER_PLATFORM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters