Example #1
0
        public static async Task ExecuteCommandAsync(this DTE dte, string command, string args = "")
        {
            // args is "" the default because it is the default value used by Dte.ExecuteCommand and changing our default
            // to something more logical, like null, would change the expected behavior of Dte.ExecuteCommand

            await dte.WaitForCommandAvailabilityAsync(command).ConfigureAwait(continueOnCapturedContext: false);

            IntegrationHelper.RetryRpcCall(() => dte.ExecuteCommand(command, args));
        }
Example #2
0
        public Project AddProject(string projectName, ProjectTemplate projectTemplate, ProjectLanguage projectLanguage)
        {
            var projectPath         = Path.Combine(DirectoryName, projectName);
            var projectTemplatePath = GetProjectTemplatePath(projectTemplate, projectLanguage);

            var dteProject = IntegrationHelper.RetryRpcCall(() => _dteSolution.AddFromTemplate(projectTemplatePath, projectPath, projectName, Exclusive: false));

            if (dteProject == null)
            {
                dteProject = GetDteProject(projectName);
            }

            return(new Project(dteProject, this, projectLanguage));
        }
Example #3
0
        public Solution OpenSolution(string path, bool saveExistingSolutionIfExists = false)
        {
            var dteSolution = IntegrationHelper.RetryRpcCall(() => _visualStudio.Dte.Solution);

            if (IntegrationHelper.RetryRpcCall(() => dteSolution.IsOpen))
            {
                CloseSolution(saveExistingSolutionIfExists);
            }

            IntegrationHelper.RetryRpcCall(() => dteSolution.Open(path));
            _solution = new Solution((Solution2)(dteSolution), path);

            return(_solution);
        }
Example #4
0
        public static Window LocateWindow(this DTE dte, string windowTitle)
        {
            var dteWindows = IntegrationHelper.RetryRpcCall(() => dte.Windows);

            foreach (Window window in dteWindows)
            {
                var windowCaption = IntegrationHelper.RetryRpcCall(() => window.Caption);

                if (windowCaption.Equals(windowTitle))
                {
                    return(window);
                }
            }
            return(null);
        }
Example #5
0
        private DteProject GetDteProject(string projectName)
        {
            var dteSolutionProjects = IntegrationHelper.RetryRpcCall(() => _dteSolution.Projects);

            foreach (DteProject project in dteSolutionProjects)
            {
                var dteProjectName = IntegrationHelper.RetryRpcCall(() => project.Name);

                if (dteProjectName == projectName)
                {
                    return(project);
                }
            }

            throw new Exception($"The specified project could not be found. Project name: '{projectName}'");
        }
        internal InteractiveWindow(VisualStudioInstance visualStudioInstance, string dteViewCommand, string dteWindowTitle, string createMethodName)
        {
            _visualStudioInstance = visualStudioInstance;
            _dteViewCommand       = dteViewCommand;

            // We have to show the window at least once to ensure the interactive service is loaded.
            ShowAsync(waitForPrompt: false).GetAwaiter().GetResult();

            var dteWindow = IntegrationHelper.WaitForNotNullAsync(() => _visualStudioInstance.Dte.LocateWindow(dteWindowTitle)).GetAwaiter().GetResult();

            IntegrationHelper.RetryRpcCall(() => dteWindow.Close());

            // Return a wrapper to the actual interactive window service that exists in the host process
            var integrationService = _visualStudioInstance.IntegrationService;

            _interactiveWindowWrapper = integrationService.Execute <InteractiveWindowWrapper>(typeof(InteractiveWindowWrapper), createMethodName);
        }
Example #7
0
 private void CloseRemotingService()
 {
     try
     {
         if ((IntegrationHelper.RetryRpcCall(() => _dte?.Commands.Item(VisualStudioCommandNames.VsStopServiceCommand).IsAvailable).GetValueOrDefault()))
         {
             _dte.ExecuteCommandAsync(VisualStudioCommandNames.VsStopServiceCommand).GetAwaiter().GetResult();
         }
     }
     finally
     {
         if (_integrationServiceChannel != null)
         {
             ChannelServices.UnregisterChannel(_integrationServiceChannel);
         }
     }
 }
Example #8
0
        /// <summary>Creates and loads a new solution in the host process, optionally saving the existing solution if one exists.</summary>
        public Solution CreateSolution(string solutionName, bool saveExistingSolutionIfExists = false)
        {
            var dteSolution = IntegrationHelper.RetryRpcCall(() => _visualStudio.Dte.Solution);

            if (IntegrationHelper.RetryRpcCall(() => dteSolution.IsOpen))
            {
                CloseSolution(saveExistingSolutionIfExists);
            }

            var solutionPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            IntegrationHelper.DeleteDirectoryRecursively(solutionPath);

            IntegrationHelper.RetryRpcCall(() => dteSolution.Create(solutionPath, solutionName));
            _solution = new Solution((Solution2)(dteSolution), Path.Combine(solutionPath, $"{solutionName}.sln"));

            return(_solution);
        }
