forked from microsoft/Windows-universal-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayHelpers.cs
156 lines (133 loc) · 4.43 KB
/
DisplayHelpers.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
using SDKTemplate;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.Devices.WiFi;
using Windows.Networking.Connectivity;
using Windows.UI.Core;
using Windows.UI.Xaml.Media.Imaging;
namespace WiFiScan
{
public class WiFiNetworkDisplay : INotifyPropertyChanged
{
private WiFiAdapter adapter;
public WiFiNetworkDisplay(WiFiAvailableNetwork availableNetwork, WiFiAdapter adapter)
{
AvailableNetwork = availableNetwork;
this.adapter = adapter;
UpdateWiFiImage();
}
private void UpdateWiFiImage()
{
string imageFileNamePrefix = "secure";
if (AvailableNetwork.SecuritySettings.NetworkAuthenticationType == NetworkAuthenticationType.Open80211)
{
imageFileNamePrefix = "open";
}
string imageFileName = string.Format("ms-appx:/Assets/{0}_{1}bar.png", imageFileNamePrefix, AvailableNetwork.SignalBars);
WiFiImage = new BitmapImage(new Uri(imageFileName));
OnPropertyChanged("WiFiImage");
}
public async Task UpdateConnectivityLevel()
{
string connectivityLevel = "Not Connected";
string connectedSsid = null;
var connectedProfile = await adapter.NetworkAdapter.GetConnectedProfileAsync();
if (connectedProfile != null &&
connectedProfile.IsWlanConnectionProfile &&
connectedProfile.WlanConnectionProfileDetails != null)
{
connectedSsid = connectedProfile.WlanConnectionProfileDetails.GetConnectedSsid();
}
if (!string.IsNullOrEmpty(connectedSsid))
{
if (connectedSsid.Equals(AvailableNetwork.Ssid))
{
connectivityLevel = connectedProfile.GetNetworkConnectivityLevel().ToString();
}
}
ConnectivityLevel = connectivityLevel;
OnPropertyChanged("ConnectivityLevel");
}
public String Ssid
{
get
{
return availableNetwork.Ssid;
}
}
public String Bssid
{
get
{
return availableNetwork.Bssid;
}
}
public String ChannelCenterFrequency
{
get
{
return string.Format("{0}kHz", availableNetwork.ChannelCenterFrequencyInKilohertz);
}
}
public String Rssi
{
get
{
return string.Format("{0}dBm", availableNetwork.NetworkRssiInDecibelMilliwatts);
}
}
public String SecuritySettings
{
get
{
return string.Format("Authentication: {0}; Encryption: {1}", availableNetwork.SecuritySettings.NetworkAuthenticationType, availableNetwork.SecuritySettings.NetworkEncryptionType);
}
}
public String ConnectivityLevel
{
get;
private set;
}
public BitmapImage WiFiImage
{
get;
private set;
}
private WiFiAvailableNetwork availableNetwork;
public WiFiAvailableNetwork AvailableNetwork
{
get
{
return availableNetwork;
}
private set
{
availableNetwork = value;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected async void OnPropertyChanged(string name)
{
var rootPage = MainPage.Current;
await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
});
}
}
}