Skip to content

Commit

Permalink
Add Repair API demo from 1.3 Release WindowsAppSDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Santosh Chintalapati committed Sep 30, 2022
1 parent 32e506e commit eec2662
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<DependentUpon>Scenario2_Initialize.xaml</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="Scenario3_Repair.xaml.h">
<DependentUpon>Scenario3_Repair.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="SettingsPage.xaml.h">
<DependentUpon>SettingsPage.xaml</DependentUpon>
<SubType>Code</SubType>
Expand All @@ -138,6 +141,9 @@
<Page Include="Scenario2_Initialize.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Scenario3_Repair.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="SettingsPage.xaml">
<SubType>Designer</SubType>
</Page>
Expand Down Expand Up @@ -169,6 +175,9 @@
<DependentUpon>Scenario2_Initialize.xaml</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="Scenario3_Repair.xaml.cpp">
<DependentUpon>Scenario3_Repair.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="SettingsPage.xaml.cpp">
<DependentUpon>SettingsPage.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Page Include="Styles.xaml" />
<Page Include="Scenario1_GetStatus.xaml" />
<Page Include="Scenario2_Initialize.xaml" />
<Page Include="Scenario3_Repair.xaml" />
</ItemGroup>
<ItemGroup>
<Midl Include="Project.idl" />
Expand Down Expand Up @@ -54,4 +55,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions Samples/DeploymentManager/cpp-winui/Project.idl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace DeploymentManagerSample
Scenario2_Initialize();
}

[default_interface]
runtimeclass Scenario3_Repair : Microsoft.UI.Xaml.Controls.Page
{
Scenario3_Repair();
}

/* The following code is template-specific IDL.
These runtime classes are the same across all C++/WinRT WinUI samples. */

Expand Down
3 changes: 2 additions & 1 deletion Samples/DeploymentManager/cpp-winui/SampleConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace winrt::DeploymentManagerSample
IVector<Scenario> implementation::MainPage::scenariosInner = single_threaded_observable_vector<Scenario>(
{
Scenario{ L"Get Status", hstring(name_of<DeploymentManagerSample::Scenario1_GetStatus>())},
Scenario{ L"Initialize", hstring(name_of<DeploymentManagerSample::Scenario2_Initialize>())}
Scenario{ L"Initialize", hstring(name_of<DeploymentManagerSample::Scenario2_Initialize>())},
Scenario{ L"Repair", hstring(name_of<DeploymentManagerSample::Scenario3_Repair>())}
});

hstring SampleConfig::FeatureName{ L"DeploymentManager" };
Expand Down
26 changes: 26 additions & 0 deletions Samples/DeploymentManager/cpp-winui/Scenario3_Repair.xaml
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 Samples/DeploymentManager/cpp-winui/Scenario3_Repair.xaml.cpp
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 Samples/DeploymentManager/cpp-winui/Scenario3_Repair.xaml.h
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>
{
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>DeploymentManagerSample</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand All @@ -12,10 +12,9 @@
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
<WindowsSdkPackageVersion>10.0.19041.24</WindowsSdkPackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.588-beta" PrivateAssets="all" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.63-beta" PrivateAssets="all" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.4" />
</ItemGroup>

Expand Down
4 changes: 3 additions & 1 deletion Samples/DeploymentManager/cs-winui/SampleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public partial class MainPage : Page
private readonly List<Scenario> scenarios = new()
{
new Scenario() { Title = "Get Status", ClassName = typeof(Scenario1_GetStatus).FullName },
new Scenario() { Title = "Initialize", ClassName = typeof(Scenario2_Initialize).FullName }
new Scenario() { Title = "Initialize", ClassName = typeof(Scenario2_Initialize).FullName },
new Scenario() { Title = "Repair", ClassName = typeof(Scenario3_Repair).FullName }

};
}

Expand Down
27 changes: 27 additions & 0 deletions Samples/DeploymentManager/cs-winui/Scenario3_Repair.xaml
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 Samples/DeploymentManager/cs-winui/Scenario3_Repair.xaml.cs
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.";
}
}
}
}

0 comments on commit eec2662

Please sign in to comment.