-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenario4_childmanagement.xaml.cs
121 lines (97 loc) · 4.71 KB
/
scenario4_childmanagement.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.ApplicationModel.WindowsAppRuntime;
using System;
using System.Collections.Generic;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
using Windows.ApplicationModel;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Management.Deployment;
namespace PackageSampleHostedApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Scenario4 : Page
{
// A pointer back to the main page. This is needed if you want to call methods in MainPage such
// as NotifyUser()
MainPage rootPage = MainPage.Current;
PackageCatalog catalog = null;
public Scenario4()
{
this.InitializeComponent();
}
//[Windows.Foundation.Metadata.Overload("AddPackageByUriAsync")]
//[Windows.Foundation.Metadata.RemoteAsync]
//public IAsyncOperationWithProgress<Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentResult, DeploymentProgress> AddPackageByUriAsync(System.Uri packageUri, AddPackageOptions options);
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void GetHostInfo_Click(object sender, RoutedEventArgs e)
{
var pkgdependents = PackageRelationship.Dependents;
var hostRuntimeDependents = new FindRelatedPackagesOptions(pkgdependents)
{
IncludeFrameworks = false,
IncludeHostRuntimes = true,
IncludeOptionals = false,
IncludeResources = false
};
//var hostRuntimeDependents = new FindRelatedPackagesOptions(PackageRelationship.Dependents)
IList<Windows.ApplicationModel.Package> dependents = Package.Current.FindRelatedPackages(hostRuntimeDependents);
String output = String.Format("Count: {0}", dependents.Count.ToString());
for (int i = 0; i < dependents.Count; i++)
{
Package dependent = dependents[i];
output += String.Format("\n[{0}]: {1}", i.ToString(), dependent.Id.FullName);
}
OutputTextBlock.Text = output;
}
private void PackageInstallingCallback(object x, PackageInstallingEventArgs args)
{
Package package = args.Package;
OutputTextBlock.Text = package.DisplayName;
}
private void PackageUninstallingCallback(object x, PackageUninstallingEventArgs args)
{
if (this.DispatcherQueue.HasThreadAccess)
{
OutputTextBlock.Text = OutputTextBlock.Text;
}
else
{
bool isQueued = this.DispatcherQueue.TryEnqueue(
Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal,
() => OutputTextBlock.Text = OutputTextBlock.Text + "\n PackageUninstalling " + args.Package.Id.FullName + " Progress " + args.Progress + " IsComplete " + args.IsComplete + " ActivityId " + args.ActivityId);
}
}
//{
// var ignored = CoreApplication.MainView.CoreWindow.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
// {
// OutputTextBlock.Text = OutputTextBlock.Text + "\n PackageUninstalling " + args.Package.Id.FullName + " Progress " + args.Progress + " IsComplete " + args.IsComplete + " ActivityId " + args.ActivityId + " ErrorCode " + args.ErrorCode.ToString();
// });
//}
private void OptionalPackageUpdatingCallback(object x, PackageUpdatingEventArgs args)
{
Package package = args.TargetPackage;
OutputTextBlock.Text = package.DisplayName;
}
private void Register_for_notifications_Click(object sender, RoutedEventArgs e)
{
catalog = PackageCatalog.OpenForPackage(Package.Current);
OutputTextBlock.Text = "PackageCatalog Opened";
catalog.PackageUpdating += OptionalPackageUpdatingCallback;
catalog.PackageInstalling += PackageInstallingCallback;
catalog.PackageUninstalling += PackageUninstallingCallback;
}
}
}