Skip to content

Commit 17630ba

Browse files
author
Santosh Chintalapati
committed
Add Repair API demo from 1.3 Release WindowsAppSDK
1 parent 32e506e commit 17630ba

11 files changed

+293
-6
lines changed

Samples/DeploymentManager/cpp-winui/DeploymentManagerSample.vcxproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@
121121
<DependentUpon>Scenario2_Initialize.xaml</DependentUpon>
122122
<SubType>Code</SubType>
123123
</ClInclude>
124+
<ClInclude Include="Scenario3_Repair.xaml.h">
125+
<DependentUpon>Scenario3_Repair.xaml</DependentUpon>
126+
</ClInclude>
124127
<ClInclude Include="SettingsPage.xaml.h">
125128
<DependentUpon>SettingsPage.xaml</DependentUpon>
126129
<SubType>Code</SubType>
@@ -138,6 +141,9 @@
138141
<Page Include="Scenario2_Initialize.xaml">
139142
<SubType>Designer</SubType>
140143
</Page>
144+
<Page Include="Scenario3_Repair.xaml">
145+
<SubType>Designer</SubType>
146+
</Page>
141147
<Page Include="SettingsPage.xaml">
142148
<SubType>Designer</SubType>
143149
</Page>
@@ -169,6 +175,9 @@
169175
<DependentUpon>Scenario2_Initialize.xaml</DependentUpon>
170176
<SubType>Code</SubType>
171177
</ClCompile>
178+
<ClCompile Include="Scenario3_Repair.xaml.cpp">
179+
<DependentUpon>Scenario3_Repair.xaml</DependentUpon>
180+
</ClCompile>
172181
<ClCompile Include="SettingsPage.xaml.cpp">
173182
<DependentUpon>SettingsPage.xaml</DependentUpon>
174183
<SubType>Code</SubType>

Samples/DeploymentManager/cpp-winui/DeploymentManagerSample.vcxproj.filters

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Page Include="Styles.xaml" />
1111
<Page Include="Scenario1_GetStatus.xaml" />
1212
<Page Include="Scenario2_Initialize.xaml" />
13+
<Page Include="Scenario3_Repair.xaml" />
1314
</ItemGroup>
1415
<ItemGroup>
1516
<Midl Include="Project.idl" />
@@ -54,4 +55,4 @@
5455
<ItemGroup>
5556
<None Include="packages.config" />
5657
</ItemGroup>
57-
</Project>
58+
</Project>

Samples/DeploymentManager/cpp-winui/Project.idl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ namespace DeploymentManagerSample
1818
Scenario2_Initialize();
1919
}
2020

21+
[default_interface]
22+
runtimeclass Scenario3_Repair : Microsoft.UI.Xaml.Controls.Page
23+
{
24+
Scenario3_Repair();
25+
}
26+
2127
/* The following code is template-specific IDL.
2228
These runtime classes are the same across all C++/WinRT WinUI samples. */
2329

Samples/DeploymentManager/cpp-winui/SampleConfiguration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ namespace winrt::DeploymentManagerSample
1717
IVector<Scenario> implementation::MainPage::scenariosInner = single_threaded_observable_vector<Scenario>(
1818
{
1919
Scenario{ L"Get Status", hstring(name_of<DeploymentManagerSample::Scenario1_GetStatus>())},
20-
Scenario{ L"Initialize", hstring(name_of<DeploymentManagerSample::Scenario2_Initialize>())}
20+
Scenario{ L"Initialize", hstring(name_of<DeploymentManagerSample::Scenario2_Initialize>())},
21+
Scenario{ L"Repair", hstring(name_of<DeploymentManagerSample::Scenario3_Repair>())}
2122
});
2223

