public bool ParseAndCollectErrors(string featureFileContent, IDeveroomLogger logger, out DeveroomGherkinDocument gherkinDocument, out List <ParserException> parserErrors)
        {
            var reader = new StringReader(featureFileContent);

            gherkinDocument = null;
            parserErrors    = new List <ParserException>();
            try
            {
                gherkinDocument = Parse(reader, "foo.feature"); //TODO: remove unused path
                return(true);
            }
            catch (ParserException parserException)
            {
                logger.LogVerbose($"ParserErrors: {parserException.Message}");
                gherkinDocument = GetResultOfInvalid();
                if (parserException is CompositeParserException compositeParserException)
                {
                    parserErrors.AddRange(compositeParserException.Errors);
                }
                else
                {
                    parserErrors.Add(parserException);
                }
            }
            catch (Exception e)
            {
                logger.LogException(_monitoringService, e, "Exception during Gherkin parsing");
                gherkinDocument = GetResult();
            }
            return(false);
        }
示例#2
0
        private string GetSpecFlowToolsFolderSafe(ProjectSettings projectSettings)
        {
            try
            {
                if (projectSettings.SpecFlowPackage.InstallPath == null)
                {
                    throw new InvalidOperationException("Unable to generate feature-file code behind, the SpecFlow NuGet package folder could not be detected.");
                }

                var specFlowToolsFolder = Path.Combine(projectSettings.SpecFlowPackage.InstallPath, "tools");
                if (!_projectScope.IdeScope.FileSystem.Directory.Exists(specFlowToolsFolder))
                {
                    _projectScope.IdeScope.Actions.ShowProblem($"Unable to find SpecFlow tools folder: '{specFlowToolsFolder}'. Build solution to ensure that all packages are restored. The feature file has to be re-generated (e.g. by saving) after the packages have been restored.");
                }
                return(specFlowToolsFolder);
            }
            catch (Exception ex)
            {
                _logger.LogException(MonitoringService, ex);
                return(null);
            }
        }
        public GenerationResult GenerateFeatureFile(string featureFilePath, string targetExtension, string targetNamespace)
        {
            var projectSettings     = _projectScope.GetProjectSettings();
            var specFlowToolsFolder = GetSpecFlowToolsFolderSafe(_projectScope, projectSettings, out var toolsFolderErrorMessage);

            if (specFlowToolsFolder == null)
            {
                return(CreateErrorResult(featureFilePath, $"Unable to use SpecFlow tools folder '{projectSettings.SpecFlowGeneratorFolder}': {toolsFolderErrorMessage}"));
            }

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                var connector = OutProcSpecFlowConnectorFactory.Create(_projectScope);

                var result = connector.RunGenerator(featureFilePath, projectSettings.SpecFlowConfigFilePath,
                                                    targetExtension, targetNamespace, _projectScope.ProjectFolder, specFlowToolsFolder);

                _projectScope.IdeScope.MonitoringService.MonitorSpecFlowGeneration(result.IsFailed, projectSettings);

                if (result.IsFailed)
                {
                    _logger.LogWarning(result.ErrorMessage);
                    SetErrorContent(featureFilePath, result);
                    _logger.LogVerbose(() => result.FeatureFileCodeBehind.Content);
                }
                else
                {
                    _logger.LogInfo($"code-behind file generated for file {featureFilePath} in project {_projectScope.ProjectName}");
                    _logger.LogVerbose(() => result.FeatureFileCodeBehind.Content.Substring(0, Math.Min(450, result.FeatureFileCodeBehind.Content.Length)));
                }

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogException(MonitoringService, ex);
                return(CreateErrorResult(featureFilePath, ex.Message));
            }
            finally
            {
                stopwatch.Stop();
                _logger.LogVerbose($"Generation: {stopwatch.ElapsedMilliseconds} ms");
            }
        }
 private void DispatcherTick(object sender, EventArgs e)
 {
     try
     {
         _dispatcherTimer.Stop();
         bool doContinue = _action();
         if (doContinue)
         {
             _dispatcherTimer.Start();
         }
     }
     catch (Exception ex)
     {
         _logger?.LogException(_monitoringService, ex);
         if (_logger == null)
         {
             MessageBox.Show("Unhandled exception: " + ex, "Deveroom error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
        public ICollection <DeveroomTag> Parse(ITextSnapshot fileSnapshot, ProjectBindingRegistry bindingRegistry, DeveroomConfiguration configuration)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                return(ParseInternal(fileSnapshot, bindingRegistry, configuration));
            }
            catch (Exception ex)
            {
                _logger.LogException(_monitoringService, ex, "Unhandled parsing error");
                return(new List <DeveroomTag>());
            }
            finally
            {
                stopwatch.Stop();
                _logger.LogVerbose($"Parsed buffer v{fileSnapshot.Version.VersionNumber} in {stopwatch.ElapsedMilliseconds}ms on thread {Thread.CurrentThread.ManagedThreadId}");
            }
        }