blob: 46a1e2355bcc199bdd255e14a075dad5f79fee79 (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.Commands;
using Tango.WiFi;
namespace Tango.PPC.Common.Connectivity
{
public class WiFiNetwork : ExtendedObject
{
private Wifi _wifi;
public bool IsConnected
{
get { return AccessPoint.IsConnected; }
}
public String Name
{
get { return AccessPoint.Name; }
}
public double SignalStrength
{
get { return AccessPoint.SignalStrength; }
}
public bool IsSecure
{
get { return AccessPoint.IsSecure; }
}
public bool HasProfile
{
get { return AccessPoint.HasProfile; }
}
private AccessPoint _accessPoint;
public AccessPoint AccessPoint
{
get { return _accessPoint; }
set
{
_accessPoint = value;
foreach (var prop in this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
RaisePropertyChanged(prop.Name);
}
}
}
private bool _autoConnect;
public bool AutoConnect
{
get { return _autoConnect; }
set { _autoConnect = value; RaisePropertyChangedAuto(); }
}
private bool _connecting;
public bool Connecting
{
get { return _connecting; }
set { _connecting = value; RaisePropertyChangedAuto(); }
}
private bool _disconnecting;
public bool Disconnecting
{
get { return _disconnecting; }
set { _disconnecting = value; RaisePropertyChangedAuto(); }
}
public WiFiNetwork(AccessPoint accessPoint, Wifi wifi)
{
_wifi = wifi;
AccessPoint = accessPoint;
}
public WiFiAuthentication CreateAuthenticationRequest()
{
return new WiFiAuthentication(new AuthRequest(AccessPoint));
}
public Task<bool> Connect(WiFiAuthentication request, bool overwriteProfile)
{
return Task.Factory.StartNew<bool>(() =>
{
try
{
Connecting = true;
return AccessPoint.Connect(request.AuthRequest, overwriteProfile);
}
catch (Exception)
{
throw;
}
finally
{
Connecting = false;
}
});
}
public Task Disconnect()
{
return Task.Factory.StartNew(() =>
{
try
{
Disconnecting = true;
_wifi.Disconnect();
AccessPoint.DeleteProfile();
}
catch (Exception)
{
throw;
}
finally
{
Disconnecting = false;
}
});
}
public Task Forget()
{
return Task.Factory.StartNew(() =>
{
try
{
AccessPoint.DeleteProfile();
}
catch
{
}
});
}
}
}
|