2324
hstring SampleConfig::FeatureName{ L"DeploymentManager" };
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Page
2+
x:Class="DeploymentManagerSample.Scenario3_Repair"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:DeploymentManagerSample"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
10+
11+
<Grid>
12+
<ScrollViewer Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
13+
<StackPanel Spacing="10" Margin="10,10,10,10">
14+
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
15+
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" TextWrapping="Wrap">
16+
Repair the Windows App SDK Runtime with DeploymentManager.Repair()
17+
</TextBlock>
18+
<Button Content="Repair Windows App Runtime" Click="RepairScenarioButton_Click" />
19+
<Button Content="Repair Windows App Runtime with force deploy overload" Click="ForceRepairScenarioButton_Click" />
20+
<TextBlock x:Name="resultStatus"></TextBlock>
21+
<TextBlock x:Name="resultExtendedError" TextWrapping="Wrap"></TextBlock>
22+
<TextBlock x:Name="resultImplication"></TextBlock>
23+
</StackPanel>
24+
</ScrollViewer>
25+
</Grid>
26+
</Page>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#include "pch.h"
5+
#include "Scenario3_Repair.xaml.h"
6+
#if __has_include("Scenario3_Repair.g.cpp")
7+
#include "Scenario3_Repair.g.cpp"
8+
#endif
9+
10+
namespace winrt
11+
{
12+
using namespace Microsoft::UI::Xaml;
13+
using namespace Microsoft::Windows::ApplicationModel::WindowsAppRuntime;
14+
using namespace Windows::Foundation;
15+
}
16+
17+
// To learn more about WinUI, the WinUI project structure,
18+
// and more about our project templates, see: http://aka.ms/winui-project-info.
19+
20+
namespace winrt::DeploymentManagerSample::implementation
21+
{
22+
Scenario3_Repair::Scenario3_Repair()
23+
{
24+
InitializeComponent();
25+
}
26+
27+
void Scenario3_Repair::UpdateRepairMessages()
28+
{
29+
resultStatus().Text(L"Result Status: Running Repair()...");
30+
resultExtendedError().Text(L"Result ExtendedError:");
31+
resultImplication().Text(L"");
32+
}
33+
34+
void Scenario3_Repair::UpdateDeploymentResultMessages(DeploymentResult deploymentResult)
35+
{
36+
resultStatus().Text(L"Result Status: "); // TODO DeploymentStatus to string
37+
38+
// Check the result.
39+
if (deploymentResult.Status() == DeploymentStatus::Ok)
40+
{
41+
resultImplication().Text(L"The WindowsAppRuntime was successfully Repaired and is now ready for use!");
42+
43+
}
44+
else
45+
{
46+
resultExtendedError().Text(L"Result ExtendedError: " + to_hstring(deploymentResult.ExtendedError()));
47+
48+
// The WindowsAppRuntime is in a bad state which Repair() did not fix.
49+
// Do error reporting or gather information for submitting a bug.
50+
// Gracefully exit the program or carry on without using the WindowsAppRuntime.
51+
resultImplication().Text(L"Repair() failed to ensure the WindowsAppRuntime.");
52+
}
53+
}
54+
55+
void Scenario3_Repair::RepairScenarioButton_Click(IInspectable const& sender, RoutedEventArgs const& e)
56+
{
57+
UpdateRepairMessages();
58+
59+
// Repair does NOT do a status check and it will attempt to repair the
60+
// WindowsAppRuntime into a good state by deploying packages. Unlike a simple
61+
// status check, Repair can sometimes take several seconds to deploy the packages.
62+
// These should be run on a separate thread so as not to hang your app while the
63+
// packages deploy.
64+
DeploymentResult deploymentResult = DeploymentManager::Repair(); // TODO how to run on separate thread?
65+
66+
UpdateDeploymentResultMessages(deploymentResult);
67+
}
68+
69+
void Scenario3_Repair::ForceRepairScenarioButton_Click(IInspectable const& sender, RoutedEventArgs const& e)
70+
{
71+
UpdateRepairMessages();
72+
73+
if (DeploymentManager::GetStatus().Status() == DeploymentStatus::Ok)
74+
{
75+
// Set force deploy option to true. This will shut down any proccesses associated
76+
// with the Main and Singleton packages if they are currently in use.
77+
DeploymentRepairOptions deploymentRepairOptions;
78+
deploymentRepairOptions.ForceDeployment(true);
79+
80+
// Repair does a status check, and if the status is not Ok it will attempt to get
81+
// the WindowsAppRuntime into a good state by deploying packages. Unlike a simple
82+
// status check, Repair can sometimes take several seconds to deploy the packages.
83+
// These should be run on a separate thread so as not to hang your app while the
84+
// packages deploy.
85+
DeploymentResult deploymentResult = DeploymentManager::Repair(deploymentRepairOptions); // TODO how to run on separate thread?
86+
87+
UpdateDeploymentResultMessages(deploymentResult);
88+
}
89+
else
90+
{
91+
resultImplication().Text(L"The WindowsAppRuntime was already in an Ok status, no action taken.");
92+
}
93+
}
94+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#pragma once
5+
6+
#include "Scenario3_Repair.g.h"
7+
#include "pch.h"
8+
9+
namespace winrt::DeploymentManagerSample::implementation
10+
{
11+
struct Scenario3_Repair : Scenario3_RepairT<Scenario3_Repair>
12+
{
13+
Scenario3_Repair();
14+
void UpdateRepairMessages();
15+
void UpdateDeploymentResultMessages(winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentResult deploymentResult);
16+
void RepairScenarioButton_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
17+
void ForceRepairScenarioButton_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
18+
};
19+
}
20+
21+
namespace winrt::DeploymentManagerSample::factory_implementation
22+
{
23+
struct Scenario3_Repair : Scenario3_RepairT<Scenario3_Repair, implementation::Scenario3_Repair>
24+
{
25+
};
26+
}

Samples/DeploymentManager/cs-winui/DeploymentManagerSample.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
4-
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
4+
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
55
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
66
<RootNamespace>DeploymentManagerSample</RootNamespace>
77
<ApplicationManifest>app.manifest</ApplicationManifest>
@@ -12,10 +12,9 @@
1212
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
1313
<WindowsSdkPackageVersion>10.0.19041.24</WindowsSdkPackageVersion>
1414
</PropertyGroup>
15-
1615
<ItemGroup>
1716
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />
18-
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.588-beta" PrivateAssets="all" />
17+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.63-beta" PrivateAssets="all" />
1918
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.4" />
2019
</ItemGroup>
2120

Samples/DeploymentManager/cs-winui/SampleConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public partial class MainPage : Page
1818
private readonly List<Scenario> scenarios = new()
1919
{
2020
new Scenario() { Title = "Get Status", ClassName = typeof(Scenario1_GetStatus).FullName },
21-
new Scenario() { Title = "Initialize", ClassName = typeof(Scenario2_Initialize).FullName }
21+
new Scenario() { Title = "Initialize", ClassName = typeof(Scenario2_Initialize).FullName },
22+
new Scenario() { Title = "Repair", ClassName = typeof(Scenario3_Repair).FullName }
23+
2224
};
2325
}
2426

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- Copyright (c) Microsoft Corporation.
2+
Licensed under the MIT License. -->
3+
<Page
4+
x:Class="DeploymentManagerSample.Scenario3_Repair"
5+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
6+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
7+
xmlns:local="using:DeploymentManagerSample"
8+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
mc:Ignorable="d">
11+
12+
<Grid>
13+
<ScrollViewer Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
14+
<StackPanel Spacing="10" Margin="10,10,10,10">
15+
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
16+
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" TextWrapping="Wrap">
17+
Repair the Windows App SDK Runtime with DeploymentManager.Repair()
18+
</TextBlock>
19+
<Button Content="Repair Windows App Runtime" Click="RepairScenarioButton_Click" />
20+
<Button Content="Repair Windows App Runtime with force deploy overload" Click="ForceRepairScenarioButton_Click" />
21+
<TextBlock x:Name="resultStatus"></TextBlock>
22+
<TextBlock x:Name="resultExtendedError" TextWrapping="Wrap"></TextBlock>
23+
<TextBlock x:Name="resultImplication"></TextBlock>
24+
</StackPanel>
25+
</ScrollViewer>
26+
</Grid>
27+
</Page>

0 commit comments

Comments
 (0)