-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[net7.0] Initial code for replacing the deployment manager (#12745)
* Initial code for replacing the deployment manager * better code * bit better and avoids an unneccessary creation * more nice code * More coolness * better logging Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
- Loading branch information
1 parent
79815e3
commit 90ad642
Showing
3 changed files
with
54 additions
and
0 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
50 changes: 50 additions & 0 deletions
50
src/Core/src/Platform/Windows/DeploymentManagerAutoInitializer.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,50 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Windows.ApplicationModel.WindowsAppRuntime; | ||
|
||
namespace Microsoft.Maui; | ||
|
||
internal static class DeploymentManagerAutoInitializer | ||
{ | ||
#pragma warning disable CA2255 // The 'ModuleInitializer' attribute should not be used in libraries | ||
[ModuleInitializer] | ||
#pragma warning restore CA2255 // The 'ModuleInitializer' attribute should not be used in libraries | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
internal static void AccessWindowsAppSDK() | ||
{ | ||
try | ||
{ | ||
var options = new DeploymentInitializeOptions(); | ||
Result = DeploymentManager.Initialize(options); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Result = new DeploymentResult(DeploymentStatus.Unknown, ex); | ||
} | ||
} | ||
|
||
public static DeploymentResult Result { get; private set; } = null!; | ||
|
||
public static void LogIfFailed(IServiceProvider services) | ||
{ | ||
if (Result?.Status == DeploymentStatus.Ok) | ||
return; | ||
|
||
var logger = services.CreateLogger("Microsoft.Maui.DeploymentManagerAutoInitializer"); | ||
if (logger is null) | ||
return; | ||
|
||
var error = Result?.ExtendedError; | ||
if (error is null) | ||
{ | ||
logger.LogError($"Unknown WindowsAppRuntime.DeploymentManager.Initialize error."); | ||
} | ||
else | ||
{ | ||
var hresult = string.Format("0x{0:X}", error.HResult); | ||
logger.LogError(error, "WindowsAppRuntime.DeploymentManager.Initialize error ({HResult}): {ErrorMessage}", hresult, error.Message); | ||
} | ||
} | ||
} |
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