public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
        {
            var project = pHierarchy.ToProject();

            if (!project.IsGaugeProject())
            {
                return(VSConstants.S_OK);
            }

            var slugifiedName = project.SlugifiedName();

            if (GaugeService.Instance.ContainsApiConnectionFor(slugifiedName))
            {
                return(VSConstants.S_OK);
            }

            try
            {
                StatusBarLogger.Log($"Initializing Gauge daemon for Project: {project.Name}");
                GaugeService.Instance.RegisterGaugeProject(project, _gaugeDaemonOptions.MinPortRange,
                                                           _gaugeDaemonOptions.MaxPortRange);
                StatusBarLogger.Log($"Initializing Gauge Project Cache: {project.Name}");
                ProjectFactory.Initialize(project);
            }
            catch (Exception ex)
            {
                OutputPaneLogger.Error($"Failed to start Gauge Daemon: {ex}");
                return(VSConstants.S_FALSE);
            }

            return(VSConstants.S_OK);
        }
Example #2
0
        public IEnumerable <Concept> GetAllConcepts()
        {
            if (_project == null)
            {
                OutputPaneLogger.Error("Error occurred GetAllConcepts: _project is null");
                return(Enumerable.Empty <Concept>());
            }
            var gaugeApiConnection = GaugeService.Instance.GetApiConnectionFor(_project);

            if (gaugeApiConnection == null)
            {
                OutputPaneLogger.Error("Error occurred GetAllConcepts: apiConnection is null");
                return(Enumerable.Empty <Concept>());
            }
            var conceptsRequest = new GetAllConceptsRequest();
            var apiMessage      = new APIMessage
            {
                MessageId          = GenerateMessageId(),
                MessageType        = APIMessage.Types.APIMessageType.GetAllConceptsRequest,
                AllConceptsRequest = conceptsRequest
            };

            var bytes = gaugeApiConnection.WriteAndReadApiMessage(apiMessage);

            return(bytes.AllConceptsResponse.Concepts.Select(info => new Concept(_project)
            {
                StepText = info.StepValue.ParameterizedStepValue,
                StepValue = info.StepValue.StepValue,
                FilePath = info.Filepath,
                LineNumber = info.LineNumber
            }));
        }
