protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));
            try
            {
                GaugeService.AssertCompatibility();
            }
            catch (GaugeVersionIncompatibleException ex)
            {
                var message = $"{ex.Message}\n{ex.Data["GaugeError"].ToString()}";
                Debug.WriteLine(message);
                throw new InvalidOperationException(message);
            }
            catch (GaugeVersionNotFoundException ex)
            {
                var message = $"{ex.Message}\n{ex.Data["GaugeError"].ToString()}";
                Debug.WriteLine(message);
                throw new InvalidOperationException(message);
            }

            base.Initialize();

            DTE = (DTE)GetService(typeof(DTE));

            RegisterEditorFactory(new GaugeEditorFactory(this));
            var options = GetDialogPage(typeof(GaugeDaemonOptions)) as GaugeDaemonOptions;

            _solutionsEventListener = new SolutionsEventListener(options, this);
        }
        public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
        {
            var project       = pHierarchy.ToProject();
            var slugifiedName = project.SlugifiedName();

            GaugeService.Instance.KillChildProcess(slugifiedName);
            GaugeService.Reset();
            return(VSConstants.S_OK);
        }
        public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
        {
            var project       = pHierarchy.ToProject();
            var slugifiedName = project.SlugifiedName();

            StatusBarLogger.Log($"Clearing Gauge Project Cache: {project.Name}");
            ProjectFactory.Delete(project.SlugifiedName());
            GaugeService.Instance.KillChildProcess(slugifiedName);
            GaugeService.Reset();
            return(VSConstants.S_OK);
        }
Beispiel #4
0
        public void ShouldBeCompatibleWithGaugeMinVersionForVs()
        {
            var curGaugeMinVersion = GaugeService.MinGaugeVersion;
            var json = "{\"version\": \"" + curGaugeMinVersion +
                       "\",\"plugins\": [{\"name\": \"csharp\",\"version\": \"0.9.2\"},{\"name\": \"html-report\",\"version\": \"2.1.0\"}]}";
            var outputStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
            var errorStream  = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));

            var gaugeProcess = A.Fake <IGaugeProcess>();

            A.CallTo(() => gaugeProcess.Start()).Returns(true);
            A.CallTo(() => gaugeProcess.StandardOutput).Returns(new StreamReader(outputStream));
            A.CallTo(() => gaugeProcess.StandardError).Returns(new StreamReader(errorStream));

            Assert.DoesNotThrow(() => GaugeService.AssertCompatibility(gaugeProcess));
        }
Beispiel #5
0
        public void ShouldGetGaugeVersion()
        {
            const string json =
                "{\"version\": \"0.4.0\",\"plugins\": [{\"name\": \"csharp\",\"version\": \"0.7.3\"},{\"name\": \"html-report\",\"version\": \"2.1.0\"}]}";
            var outputStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
            var errorStream  = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));

            var gaugeProcess = A.Fake <IGaugeProcess>();

            A.CallTo(() => gaugeProcess.Start()).Returns(true);
            A.CallTo(() => gaugeProcess.StandardOutput).Returns(new StreamReader(outputStream));
            A.CallTo(() => gaugeProcess.StandardError).Returns(new StreamReader(errorStream));

            var installedGaugeVersion = GaugeService.GetInstalledGaugeVersion(gaugeProcess);

            Assert.AreEqual("0.4.0", installedGaugeVersion.version);
            Assert.AreEqual(2, installedGaugeVersion.plugins.Length);
        }