Example #9
0
        private void CleanupOpenSolution()
        {
            IntegrationHelper.RetryRpcCall(() => _dte.Documents.CloseAll(vsSaveChanges.vsSaveChangesNo));

            var dteSolution = IntegrationHelper.RetryRpcCall(() => _dte.Solution);

            if (dteSolution != null)
            {
                var directoriesToDelete = IntegrationHelper.RetryRpcCall(() =>
                {
                    var directoryList = new List <string>();

                    var dteSolutionProjects = IntegrationHelper.RetryRpcCall(() => dteSolution.Projects);

                    // Save the full path to each project in the solution. This is so we can cleanup any folders after the solution is closed.
                    foreach (EnvDTE.Project project in dteSolutionProjects)
                    {
                        var projectFullName = IntegrationHelper.RetryRpcCall(() => project.FullName);
                        directoryList.Add(Path.GetDirectoryName(projectFullName));
                    }

                    // Save the full path to the solution. This is so we can cleanup any folders after the solution is closed.
                    // The solution might be zero-impact and thus has no name, so deal with that
                    var dteSolutionFullName = IntegrationHelper.RetryRpcCall(() => dteSolution.FullName);

                    if (!string.IsNullOrEmpty(dteSolutionFullName))
                    {
                        directoryList.Add(Path.GetDirectoryName(dteSolutionFullName));
                    }

                    return(directoryList);
                });

                IntegrationHelper.RetryRpcCall(() => dteSolution.Close(SaveFirst: false));

                foreach (var directoryToDelete in directoriesToDelete)
                {
                    IntegrationHelper.TryDeleteDirectoryRecursively(directoryToDelete);
                }
            }
        }
Example #10
0
        public void Find(string expectedText)
        {
            Activate();
            ClearTextSelection();

            var dteFind = IntegrationHelper.RetryRpcCall(() => _visualStudioInstance.Dte.Find);

            dteFind.Action            = vsFindAction.vsFindActionFind;
            dteFind.FindWhat          = expectedText;
            dteFind.MatchCase         = true;
            dteFind.MatchInHiddenText = true;
            dteFind.MatchWholeWord    = true;
            dteFind.PatternSyntax     = vsFindPatternSyntax.vsFindPatternSyntaxLiteral;
            dteFind.Target            = vsFindTarget.vsFindTargetCurrentDocument;

            var findResult = IntegrationHelper.RetryRpcCall(() => dteFind.Execute());

            if (findResult != vsFindResult.vsFindResultFound)
            {
                throw new Exception($"The specified text was not found. ExpectedText: '{expectedText}'; ActualText: '{Text}'");
            }
        }
Example #11
0
 public void CloseSolution(bool saveFirst = false) => IntegrationHelper.RetryRpcCall(() => _visualStudio.Dte.Solution.Close(saveFirst));
Example #12
0
        private void CloseHostProcess()
        {
            IntegrationHelper.RetryRpcCall(() => _dte.Quit());

            IntegrationHelper.KillProcess(_hostProcess);
        }
Example #13
0
        private void CleanupInteractiveWindow()
        {
            var csharpInteractiveWindow = _dte.LocateWindow(CSharpInteractiveWindow.DteWindowTitle);

            IntegrationHelper.RetryRpcCall(() => csharpInteractiveWindow?.Close());
        }
Example #14
0
 public void Activate() => IntegrationHelper.RetryRpcCall(() => _visualStudioInstance.Dte.ActiveDocument.Activate());
Example #15
0
 // TODO: Adjust language name based on whether we are using a web template
 private string GetProjectTemplatePath(ProjectTemplate projectTemplate, ProjectLanguage projectLanguage)
 => IntegrationHelper.RetryRpcCall(() => _dteSolution.GetProjectTemplate(_projectTemplates[projectTemplate], ProjectLanguages[projectLanguage]));
Example #16
0
 public void Save()
 {
     Directory.CreateDirectory(DirectoryName);
     IntegrationHelper.RetryRpcCall(() => _dteSolution.SaveAs(FileName));
 }
Example #17
0
 public static Task WaitForCommandAvailabilityAsync(this DTE dte, string command)
 => IntegrationHelper.WaitForResultAsync(() => IntegrationHelper.RetryRpcCall(() => dte.Commands.Item(command).IsAvailable), expectedResult: true);