diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-01 17:56:49 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-01 17:56:49 +0300 |
| commit | 8a1e772f025eaf3bfdf17905d9e33c460993e559 (patch) | |
| tree | b6d705cca71033cd6c5f814596ceb9abc849bf50 /Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity | |
| parent | c0fd8dcc53e45aa5aa0095cc2c8c5f39a34f7886 (diff) | |
| download | Tango-8a1e772f025eaf3bfdf17905d9e33c460993e559.tar.gz Tango-8a1e772f025eaf3bfdf17905d9e33c460993e559.zip | |
Many bug fixes !!!
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs | 35 |
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 }); } |