Beispiel #6
0
        public void ShouldGetGaugeVersionWhenDeprecated()
        {
            var json = string.Concat(
                "[DEPRECATED] This usage will be removed soon. Run `gauge help --legacy` for more info.",
                Environment.NewLine,
                "{\"version\": \"0.4.0\",\"plugins\": [{\"name\": \"csharp\",\"version\": \"0.7.3\"},{\"name\": \"html-report\",\"version\": \"2.1.0\"}]}");
            var outputStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
            var errorStream  = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));

            var gaugeProcess = A.Fake <IGaugeProcess>();

            A.CallTo(() => gaugeProcess.Start()).Returns(true);
            A.CallTo(() => gaugeProcess.StandardOutput).Returns(new StreamReader(outputStream));
            A.CallTo(() => gaugeProcess.StandardError).Returns(new StreamReader(errorStream));

            var installedGaugeVersion = GaugeService.GetInstalledGaugeVersion(gaugeProcess);

            Assert.AreEqual("0.4.0", installedGaugeVersion.version);
            Assert.AreEqual(2, installedGaugeVersion.plugins.Length);
        }
Beispiel #7
0
        public void ShouldThrowExceptionWhenExitCodeIsNonZero()
        {
            const string errorMessage = "This is an error message";
            var          outputStream = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));
            var          errorStream  = new MemoryStream(Encoding.UTF8.GetBytes(errorMessage));

            var gaugeProcess = A.Fake <IGaugeProcess>();

            A.CallTo(() => gaugeProcess.Start()).Returns(true);
            A.CallTo(() => gaugeProcess.ExitCode).Returns(123);
            A.CallTo(() => gaugeProcess.StandardOutput).Returns(new StreamReader(outputStream));
            A.CallTo(() => gaugeProcess.StandardError).Returns(new StreamReader(errorStream));

            var exception =
                Assert.Throws <GaugeVersionNotFoundException>(() =>
                                                              GaugeService.GetInstalledGaugeVersion(gaugeProcess));

            Assert.NotNull(exception);
            Assert.NotNull(exception.Data);
            Assert.AreEqual("Unable to read Gauge version", exception.Message);
            Assert.AreEqual(errorMessage, exception.Data["GaugeError"]);
        }
Beispiel #8
0
        public static IEnumerable <string> GetAllSpecsFromGauge()
        {
            try
            {
                GaugeService.AssertCompatibility();
            }
            catch (GaugeVersionIncompatibleException ex)
            {
                GaugeService.DisplayGaugeNotStartedMessage(GaugeDisplayErrorLevel.Error,
                                                           "Unable to launch Gauge Daemon.\nCheck Gauge output pane for details.", ex.Data["GaugeError"].ToString());
                return(Enumerable.Empty <string>());
            }
            catch (GaugeVersionNotFoundException ex)
            {
                GaugeService.DisplayGaugeNotStartedMessage(GaugeDisplayErrorLevel.Error,
                                                           "Unable to launch Gauge Daemon.\nCheck Gauge output pane for details.", ex.Data["GaugeError"].ToString());
                return(Enumerable.Empty <string>());
            }

            var specifications     = new List <ProtoSpec>();
            var gaugeServiceClient = new GaugeServiceClient();

            try
            {
                foreach (var apiConnection in GaugeService.Instance.GetAllApiConnections())
                {
                    specifications.AddRange(gaugeServiceClient.GetSpecsFromGauge(apiConnection));
                }

                return(specifications.Select(spec => spec.FileName).Distinct());
            }
            catch (GaugeApiInitializationException ex)
            {
                GaugeService.DisplayGaugeNotStartedMessage(GaugeDisplayErrorLevel.Error,
                                                           "Unable to launch Gauge Daemon.\nCheck Gauge output pane for details.", $"STDOUT:\n{ex.Data["STDOUT"]}\nSTDERR:\n{ex.Data["STDERR"]}");
                return(Enumerable.Empty <string>());
            }
        }
