aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs
index dabfc5893..53e143def 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs
@@ -28,6 +28,8 @@ namespace Tango.PPC.UI.Connectivity
private INotificationProvider _notification;
private IMachineProvider _machineProvider;
private Rfc2898Cryptographer _cryptographer;
+ private System.Timers.Timer _updateTimer;
+ private WiFiNetwork _connectedNetwork;
/// <summary>
/// Occurs when the connectivity provider state has changed (e.g network connected/disconnected).
@@ -136,12 +138,40 @@ namespace Tango.PPC.UI.Connectivity
IsConnected = networks.Exists(x => x.IsConnected);
+ if (IsConnected)
+ {
+ _connectedNetwork = auto_connect_network;
+ }
+
if (auto_connect_network != null && !auto_connect_network.IsConnected)
{
auto_connect_network.AutoConnect = true;
await Connect(auto_connect_network, _cryptographer.Decrypt(settings.AutoConnectWiFiPassword));
}
});
+
+ _updateTimer = new System.Timers.Timer(TimeSpan.FromSeconds(30).TotalMilliseconds);
+ _updateTimer.Elapsed += _updateTimer_Elapsed;
+ _updateTimer.Start();
+ }
+
+ /// <summary>
+ /// Periodically checks if WiFI network is gone/disconnected.
+ /// </summary>
+ /// <param name="sender">The source of the event.</param>
+ /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param>
+ private void _updateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
+ {
+ if (IsConnected && _connectedNetwork != null)
+ {
+ var networks = GetAvailableWiFiNetworks().Result;
+ var matching_network = networks.FirstOrDefault(x => x.Name == _connectedNetwork.Name);
+
+ if (matching_network == null || !matching_network.AccessPoint.IsConnected)
+ {
+ OnConnectionStateChanged(false);
+ }
+ }
}
/// <summary>
@@ -264,6 +294,7 @@ namespace Tango.PPC.UI.Connectivity
settings.AutoConnectWiFiName = network.AutoConnect ? network.Name : null;
settings.AutoConnectWiFiPassword = _cryptographer.Encrypt(auth.Password);
settings.Save();
+ _connectedNetwork = network;
}
return result;
@@ -295,6 +326,10 @@ namespace Tango.PPC.UI.Connectivity
/// <param name="connected">if set to <c>true</c> [connected].</param>
protected virtual void OnConnectionStateChanged(bool connected)
{
+ if (!connected)
+ {
+ _connectedNetwork = null;
+ }
IsConnected = connected;
ConnectionStateChanged?.Invoke(this, new ConnectionStateEventArgs() { IsConnected = connected });
}