forked from johngallardo/CapabilityChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoteSystemModel.cs
83 lines (72 loc) · 2.44 KB
/
RemoteSystemModel.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System.RemoteSystems;
namespace CapabilityChecker
{
public enum CapabilityState
{
NotChecked,
Checking,
Capable,
NotCapable
}
public class PropertyChangedBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void SetPropertyValue<T>(string name, ref T old, T n) where T : IComparable
{
if (old.CompareTo(n) != 0)
{
old = n;
NotifyPropertyChanged(name);
}
}
protected void SetPropertyReference<T>(string name, ref T old, T n) where T : class
{
if(old != n)
{
old = n;
NotifyPropertyChanged(name);
}
}
private void NotifyPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public class RemoteSystemModel : PropertyChangedBase
{
public RemoteSystemModel(RemoteSystem system)
{
_remoteSystem = system;
}
public string Name { get { return _remoteSystem.DisplayName; } }
public string Kind { get { return _remoteSystem.Kind; } }
private CapabilityState _isAppServiceCapable = CapabilityState.NotChecked;
public CapabilityState IsAppServiceCapable
{
get => _isAppServiceCapable;
set => SetPropertyValue(nameof(IsAppServiceCapable), ref _isAppServiceCapable, value);
}
public async Task CheckAppServiceCapableAsync()
{
IsAppServiceCapable = CapabilityState.Checking;
var operation = _remoteSystem.GetCapabilitySupportedAsync(KnownRemoteSystemCapabilities.AppService);
IsAppServiceCapable = await operation ? CapabilityState.Capable : CapabilityState.NotCapable;
}
public async Task LaunchUri(string uri)
{
RemoteSystemConnectionRequest request = new RemoteSystemConnectionRequest(_remoteSystem);
await Windows.System.RemoteLauncher.LaunchUriAsync(request, new Uri(uri));
}
private RemoteSystem _remoteSystem;
}
}