-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Repair API demo from 1.3 Release WindowsAppSDK
- Loading branch information
Santosh Chintalapati
committed
Sep 30, 2022
1 parent
32e506e
commit 17630ba
Showing
11 changed files
with
293 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Page | ||
x:Class="DeploymentManagerSample.Scenario3_Repair" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:DeploymentManagerSample" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<ScrollViewer Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
<StackPanel Spacing="10" Margin="10,10,10,10"> | ||
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/> | ||
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" TextWrapping="Wrap"> | ||
Repair the Windows App SDK Runtime with DeploymentManager.Repair() | ||
</TextBlock> | ||
<Button Content="Repair Windows App Runtime" Click="RepairScenarioButton_Click" /> | ||
<Button Content="Repair Windows App Runtime with force deploy overload" Click="ForceRepairScenarioButton_Click" /> | ||
<TextBlock x:Name="resultStatus"></TextBlock> | ||
<TextBlock x:Name="resultExtendedError" TextWrapping="Wrap"></TextBlock> | ||
<TextBlock x:Name="resultImplication"></TextBlock> | ||
</StackPanel> | ||
</ScrollViewer> | ||
</Grid> | ||
</Page> |
94 changes: 94 additions & 0 deletions
94
Samples/DeploymentManager/cpp-winui/Scenario3_Repair.xaml.cpp
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,94 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "pch.h" | ||
#include "Scenario3_Repair.xaml.h" | ||
#if __has_include("Scenario3_Repair.g.cpp") | ||
#include "Scenario3_Repair.g.cpp" | ||
#endif | ||
|
||
namespace winrt | ||
{ | ||
using namespace Microsoft::UI::Xaml; | ||
using namespace Microsoft::Windows::ApplicationModel::WindowsAppRuntime; | ||
using namespace Windows::Foundation; | ||
} | ||
|
||
// To learn more about WinUI, the WinUI project structure, | ||
// and more about our project templates, see: http://aka.ms/winui-project-info. | ||
|
||
namespace winrt::DeploymentManagerSample::implementation | ||
{ | ||
Scenario3_Repair::Scenario3_Repair() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
void Scenario3_Repair::UpdateRepairMessages() | ||
{ | ||
resultStatus().Text(L"Result Status: Running Repair()..."); | ||
resultExtendedError().Text(L"Result ExtendedError:"); | ||
resultImplication().Text(L""); | ||
} | ||
|
||
void Scenario3_Repair::UpdateDeploymentResultMessages(DeploymentResult deploymentResult) | ||
{ | ||
resultStatus().Text(L"Result Status: "); // TODO DeploymentStatus to string | ||
|
||
// Check the result. | ||
if (deploymentResult.Status() == DeploymentStatus::Ok) | ||
{ | ||
resultImplication().Text(L"The WindowsAppRuntime was successfully Repaired and is now ready for use!"); | ||
|
||
} | ||
else | ||
{ | ||
resultExtendedError().Text(L"Result ExtendedError: " + to_hstring(deploymentResult.ExtendedError())); | ||
|
||
// The WindowsAppRuntime is in a bad state which Repair() did not fix. | ||
// Do error reporting or gather information for submitting a bug. | ||
// Gracefully exit the program or carry on without using the WindowsAppRuntime. | ||
resultImplication().Text(L"Repair() failed to ensure the WindowsAppRuntime."); | ||
} | ||
} | ||
|
||
void Scenario3_Repair::RepairScenarioButton_Click(IInspectable const& sender, RoutedEventArgs const& e) | ||
{ | ||
UpdateRepairMessages(); | ||
|
||
// Repair does NOT do a status check and it will attempt to repair the | ||
// WindowsAppRuntime into a good state by deploying packages. Unlike a simple | ||
// status check, Repair can sometimes take several seconds to deploy the packages. | ||
// These should be run on a separate thread so as not to hang your app while the | ||
// packages deploy. | ||
DeploymentResult deploymentResult = DeploymentManager::Repair(); // TODO how to run on separate thread? | ||
|
||
UpdateDeploymentResultMessages(deploymentResult); | ||
} | ||
|
||
void Scenario3_Repair::ForceRepairScenarioButton_Click(IInspectable const& sender, RoutedEventArgs const& e) | ||
{ | ||
UpdateRepairMessages(); | ||
|
||
if (DeploymentManager::GetStatus().Status() == DeploymentStatus::Ok) | ||
{ | ||
// Set force deploy option to true. This will shut down any proccesses associated | ||
// with the Main and Singleton packages if they are currently in use. | ||
DeploymentRepairOptions deploymentRepairOptions; | ||
deploymentRepairOptions.ForceDeployment(true); | ||
|
||
// Repair does a status check, and if the status is not Ok it will attempt to get | ||
// the WindowsAppRuntime into a good state by deploying packages. Unlike a simple | ||
// status check, Repair can sometimes take several seconds to deploy the packages. | ||
// These should be run on a separate thread so as not to hang your app while the | ||
// packages deploy. | ||
DeploymentResult deploymentResult = DeploymentManager::Repair(deploymentRepairOptions); // TODO how to run on separate thread? | ||
|
||
UpdateDeploymentResultMessages(deploymentResult); | ||
} | ||
else | ||
{ | ||
resultImplication().Text(L"The WindowsAppRuntime was already in an Ok status, no action taken."); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Samples/DeploymentManager/cpp-winui/Scenario3_Repair.xaml.h
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,26 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include "Scenario3_Repair.g.h" | ||
#include "pch.h" | ||
|
||
namespace winrt::DeploymentManagerSample::implementation | ||
{ | ||
struct Scenario3_Repair : Scenario3_RepairT<Scenario3_Repair> | ||
{ | ||
Scenario3_Repair(); | ||
void UpdateRepairMessages(); | ||
void UpdateDeploymentResultMessages(winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentResult deploymentResult); | ||
void RepairScenarioButton_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e); | ||
void ForceRepairScenarioButton_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e); | ||
}; | ||
} | ||
|
||
namespace winrt::DeploymentManagerSample::factory_implementation | ||
{ | ||
struct Scenario3_Repair : Scenario3_RepairT<Scenario3_Repair, implementation::Scenario3_Repair> | ||
{ | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT License. --> | ||
<Page | ||
x:Class="DeploymentManagerSample.Scenario3_Repair" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:DeploymentManagerSample" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<Grid> | ||
<ScrollViewer Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
<StackPanel Spacing="10" Margin="10,10,10,10"> | ||
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/> | ||
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" TextWrapping="Wrap"> | ||
Repair the Windows App SDK Runtime with DeploymentManager.Repair() | ||
</TextBlock> | ||
<Button Content="Repair Windows App Runtime" Click="RepairScenarioButton_Click" /> | ||
<Button Content="Repair Windows App Runtime with force deploy overload" Click="ForceRepairScenarioButton_Click" /> | ||
<TextBlock x:Name="resultStatus"></TextBlock> | ||
<TextBlock x:Name="resultExtendedError" TextWrapping="Wrap"></TextBlock> | ||
<TextBlock x:Name="resultImplication"></TextBlock> | ||
</StackPanel> | ||
</ScrollViewer> | ||
</Grid> | ||
</Page> |
96 changes: 96 additions & 0 deletions
96
Samples/DeploymentManager/cs-winui/Scenario3_Repair.xaml.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,96 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.Windows.ApplicationModel.WindowsAppRuntime; | ||
using System.Threading.Tasks; | ||
|
||
namespace DeploymentManagerSample | ||
{ | ||
public partial class Scenario3_Repair : Page | ||
{ | ||
public Scenario3_Repair() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private void updateRepairMessages() | ||
{ | ||
resultStatus.Text = "Result Status: Running Repair()..."; | ||
resultExtendedError.Text = "Result ExtendedError:"; | ||
resultImplication.Text = ""; | ||
} | ||
|
||
private void updateDeploymentResultMessages(DeploymentResult deploymentResult) | ||
{ | ||
resultStatus.Text = "Result Status: " + deploymentResult.Status.ToString(); | ||
|
||
// Check the result. | ||
if (deploymentResult.Status == DeploymentStatus.Ok) | ||
{ | ||
resultImplication.Text = "The WindowsAppRuntime was successfully Repaired and is now ready for use!"; | ||
|
||
} | ||
else | ||
{ | ||
resultExtendedError.Text = "Result ExtendedError: " + deploymentResult.ExtendedError.ToString(); | ||
|
||
// The WindowsAppRuntime is in a bad state which Repair() did not fix. | ||
// Do error reporting or gather information for submitting a bug. | ||
// Gracefully exit the program or carry on without using the WindowsAppRuntime. | ||
resultImplication.Text = "Repair() failed to ensure the WindowsAppRuntime."; | ||
} | ||
} | ||
|
||
private void RepairScenarioButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
updateRepairMessages(); | ||
|
||
if (DeploymentManager.GetStatus().Status != DeploymentStatus.Ok) | ||
{ | ||
// Repair does NOT check for WindowsAppRuntime status and it will always attempt to get | ||
// the WindowsAppRuntime into a good state by deploying packages. Unlike a simple | ||
// status check, Repair can sometimes take several seconds to deploy the packages. | ||
// These should be run on a separate thread so as not to hang your app while the | ||
// packages deploy. | ||
var RepairTask = Task.Run(() => DeploymentManager.Repair()); | ||
RepairTask.Wait(); | ||
|
||
updateDeploymentResultMessages(RepairTask.Result); | ||
} | ||
else | ||
{ | ||
resultImplication.Text = "The WindowsAppRuntime was already in an Ok status, no action taken."; | ||
} | ||
} | ||
|
||
private void ForceRepairScenarioButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
updateRepairMessages(); | ||
|
||
if (DeploymentManager.GetStatus().Status != DeploymentStatus.Ok) | ||
{ | ||
// Set force deploy option to true. This will shut down any proccesses associated | ||
// with the Main and Singleton packages if they are currently in use. | ||
DeploymentRepairOptions deploymentRepairOptions = new() { | ||
ForceDeployment = true | ||
}; | ||
|
||
// Repair does NOT check for WindowsAppRuntime status and it will always attempt to get | ||
// the WindowsAppRuntime into a good state by deploying packages. Unlike a simple | ||
// status check, Repair can sometimes take several seconds to deploy the packages. | ||
// These should be run on a separate thread so as not to hang your app while the | ||
// packages deploy. | ||
var RepairTask = Task.Run(() => DeploymentManager.Repair(deploymentRepairOptions)); | ||
RepairTask.Wait(); | ||
|
||
updateDeploymentResultMessages(RepairTask.Result); | ||
} | ||
else | ||
{ | ||
resultImplication.Text = "The WindowsAppRuntime was already in an Ok status, no action taken."; | ||
} | ||
} | ||
} | ||
} |