diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-12 18:23:24 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-12 18:23:24 +0200 |
| commit | d9a89773f2f283fbf5596799dd4d50d231817203 (patch) | |
| tree | d213bc8024342356dc54654235b77decbdbd26b8 /Software/Visual_Studio/PPC/Tango.PPC.Common | |
| parent | de0b06ac48e9765914f4e07c0e03497033066296 (diff) | |
| download | Tango-d9a89773f2f283fbf5596799dd4d50d231817203.tar.gz Tango-d9a89773f2f283fbf5596799dd4d50d231817203.zip | |
IHotSpot Provider & IRemoteAssistance Provider.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common')
10 files changed, 380 insertions, 52 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/IConnectivityProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/IConnectivityProvider.cs index 077f05110..85c25128a 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/IConnectivityProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connectivity/IConnectivityProvider.cs @@ -79,23 +79,5 @@ namespace Tango.PPC.Common.Connectivity /// <param name="network">The network.</param> /// <returns></returns> void Disconnect(WiFiNetwork network); - - /// <summary> - /// Gets a value indicating whether the hot spot network is active. - /// </summary> - bool IsHotspotActive { get; } - - /// <summary> - /// Enables the hot spot. - /// </summary> - /// <param name="password">The password.</param> - /// <returns></returns> - Task EnableHotSpot(String password); - - /// <summary> - /// Disables the hot spot. - /// </summary> - /// <returns></returns> - Task DisableHotSpot(); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/HotSpot/DefaultHotSpotProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/HotSpot/DefaultHotSpotProvider.cs new file mode 100644 index 000000000..1126a84bc --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/HotSpot/DefaultHotSpotProvider.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.PPC.Common.Application; +using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Scripting; +using Tango.Settings; + +namespace Tango.PPC.Common.HotSpot +{ + /// <summary> + /// Represents the default hot spot provider. + /// </summary> + /// <seealso cref="Tango.Core.ExtendedObject" /> + /// <seealso cref="Tango.PPC.Common.HotSpot.IHotSpotProvider" /> + public class DefaultHotSpotProvider : ExtendedObject, IHotSpotProvider + { + private IMachineProvider _machineProvider; + + private bool _isEnabled; + /// <summary> + /// Gets a value indicating whether the hot spot network is active. + /// </summary> + public bool IsEnabled + { + get { return _isEnabled; } + private set { _isEnabled = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Initializes a new instance of the <see cref="DefaultHotSpotProvider"/> class. + /// </summary> + /// <param name="applicationManager">The application manager.</param> + /// <param name="machineProvider">The machine provider.</param> + public DefaultHotSpotProvider(IPPCApplicationManager applicationManager, IMachineProvider machineProvider) + { + _machineProvider = machineProvider; + applicationManager.ApplicationReady += ApplicationManager_ApplicationReady; + } + + /// <summary> + /// Handles the ApplicationReady event of the ApplicationManager. + /// </summary> + /// <param name="sender">The source of the event.</param> + /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> + private void ApplicationManager_ApplicationReady(object sender, EventArgs e) + { + Task.Factory.StartNew(async () => + { + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + + if (settings.EnableHotSpot) + { + try + { + await EnableHotSpot(settings.HotSpotPassword); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error starting on application startup."); + } + } + }); + } + + /// <summary> + /// Enables the hot spot. + /// </summary> + /// <param name="password">The password.</param> + /// <returns></returns> + public async Task EnableHotSpot(string password) + { + if (!IsEnabled) + { + try + { + CmdCommand command = new CmdCommand("netsh", $"wlan set hostednetwork mode=allow ssid='{"Tango_" + _machineProvider.Machine.SerialNumber}' key='{password}'"); + await command.Run(); + IsEnabled = 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 (IsEnabled) + { + try + { + CmdCommand command = new CmdCommand("netsh", "wlan stop hosted network"); + await command.Run(); + IsEnabled = false; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error deactivating hot spot."); + throw; + } + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/HotSpot/IHotSpotProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/HotSpot/IHotSpotProvider.cs new file mode 100644 index 000000000..1a4dabae3 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/HotSpot/IHotSpotProvider.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.HotSpot +{ + /// <summary> + /// Represents a hot-spot network provider. + /// </summary> + public interface IHotSpotProvider + { + /// <summary> + /// Gets a value indicating whether the hot spot network is active. + /// </summary> + bool IsEnabled { get; } + + /// <summary> + /// Enables the hot spot. + /// </summary> + /// <param name="password">The password.</param> + /// <returns></returns> + Task EnableHotSpot(String password); + + /// <summary> + /// Disables the hot spot. + /// </summary> + /// <returns></returns> + Task DisableHotSpot(); + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index 3c70e0744..3d816c89a 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -74,14 +74,25 @@ namespace Tango.PPC.Common.MachineSetup { LogManager.Log($"Starting machine setup for serial number {serialNumber}..."); - //Connecting to machine... - LogManager.Log("Initiating machine connection..."); + IMachineOperator op = null; - UpdateProgress("Connecting to machine", "Connecting..."); - IMachineOperator op = await DefaultMachineProvider.CreateMinimalMachineOperator((msg) => + var demoMode = SettingsManager.Default.GetOrCreate<PPCSettings>().DemoMode; + + if (!demoMode) { - UpdateProgress("Connecting to machine", msg); - }); + //Connecting to machine... + LogManager.Log("Initiating machine connection..."); + + UpdateProgress("Connecting to machine", "Connecting..."); + op = await DefaultMachineProvider.CreateMinimalMachineOperator((msg) => + { + UpdateProgress("Connecting to machine", msg); + }); + } + else + { + LogManager.Log("Application in demo mode. Skipping machine connection..."); + } //Connect to machine service and get matching packages for this machine. UpdateProgress("Downloading software package", "Connecting to machine service..."); @@ -238,39 +249,50 @@ namespace Tango.PPC.Common.MachineSetup throw LogManager.Log(ex, "Setup manager error while trying to synchronize database."); } - //Updating firmware - UpdateProgress("Updating Firmware", "Connecting to firmware device..."); - LogManager.Log(""); - LogManager.Log("-------------------------------------------------------------------------"); - LogManager.Log("Updating Firmware..."); - - UpdateProgress("Updating Firmware", "Loading firmware package..."); - var tfpPath = Path.Combine(_newPackageTempFolder, "firmware_package.tfp"); - var stream = new FileStream(tfpPath, FileMode.Open); - var handler = await op.UpgradeFirmware(stream); - handler.Failed += (_, ex) => + if (!demoMode) { - stream.Dispose(); - result.SetException(ex); - }; - handler.Completed += (_, __) => + //Updating firmware + UpdateProgress("Updating Firmware", "Connecting to firmware device..."); + LogManager.Log(""); + LogManager.Log("-------------------------------------------------------------------------"); + LogManager.Log("Updating Firmware..."); + + UpdateProgress("Updating Firmware", "Loading firmware package..."); + var tfpPath = Path.Combine(_newPackageTempFolder, "firmware_package.tfp"); + var stream = new FileStream(tfpPath, FileMode.Open); + var handler = await op.UpgradeFirmware(stream); + handler.Failed += (_, ex) => + { + stream.Dispose(); + result.SetException(ex); + }; + handler.Completed += (_, __) => + { + UpdateProgress("Updating Firmware", "Firmware update completed successfully."); + stream.Dispose(); + result.SetResult(new MachineSetupResult() + { + UpdatePackagePath = _newPackageTempFolder, + }); + }; + handler.Canceled += (_, __) => + { + stream.Dispose(); + result.SetException(new Exception("The operation has been canceled.")); + }; + handler.Progress += (_, e) => + { + UpdateProgress("Updating Firmware", e.Message, false, e.Current, e.Total); + }; + } + else { - UpdateProgress("Updating Firmware", "Firmware update completed successfully."); - stream.Dispose(); + LogManager.Log("Application in demo mode. Skipping firmware upgrade..."); result.SetResult(new MachineSetupResult() { UpdatePackagePath = _newPackageTempFolder, }); - }; - handler.Canceled += (_, __) => - { - stream.Dispose(); - result.SetException(new Exception("The operation has been canceled.")); - }; - handler.Progress += (_, e) => - { - UpdateProgress("Updating Firmware", e.Message, false, e.Current, e.Total); - }; + } } catch (Exception ex) { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index b6ab9c163..142c3afe9 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -81,6 +81,11 @@ namespace Tango.PPC.Common public String HotSpotPassword { get; set; } /// <summary> + /// Gets or sets a value indicating whether to enable team viewer service. + /// </summary> + public bool EnableRemoteAssistance { get; set; } + + /// <summary> /// Initializes a new instance of the <see cref="PPCSettings"/> class. /// </summary> public PPCSettings() diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs index dc67d2137..289683855 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs @@ -11,9 +11,11 @@ using Tango.PPC.Common.Connection; using Tango.PPC.Common.Connectivity; using Tango.PPC.Common.EventLogging; using Tango.PPC.Common.ExternalBridge; +using Tango.PPC.Common.HotSpot; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.Printing; +using Tango.PPC.Common.RemoteAssistance; using Tango.PPC.Common.Storage; using Tango.Settings; using Tango.SharedUI; @@ -84,6 +86,18 @@ namespace Tango.PPC.Common public IConnectivityProvider ConnectivityProvider { get; set; } /// <summary> + /// Gets or sets the hot spot provider. + /// </summary> + [TangoInject] + public IHotSpotProvider HotSpotProvider { get; set; } + + /// <summary> + /// Gets or sets the remote assistance provider. + /// </summary> + [TangoInject] + public IRemoteAssistanceProvider RemoteAssistanceProvider { get; set; } + + /// <summary> /// Gets or sets the storage provider. /// </summary> [TangoInject] diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/DefaultRemoteAssistanceProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/DefaultRemoteAssistanceProvider.cs new file mode 100644 index 000000000..53596544a --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/DefaultRemoteAssistanceProvider.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Scripting; + +namespace Tango.PPC.Common.RemoteAssistance +{ + /// <summary> + /// Represents the default remote assistance provider. + /// </summary> + /// <seealso cref="Tango.Core.ExtendedObject" /> + /// <seealso cref="Tango.PPC.Common.RemoteAssistance.IRemoteAssistanceProvider" /> + public class DefaultRemoteAssistanceProvider : ExtendedObject, IRemoteAssistanceProvider + { + private IMachineProvider _machineProvider; + + private bool _isEnabled; + /// <summary> + /// Gets a value indicating whether the remote assistance service is enabled. + /// </summary> + public bool IsEnabled + { + get { return _isEnabled; } + private set { _isEnabled = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Initializes a new instance of the <see cref="DefaultRemoteAssistanceProvider"/> class. + /// </summary> + /// <param name="machineProvider">The machine provider.</param> + public DefaultRemoteAssistanceProvider(IMachineProvider machineProvider) + { + _machineProvider = machineProvider; + } + + /// <summary> + /// Enables the remote assistance. + /// </summary> + /// <returns></returns> + public async Task EnableRemoteAssistance() + { + if (!IsEnabled) + { + try + { + CmdCommand command = new CmdCommand("sc.exe", "config TeamViewer start=auto"); + command.Timeout = TimeSpan.FromSeconds(10); + await command.Run(); + + command = new CmdCommand("net", "start TeamViewer"); + command.Timeout = TimeSpan.FromSeconds(10); + await command.Run(); + + IsEnabled = true; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error enabling remote assistance."); + throw; + } + } + } + + /// <summary> + /// Disables the remote assistance. + /// </summary> + /// <returns></returns> + public async Task DisableRemoteAssistance() + { + if (IsEnabled) + { + try + { + CmdCommand command = new CmdCommand("sc.exe", "config TeamViewer start=disabled"); + command.Timeout = TimeSpan.FromSeconds(10); + await command.Run(); + + command = new CmdCommand("net", "stop TeamViewer"); + command.Timeout = TimeSpan.FromSeconds(10); + await command.Run(); + IsEnabled = false; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error disabling remote assistance."); + throw; + } + } + } + + /// <summary> + /// Installs the remote assistance. + /// </summary> + /// <param name="groupName">Name of the group.</param> + /// <param name="computerName">Name of the computer.</param> + /// <returns></returns> + public async Task InstallRemoteAssistance(string groupName, string computerName) + { + try + { + CmdCommand command = new CmdCommand("msiexec.exe", $"/i \"C:\\Program Files(x86)\\TeamViewer\\TeamViewer_Host.msi\" /qn CUSTOMCONFIGID=ke43ann APITOKEN=4765529-gon1LwO1N1TTrlLI21ji ASSIGNMENTOPTIONS=\" --reassign --alias {"TANGO-" + _machineProvider.Machine.SerialNumber} --grant-easy-access\""); + await command.Run(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error installing remote assistance."); + throw; + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/IRemoteAssistanceProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/IRemoteAssistanceProvider.cs new file mode 100644 index 000000000..288b5c652 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/IRemoteAssistanceProvider.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.RemoteAssistance +{ + /// <summary> + /// Represents a remote assistance provider. + /// </summary> + public interface IRemoteAssistanceProvider + { + /// <summary> + /// Gets a value indicating whether the remote assistance service is enabled. + /// </summary> + bool IsEnabled { get; } + + /// <summary> + /// Enables the remote assistance. + /// </summary> + /// <returns></returns> + Task EnableRemoteAssistance(); + + /// <summary> + /// Disables the remote assistance. + /// </summary> + /// <returns></returns> + Task DisableRemoteAssistance(); + + /// <summary> + /// Installs the remote assistance. + /// </summary> + /// <param name="groupName">Name of the group.</param> + /// <param name="computerName">Name of the computer.</param> + /// <returns></returns> + Task InstallRemoteAssistance(String groupName, String computerName); + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs index 2ee0d83d9..abae98f06 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Scripting/CmdCommand.cs @@ -29,6 +29,7 @@ namespace Tango.PPC.Common.Scripting _process.StartInfo.RedirectStandardError = true; _process.StartInfo.RedirectStandardOutput = true; _process.StartInfo.Arguments = arguments; + _process.StartInfo.Verb = "runas"; Arguments = arguments; } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index b9d9c7620..2f95d5060 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -128,6 +128,8 @@ <Compile Include="ExtensionMethods\ObservableCollectionExtensions.cs" /> <Compile Include="ExternalBridge\IPPCExternalBridgeService.cs" /> <Compile Include="ExternalBridge\PPCExternalBridgeService.cs" /> + <Compile Include="HotSpot\DefaultHotSpotProvider.cs" /> + <Compile Include="HotSpot\IHotSpotProvider.cs" /> <Compile Include="IPPCView.cs" /> <Compile Include="MachineSetup\IMachineSetupManager.cs" /> <Compile Include="MachineSetup\MachineSetupManager.cs" /> @@ -158,6 +160,8 @@ <Compile Include="PPCModuleAttribute.cs" /> <Compile Include="PPCModuleBase.cs" /> <Compile Include="Printing\IPrintingManager.cs" /> + <Compile Include="RemoteAssistance\DefaultRemoteAssistanceProvider.cs" /> + <Compile Include="RemoteAssistance\IRemoteAssistanceProvider.cs" /> <Compile Include="Scripting\CmdCommand.cs" /> <Compile Include="Storage\DefaultStorageProvider.cs" /> <Compile Include="Storage\IStorageProvider.cs" /> @@ -326,7 +330,7 @@ </Target> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file |
