aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2018-05-27 14:29:20 +0300
committerMirta <mirta@twine-s.com>2018-05-27 14:29:20 +0300
commit2b35d18dc0631da5613073923a7a078cb2da5534 (patch)
tree3d80a7113cc7f45ecccea7a7228c26d0a2d098db /Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs
parentaae61aa72d939bee03ea6fd8896bef71e9c09b61 (diff)
parent2a3653d4eb3dce191dff82689cbd89aa27e10234 (diff)
downloadTango-2b35d18dc0631da5613073923a7a078cb2da5534.tar.gz
Tango-2b35d18dc0631da5613073923a7a078cb2da5534.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs')
-rw-r--r--Software/Visual_Studio/VSIX/Tango.BuildExtensions/RemoteDebugCommand.cs169
1 files changed, 169 insertions, 0 deletions
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 file="RemoteDebugCommand.cs" company="Company">
+// Copyright (c) Company. All rights reserved.
+// </copyright>
+//------------------------------------------------------------------------------
+
+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
+{
+ /// <summary>
+ /// Command handler
+ /// </summary>
+ internal sealed class RemoteDebugCommand : VSIXBase
+ {
+ private const string SHARED_PATH = @"\\twine01\data\RemoteDebugging";
+
+ /// <summary>
+ /// Command ID.
+ /// </summary>
+ public const int CommandId = 4129;
+
+ /// <summary>
+ /// Command menu group (command set GUID).
+ /// </summary>
+ public static readonly Guid CommandSet = new Guid("c03a7b01-8109-4ec5-8f90-858bed027e5d");
+
+ /// <summary>
+ /// VS Package that provides this command, not null.
+ /// </summary>
+ private readonly Package package;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="RemoteDebugCommand"/> class.
+ /// Adds our command handlers for menu (commands must exist in the command table file)
+ /// </summary>
+ /// <param name="package">Owner package, not null.</param>
+ 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);
+ }
+ }
+
+ /// <summary>
+ /// Gets the instance of the command.
+ /// </summary>
+ public static RemoteDebugCommand Instance
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// Gets the service provider from the owner package.
+ /// </summary>
+ private IServiceProvider ServiceProvider
+ {
+ get
+ {
+ return this.package;
+ }
+ }
+
+ /// <summary>
+ /// Initializes the singleton instance of the command.
+ /// </summary>
+ /// <param name="package">Owner package, not null.</param>
+ public static void Initialize(Package package)
+ {
+ Instance = new RemoteDebugCommand(package);
+ }
+
+ // %ifnot% $toolWindow$
+ /// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="sender">Event sender.</param>
+ /// <param name="e">Event args.</param>
+ 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);
+ }
+ }
+ }
+}