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/RemoteAssistance | |
| 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/RemoteAssistance')
2 files changed, 154 insertions, 0 deletions
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); + } +} |
