diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-05-24 19:35:16 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-05-24 19:35:16 +0300 |
| commit | 3b9b17a00716128ed9f68728c31714f753b8e9ea (patch) | |
| tree | 626699296ceb7ea5119e664f99554b53db31cde9 /Software/Visual_Studio/VSIX/Tango.BuildExtensions/VSIXBase.cs | |
| parent | 5fd370643691a312e1266f138982d784f0f9ebb1 (diff) | |
| download | Tango-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/VSIXBase.cs')
| -rw-r--r-- | Software/Visual_Studio/VSIX/Tango.BuildExtensions/VSIXBase.cs | 298 |
1 files changed, 298 insertions, 0 deletions
diff --git a/Software/Visual_Studio/VSIX/Tango.BuildExtensions/VSIXBase.cs b/Software/Visual_Studio/VSIX/Tango.BuildExtensions/VSIXBase.cs new file mode 100644 index 000000000..068268298 --- /dev/null +++ b/Software/Visual_Studio/VSIX/Tango.BuildExtensions/VSIXBase.cs @@ -0,0 +1,298 @@ +using System; +using System.ComponentModel.Design; +using System.Globalization; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using System.Collections.Generic; +using EnvDTE; +using EnvDTE80; +using Microsoft.VisualStudio; +using System.Linq; +using TestStack.White.UIItems.Finders; +using TestStack.White.InputDevices; +using TestStack.White.UIItems; +using VSLangProj; +using System.Runtime.InteropServices; +using TestStack.White.WindowsAPI; +using System.IO; + +namespace Tango.BuildExtensions +{ + public class VSIXBase + { + private SelectForm _form; + + public IServiceProvider BaseServiceProvider { get; private set; } + + public DTE2 DTE { get; private set; } + + public VSIXBase(IServiceProvider serviceProvider) + { + BaseServiceProvider = serviceProvider; + DTE = GetActiveIDE(); + } + + #region Solution & Projects + + private DTE2 GetActiveIDE() + { + // Get an instance of currently running Visual Studio IDE. + DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2; + return dte2; + } + + public IList<Project> GetSolutionProjects() + { + 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; + } + + public List<ProjectItem> GetProjectItems(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); + } + } + } + + protected String GetProjectOutputFilePath(EnvDTE.Project vsProject) + { + string fullPath = vsProject.Properties.Item("FullPath").Value.ToString(); + + string outputPath = vsProject.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString(); + + string outputDir = Path.Combine(fullPath, outputPath); + + string outputFileName = vsProject.Properties.Item("OutputFileName").Value.ToString(); + + string assemblyPath = Path.Combine(outputDir, outputFileName); + + return assemblyPath; + } + + #endregion + + #region Notifications + + public 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); + } + + public void ShowMessage(String text) + { + // Show a message box to prove we were here + + VsShellUtilities.ShowMessageBox( + BaseServiceProvider, + text, + "Tango Initializer", + OLEMSGICON.OLEMSGICON_INFO, + OLEMSGBUTTON.OLEMSGBUTTON_OK, + OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + } + + #endregion + + #region Windows API + + protected 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; + } + + protected 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 + + protected void Wait(int milli) + { + System.Threading.Thread.Sleep(milli); + } + + #endregion + + #region Status Form + + protected 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) { } + } + + protected void SetProgressText(String text) + { + if (_form != null) + { + _form.Invoke(new Action(() => + { + _form.SetStatus(text); + })); + } + } + + protected void CloseProgressForm() + { + if (_form != null) + { + _form.Invoke(new Action(() => + { + _form.Close(); + _form = null; + })); + } + } + + #endregion + + #region Content + + protected string GetFullPathToContentFile(String fileName) + { + return Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase), fileName).Replace("file:\\", ""); + } + + #endregion + + #region IO + + /// <summary> + /// Copies the specified directory source path to the specified destination. + /// </summary> + /// <param name="sourcePath">The source path.</param> + /// <param name="destinationPath">The destination path.</param> + /// <param name="copySubDirs">if set to <c>true</c> will copy sub directories.</param> + /// <exception cref="DirectoryNotFoundException">Source directory does not exist or could not be found: " + /// + sourcePath</exception> + protected void CopyDirectory(string sourcePath, string destinationPath, bool copySubDirs, Action<String> progress = null) + { + // Get the subdirectories for the specified directory. + DirectoryInfo dir = new DirectoryInfo(sourcePath); + + if (!dir.Exists) + { + throw new DirectoryNotFoundException( + "Source directory does not exist or could not be found: " + + sourcePath); + } + + DirectoryInfo[] dirs = dir.GetDirectories(); + // If the destination directory doesn't exist, create it. + if (!Directory.Exists(destinationPath)) + { + Directory.CreateDirectory(destinationPath); + } + + // Get the files in the directory and copy them to the new location. + FileInfo[] files = dir.GetFiles(); + foreach (FileInfo file in files) + { + string temppath = Path.Combine(destinationPath, file.Name); + progress?.Invoke(temppath); + file.CopyTo(temppath, true); + } + + // If copying subdirectories, copy them and their contents to new location. + if (copySubDirs) + { + foreach (DirectoryInfo subdir in dirs) + { + string temppath = Path.Combine(destinationPath, subdir.Name); + CopyDirectory(subdir.FullName, temppath, copySubDirs); + } + } + } + + #endregion + } +} |
