aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-12-11 19:43:35 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-12-11 19:43:35 +0200
commit48f781d037a83c51fdd555fb6c9d1c2b4e424efe (patch)
treec13666e1ecb34dca68a8755af5c69534a493951f /Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity
parent1952756022f71729aab3cea304d039f9b340b5d2 (diff)
downloadTango-48f781d037a83c51fdd555fb6c9d1c2b4e424efe.tar.gz
Tango-48f781d037a83c51fdd555fb6c9d1c2b4e424efe.zip
Working on PPC hotspot and external bridge.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs72
1 files changed, 71 insertions, 1 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 a3420fb01..fbc619e12 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs
@@ -17,6 +17,7 @@ using Tango.PPC.Common.Application;
using Tango.PPC.Common.Connection;
using Tango.PPC.Common.Connectivity;
using Tango.PPC.Common.Notifications;
+using Tango.PPC.Common.Scripting;
using Tango.Settings;
using Tango.WiFi;
@@ -26,6 +27,7 @@ namespace Tango.PPC.UI.Connectivity
{
private Wifi _wifi;
private INotificationProvider _notification;
+ private IMachineProvider _machineProvider;
/// <summary>
/// Occurs when the connectivity provider state has changed (e.g network connected/disconnected).
@@ -42,6 +44,16 @@ namespace Tango.PPC.UI.Connectivity
set { _isConnected = value; RaisePropertyChangedAuto(); }
}
+ private bool _isHotspoActive;
+ /// <summary>
+ /// Gets a value indicating whether the hot spot network is active.
+ /// </summary>
+ public bool IsHotspotActive
+ {
+ get { return _isHotspoActive; }
+ set { _isHotspoActive = value; RaisePropertyChangedAuto(); }
+ }
+
/// <summary>
/// Gets the available WiFi networks.
/// </summary>
@@ -70,9 +82,10 @@ namespace Tango.PPC.UI.Connectivity
/// <summary>
/// Initializes a new instance of the <see cref="DefaultConnectivityProvider"/> class.
/// </summary>
- public DefaultConnectivityProvider(IPPCApplicationManager applicationManager, INotificationProvider notificationProvider)
+ public DefaultConnectivityProvider(IPPCApplicationManager applicationManager, INotificationProvider notificationProvider, IMachineProvider machineProvider)
{
_notification = notificationProvider;
+ _machineProvider = machineProvider;
AvailableWiFiNetworks = new ObservableCollection<WiFiNetwork>();
AvailableWiFiNetworks.EnableCrossThreadOperations();
@@ -125,6 +138,18 @@ namespace Tango.PPC.UI.Connectivity
{
await Connect(auto_connect_network);
}
+
+ if (settings.EnableHotSpot)
+ {
+ try
+ {
+ await EnableHotSpot(settings.HotSpotPassword);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error starting on application startup.");
+ }
+ }
});
}
@@ -264,5 +289,50 @@ namespace Tango.PPC.UI.Connectivity
IsConnected = connected;
ConnectionStateChanged?.Invoke(this, new ConnectionStateEventArgs() { IsConnected = connected });
}
+
+ /// <summary>
+ /// Enables the hot spot.
+ /// </summary>
+ /// <param name="password">The password.</param>
+ /// <returns></returns>
+ public async Task EnableHotSpot(string password)
+ {
+ if (!IsHotspotActive)
+ {
+ try
+ {
+ CmdCommand command = new CmdCommand("netsh", $"wlan set hostednetwork mode=allow ssid='{"Tango_" + _machineProvider.Machine.SerialNumber}' key='{password}'");
+ await command.Run();
+ IsHotspotActive = true;
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error activating hot spot.");
+ throw;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Disables the hot spot.
+ /// </summary>
+ /// <returns></returns>
+ public async Task DisableHotSpot()
+ {
+ if (IsHotspotActive)
+ {
+ try
+ {
+ CmdCommand command = new CmdCommand("netsh", "wlan stop hosted network");
+ await command.Run();
+ IsHotspotActive = false;
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error deactivating hot spot.");
+ throw;
+ }
+ }
+ }
}
}