Beispiel #9
0
        public void ShouldBeIncompatibleWithOldGaugeVersion()
        {
            const string json =
                "{\"version\": \"0.6.2\",\"plugins\": [{\"name\": \"csharp\",\"version\": \"0.9.2\"},{\"name\": \"html-report\",\"version\": \"2.1.0\"}]}";
            var outputStream       = new MemoryStream(Encoding.UTF8.GetBytes(json));
            var errorStream        = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));
            var curGaugeMinVersion = GaugeService.MinGaugeVersion;
            var expectedMessage    = "This plugin works with Gauge " + curGaugeMinVersion +
                                     " or above. You have Gauge 0.6.2 installed. Please update your Gauge installation.\n" +
                                     " Run 'gauge version' from your command prompt for installation information.";

            var gaugeProcess = A.Fake <IGaugeProcess>();

            A.CallTo(() => gaugeProcess.Start()).Returns(true);
            A.CallTo(() => gaugeProcess.StandardOutput).Returns(new StreamReader(outputStream));
            A.CallTo(() => gaugeProcess.StandardError).Returns(new StreamReader(errorStream));

            var gaugeVersionIncompatibleException =
                Assert.Throws <GaugeVersionIncompatibleException>(() =>
                                                                  GaugeService.AssertCompatibility(gaugeProcess));

            Assert.AreEqual(expectedMessage, gaugeVersionIncompatibleException.Data["GaugeError"]);
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (VsShellUtilities.IsInAutomationFunction(_serviceProvider))
            {
                return(Next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            var hresult = VSConstants.S_OK;

            if ((VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.RENAME)
            {
                GaugePackage.DTE.ExecuteCommand("Build.BuildSolution");
                var caretBufferPosition = _view.Caret.Position.BufferPosition;
                var currentLine         = caretBufferPosition.GetContainingLine();
                var lineText            = currentLine.GetText();
                if (!Parser.StepRegex.IsMatch(lineText))
                {
                    return(hresult);
                }

                var originalText = Step.GetStepText(currentLine);

                var refactorDialog = new RefactorDialog(originalText);
                var showModal      = refactorDialog.ShowModal();
                if (!showModal.HasValue || !showModal.Value)
                {
                    return(hresult);
                }

                var newText         = refactorDialog.StepText;
                var progressDialog  = CreateProgressDialog();
                var startWaitDialog = progressDialog.StartWaitDialogWithPercentageProgress("Gauge - Renaming",
                                                                                           $"Original: {originalText}\nTo: {newText}", "Invoking Refactor action", null,
                                                                                           "Refactoring Step", false, 0, 4, 1);
                if (startWaitDialog != VSConstants.S_OK)
                {
                    return(hresult);
                }

                var undoContext = GaugePackage.DTE.UndoContext;
                undoContext.Open("GaugeRefactoring");
                try
                {
                    var vsProject = _view.TextBuffer.CurrentSnapshot.GetProject(GaugePackage.DTE);
                    var response  = RefactorUsingGaugeDaemon(newText, originalText, vsProject);

                    if (!response.PerformRefactoringResponse.Success)
                    {
                        var errorMessage = string.Empty;
                        if (response.Error != null)
                        {
                            errorMessage = string.Format("{0}\n", response.Error.Error);
                        }
                        if (response.PerformRefactoringResponse != null &&
                            response.PerformRefactoringResponse.Errors.Count > 0)
                        {
                            foreach (var error in response.PerformRefactoringResponse.Errors)
                            {
                                errorMessage = $"{errorMessage}{error}\n";
                            }
                        }
                        GaugeService.DisplayGaugeNotStartedMessage(GaugeDisplayErrorLevel.Warning, "Refactoring failed.\nCheck Gauge output pane for details.", string.Format("Failed to refactor {0} to {1}. Error:\n{2}", originalText, newText,
                                                                                                                                                                              errorMessage));
                        return(VSConstants.S_FALSE);
                    }
                    bool cancel;
                    progressDialog.UpdateProgress(null, "Reloading changed files..", null, 2, 4, true, out cancel);
                    ReloadChangedDocuments(response);
                    progressDialog.UpdateProgress(null, "Building Solution..", null, 3, 4, true, out cancel);
                    GaugePackage.DTE.ExecuteCommand("Build.BuildSolution");
                    progressDialog.UpdateProgress(null, "Refreshing Cache..", null, 3, 4, true, out cancel);
                }
                finally
                {
                    int cancelled;
                    progressDialog.EndWaitDialog(out cancelled);
                    undoContext.Close();
                }
                return(hresult);
            }
            hresult = Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            return(hresult);
        }