From 3b9b17a00716128ed9f68728c31714f753b8e9ea Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 24 May 2018 19:35:16 +0300 Subject: Implemented Remote Debugging for panel PC as VS command using PsiExec! Started investigating the Surface SDK controls. --- .../Tango.BuildExtensions/RemoteDebugCommand.cs | 169 +++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs (limited to 'Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs') diff --git a/Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs b/Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs new file mode 100644 index 000000000..d4f072635 --- /dev/null +++ b/Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs @@ -0,0 +1,169 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Company. All rights reserved. +// +//------------------------------------------------------------------------------ + +using System; +using System.ComponentModel.Design; +using System.Globalization; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using System.Linq; +using System.IO; +using System.Diagnostics; + +namespace Tango.BuildExtensions +{ + /// + /// Command handler + /// + internal sealed class RemoteDebugCommand : VSIXBase + { + private const string SHARED_PATH = @"\\twine01\data\RemoteDebugging"; + + /// + /// Command ID. + /// + public const int CommandId = 4129; + + /// + /// Command menu group (command set GUID). + /// + public static readonly Guid CommandSet = new Guid("c03a7b01-8109-4ec5-8f90-858bed027e5d"); + + /// + /// VS Package that provides this command, not null. + /// + private readonly Package package; + + /// + /// Initializes a new instance of the class. + /// Adds our command handlers for menu (commands must exist in the command table file) + /// + /// Owner package, not null. + private RemoteDebugCommand(Package package) : base(package) + { + if (package == null) + { + throw new ArgumentNullException("package"); + } + + this.package = package; + + OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; + if (commandService != null) + { + var menuCommandID = new CommandID(CommandSet, CommandId); + var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID); + commandService.AddCommand(menuItem); + } + } + + /// + /// Gets the instance of the command. + /// + public static RemoteDebugCommand Instance + { + get; + private set; + } + + /// + /// Gets the service provider from the owner package. + /// + private IServiceProvider ServiceProvider + { + get + { + return this.package; + } + } + + /// + /// Initializes the singleton instance of the command. + /// + /// Owner package, not null. + public static void Initialize(Package package) + { + Instance = new RemoteDebugCommand(package); + } + + // %ifnot% $toolWindow$ + /// + /// This function is the callback used to execute the command when the menu item is clicked. + /// See the constructor to see how the menu item is associated with this function using + /// OleMenuCommandService service and MenuCommand class. + /// + /// Event sender. + /// Event args. + private void MenuItemCallback(object sender, EventArgs e) + { + RunRemote(); + } + + private void RunRemote() + { + try + { + String projectName = DTE.Solution.Properties.Item("StartupProject").Value.ToString(); + + RemoteDebugForm dlg = new RemoteDebugForm(projectName); + + if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + System.Threading.Tasks.Task.Factory.StartNew(() => + { + OpenProgressForm(); + + SetProgressText("Building " + projectName + "..."); + + var project = GetSolutionProjects().SingleOrDefault(x => x.Name == projectName); + + String filePath = GetProjectOutputFilePath(project); + String folder = Path.GetDirectoryName(filePath); + String fileName = Path.GetFileName(filePath); + String remoteFolder = Path.Combine(SHARED_PATH, projectName); + String remoteFilePath = Path.Combine(remoteFolder, fileName); + + DTE.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true); + + Directory.CreateDirectory(remoteFolder); + + CopyDirectory(folder, remoteFolder, true, (file) => + { + SetProgressText("Copying to " + file + "..."); + }); + + String PsExecPath = GetFullPathToContentFile("PsExec.exe"); + + SetProgressText("Executing remote process..."); + + Process p = new Process(); + p.StartInfo.FileName = PsExecPath; + p.StartInfo.UseShellExecute = false; + p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + p.StartInfo.CreateNoWindow = true; + p.EnableRaisingEvents = true; + p.StartInfo.RedirectStandardError = true; + p.StartInfo.RedirectStandardOutput = false; + p.ErrorDataReceived += (x, e) => + { + SetProgressText("The process will start shortly, please wait..."); + Wait(20000); + CloseProgressForm(); + }; + p.StartInfo.Arguments = String.Format("-u {0} -p {1} -i {2} \"{3}\" -accepteula", dlg.UserName, dlg.Password, dlg.HostName, remoteFilePath); + p.Start(); + p.BeginErrorReadLine(); + }); + } + } + catch (Exception ex) + { + CloseProgressForm(); + ShowMessage(ex.Message); + } + } + } +} -- cgit v1.3.1