-
Notifications
You must be signed in to change notification settings - Fork 309
Display a message box with error code included if dynamic dependencies init fails. #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rohanp-msft
merged 2 commits into
main
from
user/rohanp/add_error_handling_in_winforms_sample
Aug 21, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 60 additions & 54 deletions
114
Samples/ResourceManagement/cs-winforms-unpackaged/Program.cs
This file contains hidden or 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,54 +1,60 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Windows.Forms; | ||
| using Microsoft.ApplicationModel.Resources; | ||
| using Microsoft.Windows.ApplicationModel; | ||
|
|
||
| namespace winforms_unpackaged_app | ||
| { | ||
| static class Program | ||
| { | ||
| /// <summary> | ||
| /// The main entry point for the application. | ||
| /// </summary> | ||
| [STAThread] | ||
| static void Main() | ||
| { | ||
| Application.SetHighDpiMode(HighDpiMode.SystemAware); | ||
| Application.EnableVisualStyles(); | ||
| Application.SetCompatibleTextRenderingDefault(false); | ||
|
|
||
| // Initialize dynamic dependencies so we can consume the Project Reunion APIs in the Project Reunion framework package from this unpackaged app. | ||
| // Take a dependency on Project Reunion v0.8 preview. | ||
| MddBootstrap.Initialize(8, "preview"); | ||
|
|
||
| var resourceManager = new ResourceManager("winforms_unpackaged_app.pri"); | ||
| // Fall back to other resource loaders if the resource is not found in MRT, in this case .net. | ||
| // This enables carrying forward existing assets without the need to convert them. | ||
| resourceManager.ResourceNotFound += (sender, args) => | ||
| { | ||
| var candidate = new ResourceCandidate( | ||
| ResourceCandidateKind.String, | ||
| LegacyResources.ResourceManager.GetString(args.Name, LegacyResources.Culture)); | ||
|
|
||
| args.SetResolvedCandidate(candidate); | ||
| }; | ||
|
|
||
| var resourceLoader = new ResourceLoader(); | ||
|
|
||
| // Create a custom resource context. Set the language to German. | ||
| var overrideResourceContext = resourceManager.CreateResourceContext(); | ||
| overrideResourceContext.QualifierValues["Language"] = "de-DE"; | ||
|
|
||
| // The resource manager and the resource loader do disk I/O and should be centrally cached. | ||
| // Since both end up loading the same file, ideally an app should only use one. | ||
| // The resource manager is a superset of the resource loader in terms of functionality. | ||
| Application.Run(new AppForm(resourceManager, resourceLoader, overrideResourceContext)); | ||
|
|
||
| // Uninitialize dynamic dependencies. | ||
| MddBootstrap.Shutdown(); | ||
| } | ||
| } | ||
| } | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Windows.Forms; | ||
| using Microsoft.ApplicationModel.Resources; | ||
| using Microsoft.Windows.ApplicationModel; | ||
|
|
||
| namespace winforms_unpackaged_app | ||
| { | ||
| static class Program | ||
| { | ||
| /// <summary> | ||
| /// The main entry point for the application. | ||
| /// </summary> | ||
| [STAThread] | ||
| static void Main() | ||
| { | ||
| Application.SetHighDpiMode(HighDpiMode.SystemAware); | ||
| Application.EnableVisualStyles(); | ||
| Application.SetCompatibleTextRenderingDefault(false); | ||
|
|
||
| // Initialize dynamic dependencies so we can consume the Project Reunion APIs in the Project | ||
jefgen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Reunion framework package from this unpackaged app. | ||
| // Take a dependency on Project Reunion v0.8 preview. | ||
| int hr = MddBootstrap.Initialize(8, "preview"); | ||
rohanp-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (hr < 0) | ||
| { | ||
| MessageBox.Show("Fail to initialize Dynamic Dependencies with error 0x" + hr.ToString("X"), "Error!"); | ||
| return; | ||
| } | ||
|
|
||
| var resourceManager = new ResourceManager("winforms_unpackaged_app.pri"); | ||
| // Fall back to other resource loaders if the resource is not found in MRT, in this case .net. | ||
| // This enables carrying forward existing assets without the need to convert them. | ||
| resourceManager.ResourceNotFound += (sender, args) => | ||
| { | ||
| var candidate = new ResourceCandidate( | ||
| ResourceCandidateKind.String, | ||
| LegacyResources.ResourceManager.GetString(args.Name, LegacyResources.Culture)); | ||
|
|
||
| args.SetResolvedCandidate(candidate); | ||
| }; | ||
|
|
||
| var resourceLoader = new ResourceLoader(); | ||
|
|
||
| // Create a custom resource context. Set the language to German. | ||
| var overrideResourceContext = resourceManager.CreateResourceContext(); | ||
| overrideResourceContext.QualifierValues["Language"] = "de-DE"; | ||
|
|
||
| // The resource manager and the resource loader do disk I/O and should be centrally cached. | ||
| // Since both end up loading the same file, ideally an app should only use one. | ||
| // The resource manager is a superset of the resource loader in terms of functionality. | ||
| Application.Run(new AppForm(resourceManager, resourceLoader, overrideResourceContext)); | ||
|
|
||
| // Uninitialize dynamic dependencies. | ||
| MddBootstrap.Shutdown(); | ||
rohanp-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.