aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/VSIX/Tango.BuildExtensions/TangoBuildCommand.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-05-24 19:35:16 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-05-24 19:35:16 +0300
commit3b9b17a00716128ed9f68728c31714f753b8e9ea (patch)
tree626699296ceb7ea5119e664f99554b53db31cde9 /Software/Visual_Studio/VSIX/Tango.BuildExtensions/TangoBuildCommand.cs
parent5fd370643691a312e1266f138982d784f0f9ebb1 (diff)
downloadTango-3b9b17a00716128ed9f68728c31714f753b8e9ea.tar.gz
Tango-3b9b17a00716128ed9f68728c31714f753b8e9ea.zip
Implemented Remote Debugging for panel PC as VS command using PsiExec!
Started investigating the Surface SDK controls.
Diffstat (limited to 'Software/Visual_Studio/VSIX/Tango.BuildExtensions/TangoBuildCommand.cs')
-rw-r--r--Software/Visual_Studio/VSIX/Tango.BuildExtensions/TangoBuildCommand.cs284
1 files changed, 50 insertions, 234 deletions
diff --git a/Software/Visual_Studio/VSIX/Tango.BuildExtensions/TangoBuildCommand.cs b/Software/Visual_Studio/VSIX/Tango.BuildExtensions/TangoBuildCommand.cs
index 36506e5b0..f2fb09c36 100644
--- a/Software/Visual_Studio/VSIX/Tango.BuildExtensions/TangoBuildCommand.cs
+++ b/Software/Visual_Studio/VSIX/Tango.BuildExtensions/TangoBuildCommand.cs
@@ -27,9 +27,8 @@ namespace Tango.BuildExtensions
/// <summary>
/// Command handler
/// </summary>
- internal sealed class TangoBuildCommand
+ internal sealed class TangoBuildCommand : VSIXBase
{
- private DTE2 _dte;
private IList<Project> _projects;
private SelectForm _form;
private TestStack.White.Application _application;
@@ -66,7 +65,7 @@ namespace Tango.BuildExtensions
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
- private TangoBuildCommand(Package package)
+ private TangoBuildCommand(Package package) : base(package)
{
if (package == null)
{
@@ -138,9 +137,9 @@ namespace Tango.BuildExtensions
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
- _projects = Projects().ToList();
+ _projects = GetSolutionProjects().ToList();
- String vsWindowTitle = _dte.DTE.MainWindow.Caption;
+ String vsWindowTitle = DTE.DTE.MainWindow.Caption;
_vsProcess = System.Diagnostics.Process.GetProcesses().ToList().SingleOrDefault(x => x.MainWindowTitle == vsWindowTitle);
_application = TestStack.White.Application.Attach(_vsProcess);
_window = _application.GetWindow(vsWindowTitle);
@@ -170,7 +169,7 @@ namespace Tango.BuildExtensions
BuildSolution();
}
- SetStatusText("Done!");
+ SetProgressText("Done!");
Wait(1000);
CloseProgressForm();
}
@@ -193,41 +192,41 @@ namespace Tango.BuildExtensions
var projectItems = project.ProjectItems.OfType<ProjectItem>().ToList();
- SetStatusText("Locating " + edmxModelName + " scheme...");
+ SetProgressText("Locating " + edmxModelName + " scheme...");
- var items = GetProjectItemsDeep(project);
+ var items = GetProjectItems(project);
- var edmx = GetProjectItemsDeep(project).SingleOrDefault(x => x.Name == edmxModelName);
+ var edmx = GetProjectItems(project).SingleOrDefault(x => x.Name == edmxModelName);
if (edmx == null)
{
throw new NullReferenceException("Could not locate " + edmxModelName + "!");
}
- SetStatusText("Expanding diagram...");
+ SetProgressText("Expanding diagram...");
edmx.ExpandView();
- SetStatusText("Opening edmx diagram window...");
+ SetProgressText("Opening edmx diagram window...");
Window win = edmx.Open(EnvDTE.Constants.vsViewKindPrimary);
win.Visible = true;
- SetStatusText("Waiting for edmx diagram window...");
+ SetProgressText("Waiting for edmx diagram window...");
_window.WaitTill(() => _window.Get(SearchCriteria.ByText(edmxModelName + " [Diagram1]")) != null);
- SetStatusText("Cleaning up edmx scheme...");
+ SetProgressText("Cleaning up edmx scheme...");
- _dte.MainWindow.Activate();
- _dte.ExecuteCommand("Edit.SelectAll");
+ DTE.MainWindow.Activate();
+ DTE.ExecuteCommand("Edit.SelectAll");
Keyboard.Instance.PressSpecialKey(KeyboardInput.SpecialKeys.DELETE);
WaitForWindowOpen("Delete Unmapped Tables and Views").PressKey(KeyboardInput.SpecialKeys.RETURN);
WaitForWindowClose("Delete Unmapped Tables and Views");
_window.WaitWhileBusy();
- SetStatusText("Reinitializing edmx scheme...");
+ SetProgressText("Reinitializing edmx scheme...");
var window = WindowInfo.GetWindow(edmxModelName + " [Diagram1]*");
window.SetActive();
@@ -258,13 +257,13 @@ namespace Tango.BuildExtensions
updateWindow.PressKey(KeyboardInput.SpecialKeys.RETURN);
- SetStatusText("Generating edmx scheme...");
+ SetProgressText("Generating edmx scheme...");
WaitForWindowClose("Update Wizard");
_window.WaitWhileBusy();
- SetStatusText("Saving changes...");
+ SetProgressText("Saving changes...");
win.Close(vsSaveChanges.vsSaveChangesYes);
@@ -272,18 +271,18 @@ namespace Tango.BuildExtensions
foreach (var template in edmx.ProjectItems.OfType<ProjectItem>().Where(x => x.Name.EndsWith(".tt")))
{
- SetStatusText("Running custom tool for " + template.Name + "...");
+ SetProgressText("Running custom tool for " + template.Name + "...");
(template.Object as VSProjectItem).RunCustomTool();
_window.WaitWhileBusy();
}
_window.WaitWhileBusy();
- SetStatusText("Building project " + dalProjectName + "...");
+ SetProgressText("Building project " + dalProjectName + "...");
- _dte.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true);
+ DTE.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true);
- if (_dte.Solution.SolutionBuild.LastBuildInfo > 0)
+ if (DTE.Solution.SolutionBuild.LastBuildInfo > 0)
{
throw new ExternalException(dalProjectName + " failed to build!");
}
@@ -298,15 +297,15 @@ namespace Tango.BuildExtensions
throw new NullReferenceException("Could not locate project " + observablesGeneratorProjectName);
}
- SetStatusText("Building project " + observablesGeneratorProjectName + "...");
+ SetProgressText("Building project " + observablesGeneratorProjectName + "...");
- _dte.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true);
+ DTE.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true);
- _dte.Solution.Properties.Item("StartupProject").Value = observablesGeneratorProjectName;
+ DTE.Solution.Properties.Item("StartupProject").Value = observablesGeneratorProjectName;
- SetStatusText("Executing observables generator...");
+ SetProgressText("Executing observables generator...");
- _dte.ExecuteCommand("Debug.Start");
+ DTE.ExecuteCommand("Debug.Start");
WaitForWindowOpen("Tango Observables Generator");
@@ -319,7 +318,7 @@ namespace Tango.BuildExtensions
throw new NullReferenceException("Could not locate project " + observablesProjectName);
}
- SetStatusText("Updating " + observablesProjectName + "...");
+ SetProgressText("Updating " + observablesProjectName + "...");
foreach (var file in Directory.GetFiles(Path.GetDirectoryName(observablesProject.FileName), "*.cs", SearchOption.AllDirectories))
{
@@ -327,17 +326,17 @@ namespace Tango.BuildExtensions
if (parentFolderName != "Debug" && parentFolderName != "Release" && parentFolderName != "obj")
{
- SetStatusText("Adding/Updating file " + Path.GetFileName(file) + "...");
+ SetProgressText("Adding/Updating file " + Path.GetFileName(file) + "...");
observablesProject.ProjectItems.AddFromFile(file);
Wait(10);
}
}
- SetStatusText("Building project " + observablesProjectName + "...");
+ SetProgressText("Building project " + observablesProjectName + "...");
- _dte.Solution.SolutionBuild.BuildProject("Debug", observablesProject.FullName, true);
+ DTE.Solution.SolutionBuild.BuildProject("Debug", observablesProject.FullName, true);
- if (_dte.Solution.SolutionBuild.LastBuildInfo > 0)
+ if (DTE.Solution.SolutionBuild.LastBuildInfo > 0)
{
throw new ExternalException(observablesProjectName + " failed to build!");
}
@@ -352,15 +351,15 @@ namespace Tango.BuildExtensions
throw new NullReferenceException("Could not locate project " + pmrGeneratorProjectName);
}
- SetStatusText("Building project " + pmrGeneratorProjectName + "...");
+ SetProgressText("Building project " + pmrGeneratorProjectName + "...");
- _dte.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true);
+ DTE.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true);
- _dte.Solution.Properties.Item("StartupProject").Value = pmrGeneratorProjectName;
+ DTE.Solution.Properties.Item("StartupProject").Value = pmrGeneratorProjectName;
- SetStatusText("Executing PMR generator...");
+ SetProgressText("Executing PMR generator...");
- _dte.ExecuteCommand("Debug.Start");
+ DTE.ExecuteCommand("Debug.Start");
WaitForWindowOpen("Tango PMR Generator");
@@ -376,20 +375,20 @@ namespace Tango.BuildExtensions
throw new NullReferenceException("Could not locate project " + protoCliProjectName);
}
- SetStatusText("Building project " + protoCliProjectName + "...");
+ SetProgressText("Building project " + protoCliProjectName + "...");
- _dte.Solution.SolutionBuild.BuildProject("Debug", protoProject.FullName, true);
+ DTE.Solution.SolutionBuild.BuildProject("Debug", protoProject.FullName, true);
- if (_dte.Solution.SolutionBuild.LastBuildInfo > 0)
+ if (DTE.Solution.SolutionBuild.LastBuildInfo > 0)
{
throw new ExternalException(protoCliProjectName + " failed to build!");
}
- _dte.Solution.Properties.Item("StartupProject").Value = protoCliProjectName;
+ DTE.Solution.Properties.Item("StartupProject").Value = protoCliProjectName;
- SetStatusText("Executing Tango Proto Compiler...");
+ SetProgressText("Executing Tango Proto Compiler...");
- _dte.ExecuteCommand("Debug.Start");
+ DTE.ExecuteCommand("Debug.Start");
WaitForWindowOpen("Tango Protobuf Compiler");
@@ -403,7 +402,7 @@ namespace Tango.BuildExtensions
throw new NullReferenceException("Could not locate project " + pmrProjectName);
}
- SetStatusText("Updating " + pmrProjectName + "...");
+ SetProgressText("Updating " + pmrProjectName + "...");
foreach (var file in Directory.GetFiles(Path.GetDirectoryName(project.FileName), "*.cs", SearchOption.AllDirectories))
{
@@ -411,17 +410,17 @@ namespace Tango.BuildExtensions
if (parentFolderName != "Debug" && parentFolderName != "Release" && parentFolderName != "obj")
{
- SetStatusText("Adding/Updating file " + Path.GetFileName(file) + "...");
+ SetProgressText("Adding/Updating file " + Path.GetFileName(file) + "...");
project.ProjectItems.AddFromFile(file);
Wait(10);
}
}
- SetStatusText("Building project " + pmrProjectName + "...");
+ SetProgressText("Building project " + pmrProjectName + "...");
- _dte.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true);
+ DTE.Solution.SolutionBuild.BuildProject("Debug", project.FullName, true);
- if (_dte.Solution.SolutionBuild.LastBuildInfo > 0)
+ if (DTE.Solution.SolutionBuild.LastBuildInfo > 0)
{
throw new ExternalException(pmrProjectName + " failed to build!");
}
@@ -429,198 +428,15 @@ namespace Tango.BuildExtensions
private void BuildSolution()
{
- SetStatusText("Building solution...");
- _dte.Solution.SolutionBuild.Build(true);
+ SetProgressText("Building solution...");
+ DTE.Solution.SolutionBuild.Build(true);
- if (_dte.Solution.SolutionBuild.LastBuildInfo > 0)
+ if (DTE.Solution.SolutionBuild.LastBuildInfo > 0)
{
throw new ExternalException("Error building solution!");
}
}
#endregion
-
- #region Solution & Projects
-
- public DTE2 GetActiveIDE()
- {
- // Get an instance of currently running Visual Studio IDE.
- DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2;
- _dte = dte2;
- return dte2;
- }
-
- public IList<Project> Projects()
- {
- Projects projects = GetActiveIDE().Solution.Projects;
- List<Project> list = new List<Project>();
- var item = projects.GetEnumerator();
- while (item.MoveNext())
- {
- var project = item.Current as Project;
- if (project == null)
- {
- continue;
- }
-
- if (project.Kind == ProjectKinds.vsProjectKindSolutionFolder)
- {
- list.AddRange(GetSolutionFolderProjects(project));
- }
- else
- {
- list.Add(project);
- }
- }
-
- return list;
- }
-
- private IEnumerable<Project> GetSolutionFolderProjects(Project solutionFolder)
- {
- List<Project> list = new List<Project>();
- for (var i = 1; i <= solutionFolder.ProjectItems.Count; i++)
- {
- var subProject = solutionFolder.ProjectItems.Item(i).SubProject;
- if (subProject == null)
- {
- continue;
- }
-
- // If this is another solution folder, do a recursive call, otherwise add
- if (subProject.Kind == ProjectKinds.vsProjectKindSolutionFolder)
- {
- list.AddRange(GetSolutionFolderProjects(subProject));
- }
- else
- {
- list.Add(subProject);
- }
- }
- return list;
- }
-
- private List<ProjectItem> GetProjectItemsDeep(Project project)
- {
- List<ProjectItem> results = new List<ProjectItem>();
- FillProjectItems(project.ProjectItems.OfType<ProjectItem>().ToList(), results);
- return results;
- }
-
- private void FillProjectItems(List<ProjectItem> rootItems, List<ProjectItem> results)
- {
- foreach (var item in rootItems)
- {
- results.Add(item);
-
- if (item.ProjectItems.Count > 0)
- {
- FillProjectItems(item.ProjectItems.OfType<ProjectItem>().ToList(), results);
- }
- }
- }
-
- #endregion
-
- #region Notifications
-
- private void WriteToConsole(String text)
- {
- // Get the output window
- var outputWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
-
- // Ensure that the desired pane is visible
- var paneGuid = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
- IVsOutputWindowPane pane;
- outputWindow.CreatePane(paneGuid, "General", 1, 0);
- outputWindow.GetPane(paneGuid, out pane);
-
- // Output the message
- pane.OutputString(text + Environment.NewLine);
- }
-
- private void ShowMessage(String text)
- {
- // Show a message box to prove we were here
-
- VsShellUtilities.ShowMessageBox(
- ServiceProvider,
- text,
- "Tango Initializer",
- OLEMSGICON.OLEMSGICON_INFO,
- OLEMSGBUTTON.OLEMSGBUTTON_OK,
- OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
- }
-
- #endregion
-
- #region Windows API
-
- private WindowInfo WaitForWindowOpen(String title)
- {
- WindowInfo window = null;
-
- do
- {
- window = WindowInfo.GetAllWindows().SelectMany(x => x.Children).FirstOrDefault(x => x.Caption == title);
- } while (window == null);
-
- return window;
- }
-
- private void WaitForWindowClose(String title)
- {
- while (WindowInfo.GetAllWindows().SelectMany(x => x.Children).ToList().Exists(x => x.Caption == title))
- {
- System.Threading.Thread.Sleep(100);
- }
- }
-
- #endregion
-
- #region Threading
-
- private void Wait(int milli)
- {
- System.Threading.Thread.Sleep(milli);
- }
-
- #endregion
-
- #region Status Form
-
- private void OpenProgressForm()
- {
- System.Threading.Thread thread = new System.Threading.Thread(() =>
- {
- _form = new SelectForm();
- var handle = _form.Handle;
- _form.ShowDialog();
- });
-
- thread.SetApartmentState(System.Threading.ApartmentState.STA);
- thread.Start();
-
- while (_form == null || !_form.IsHandleCreated) { }
- }
-
- private void SetStatusText(String text)
- {
- _form.Invoke(new Action(() =>
- {
- _form.SetStatus(text);
- }));
- }
-
- private void CloseProgressForm()
- {
- _form.Invoke(new Action(() =>
- {
- _form.Close();
- _form = null;
- }));
- }
-
- #endregion
}
}