Example #3
0
        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));
            }

            if ((VSConstants.VSStd2KCmdID)nCmdID != VSConstants.VSStd2KCmdID.FORMATDOCUMENT)
            {
                return(Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            var gaugeFile = new FileInfo(GaugePackage.DTE.ActiveDocument.FullName);

            var p = GaugeProcess.ForFormat(gaugeFile.DirectoryName, gaugeFile.Name);

            p.Start();
            p.WaitForExit();
            if (p.ExitCode != 0)
            {
                OutputPaneLogger.Error($"gauge format {gaugeFile.Name}\nSTDOUT:\n{p.StandardOutput.ReadToEnd()}\nSTDERR:\n{p.StandardError.ReadToEnd()}\n");
            }
            return(VSConstants.S_OK);
        }
        private IGaugeApiConnection StartGaugeAsDaemon(Project gaugeProject, int minPortRange, int maxPortRange)
        {
            var slugifiedName = gaugeProject.SlugifiedName();

            if (ChildProcesses.ContainsKey(slugifiedName))
            {
                if (ChildProcesses[slugifiedName].HasExited)
                {
                    KillChildProcess(slugifiedName);
                }
                else
                {
                    return(ApiConnections[slugifiedName]);
                }
            }
            var projectOutputPath = GetValidProjectOutputPath(gaugeProject);

            var port = GetOpenPort(minPortRange, maxPortRange);

            OutputPaneLogger.Debug("Opening Gauge Daemon for Project : {0},  at port: {1}", gaugeProject.Name, port);

            var environmentVariables = new Dictionary <string, string>
            {
                { "GAUGE_API_PORT", port.ToString(CultureInfo.InvariantCulture) },
                { "gauge_custom_build_path", projectOutputPath }
            };
            var gaugeProcess = GaugeProcess.ForDaemon(GetProjectRoot(gaugeProject), environmentVariables);

            gaugeProcess.Exited += (s, e) =>
                                   OutputPaneLogger.Error(
                $"PID {gaugeProcess.Id} has exited with exit code {gaugeProcess.ExitCode}.\nSTDOUT:\n{gaugeProcess.StandardOutput.ReadToEnd()}\nSTDERR\n{gaugeProcess.StandardError.ReadToEnd()}");

            gaugeProcess.OutputDataReceived += (sender, args) =>
            {
                if (args.Data.StartsWith("Gauge daemon initialized"))
                {
                    _initialized = true;
                }
            };

            if (!gaugeProcess.Start())
            {
                throw new GaugeApiInitializationException(gaugeProcess.StandardOutput.ReadToEnd(),
                                                          gaugeProcess.StandardError.ReadToEnd());
            }

            gaugeProcess.BeginOutputReadLine();
            OutputPaneLogger.Debug("Opening Gauge Daemon with PID: {0}", gaugeProcess.Id);

            WaitForColdStart();
            var tcpClientWrapper = new TcpClientWrapper(port);

            ApiPorts.Add(slugifiedName, port);
            ChildProcesses.Add(slugifiedName, gaugeProcess.BaseProcess);
            OutputPaneLogger.Debug("PID: {0} ready, waiting for messages..", gaugeProcess.Id);
            return(new GaugeApiConnection(tcpClientWrapper));
        }
        private static string GetValidProjectOutputPath(Project gaugeProject)
        {
            var projectOutputPath = gaugeProject.GetProjectOutputPath();

            if (string.IsNullOrEmpty(projectOutputPath))
            {
                OutputPaneLogger.Error(
                    "Unable to retrieve Project Output path for Project : {0}. Not starting Gauge Daemon",
                    gaugeProject.Name);
                throw new GaugeApiInitializationException("",
                                                          $"Unable to retrieve Project Output path for Project : {gaugeProject.Name}");
            }

            if (Directory.Exists(projectOutputPath))
            {
                return(projectOutputPath);
            }

            OutputPaneLogger.Error("Project Output path '{0}' does not exists. Not starting Gauge Daemon",
                                   projectOutputPath);
            throw new GaugeApiInitializationException("", $"Project Output path '{projectOutputPath}' does not exists");
        }
        public static void DisplayGaugeNotStartedMessage(GaugeDisplayErrorLevel errorLevel, string dialogMessage,
                                                         string errorMessageFormat, params object[] args)
        {
            var uiShell = (IVsUIShell)Package.GetGlobalService(typeof(IVsUIShell));
            var clsId   = Guid.Empty;
            var result  = 0;

            OutputPaneLogger.Error(string.Format(errorMessageFormat, args));
            OLEMSGICON msgicon;

            switch (errorLevel)
            {
            case GaugeDisplayErrorLevel.Info:
                msgicon = OLEMSGICON.OLEMSGICON_INFO;
                break;

            case GaugeDisplayErrorLevel.Warning:
                msgicon = OLEMSGICON.OLEMSGICON_WARNING;
                break;

            case GaugeDisplayErrorLevel.Error:
                msgicon = OLEMSGICON.OLEMSGICON_CRITICAL;
                break;

            default:
                msgicon = OLEMSGICON.OLEMSGICON_NOICON;
                break;
            }
            uiShell.ShowMessageBox(0, ref clsId,
                                   "Gauge - Error Occurred",
                                   dialogMessage,
                                   string.Empty,
                                   0,
                                   OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                   OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                   msgicon,
                                   0, out result
                                   );
        }
Example #7
0
        public UDNParsingResults(string path, ITextSnapshot snapshot, MarkdownPackage package, Markdown markdown, FolderDetails folderDetails)
        {
            var log = new OutputPaneLogger();

            ParsedSnapshot = snapshot;

            // Use the Publish Flag combo box to set the markdown details.
            markdown.PublishFlags.Clear();

            // Always include public
            markdown.PublishFlags.Add(Settings.Default.PublicAvailabilitiesString);

            foreach (var flagName in package.PublishFlags)
            {
                markdown.PublishFlags.Add(flagName);
            }

            Errors      = new List <ErrorDetail>();
            Images      = new List <ImageConversion>();
            Attachments = new List <AttachmentConversionDetail>();

            Document = markdown.ParseDocument(ParsedSnapshot.GetText(), Errors, Images, Attachments, folderDetails);

            DoxygenHelper.SetTrackedSymbols(Document.TransformationData.FoundDoxygenSymbols);

            CommonUnrealFunctions.CopyDocumentsImagesAndAttachments(
                path, log, folderDetails.AbsoluteHTMLPath, folderDetails.Language,
                folderDetails.CurrentFolderFromMarkdownAsTopLeaf, Images, Attachments);

            // Create common directories like css includes top level images etc.
            // Needs to be created everytime the document is generated to allow
            // changes to these files to show in the preview window without
            // restarting VS.
            CommonUnrealFunctions.CreateCommonDirectories(
                folderDetails.AbsoluteHTMLPath, folderDetails.AbsoluteMarkdownPath, log);
        }