From d9a89773f2f283fbf5596799dd4d50d231817203 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 12 Dec 2018 18:23:24 +0200 Subject: IHotSpot Provider & IRemoteAssistance Provider. --- .../DefaultRemoteAssistanceProvider.cs | 115 +++++++++++++++++++++ .../RemoteAssistance/IRemoteAssistanceProvider.cs | 39 +++++++ 2 files changed, 154 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/DefaultRemoteAssistanceProvider.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/IRemoteAssistanceProvider.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance') 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 +{ + /// + /// Represents the default remote assistance provider. + /// + /// + /// + public class DefaultRemoteAssistanceProvider : ExtendedObject, IRemoteAssistanceProvider + { + private IMachineProvider _machineProvider; + + private bool _isEnabled; + /// + /// Gets a value indicating whether the remote assistance service is enabled. + /// + public bool IsEnabled + { + get { return _isEnabled; } + private set { _isEnabled = value; RaisePropertyChangedAuto(); } + } + + /// + /// Initializes a new instance of the class. + /// + /// The machine provider. + public DefaultRemoteAssistanceProvider(IMachineProvider machineProvider) + { + _machineProvider = machineProvider; + } + + /// + /// Enables the remote assistance. + /// + /// + 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; + } + } + } + + /// + /// Disables the remote assistance. + /// + /// + 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; + } + } + } + + /// + /// Installs the remote assistance. + /// + /// Name of the group. + /// Name of the computer. + /// + 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 +{ + /// + /// Represents a remote assistance provider. + /// + public interface IRemoteAssistanceProvider + { + /// + /// Gets a value indicating whether the remote assistance service is enabled. + /// + bool IsEnabled { get; } + + /// + /// Enables the remote assistance. + /// + /// + Task EnableRemoteAssistance(); + + /// + /// Disables the remote assistance. + /// + /// + Task DisableRemoteAssistance(); + + /// + /// Installs the remote assistance. + /// + /// Name of the group. + /// Name of the computer. + /// + Task InstallRemoteAssistance(String groupName, String computerName); + } +} -- cgit v1.3.1