forked from johngallardo/CapabilityChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
121 lines (105 loc) · 3.77 KB
/
MainPage.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 System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Networking;
using Windows.System.RemoteSystems;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace CapabilityChecker
{
public class PageModel : PropertyChangedBase
{
public PageModel()
{
RemoteSystemModels = new ObservableCollection<RemoteSystemModel>();
}
public ObservableCollection<RemoteSystemModel> RemoteSystemModels { get; private set; }
private RemoteSystemModel _thisRemoteSystem;
public RemoteSystemModel ThisRemoteSystem
{
get => _thisRemoteSystem;
set => SetPropertyReference(nameof(ThisRemoteSystem), ref _thisRemoteSystem, value);
}
}
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private PageModel _model = new PageModel();
public MainPage()
{
this.InitializeComponent();
}
Visibility CollapsedIfNull(object o)
{
return o == null ? Visibility.Collapsed : Visibility.Visible;
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (_watcher == null)
{
_watcher = await CreateWatcherAsync();
}
}
private async Task<RemoteSystemWatcher> CreateWatcherAsync()
{
var access = await RemoteSystem.RequestAccessAsync();
if (access == RemoteSystemAccessStatus.Allowed)
{
var watcher = RemoteSystem.CreateWatcher();
watcher.RemoteSystemAdded += Watcher_RemoteSystemAdded;
watcher.Start();
return watcher;
}
return null;
}
private async void Watcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args)
{
await Dispatcher.RunIdleAsync((_) =>
{
AddRemoteSystem(args.RemoteSystem);
});
}
void AddRemoteSystem(RemoteSystem system)
{
_model.RemoteSystemModels.Add(new RemoteSystemModel(system));
}
RemoteSystemWatcher _watcher;
private async void Button_Click(object sender, RoutedEventArgs e)
{
var element = sender as FrameworkElement;
var model = element?.DataContext as RemoteSystemModel;
await model?.CheckAppServiceCapableAsync();
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
var element = sender as FrameworkElement;
var model = element?.DataContext as RemoteSystemModel;
await model?.LaunchUri("jgtest://www.microsoft.com");
}
private async void LoadThisClicked(object sender, RoutedEventArgs e)
{
var access = await RemoteSystem.RequestAccessAsync();
if (access == RemoteSystemAccessStatus.Allowed)
{
var hn = new HostName("127.0.0.1");
var rs = await RemoteSystem.FindByHostNameAsync(hn);
_model.ThisRemoteSystem = new RemoteSystemModel(rs);
}
}
}
}