Exemple #1
0
        private bool NavigateToErrorItem(ErrorItem errorItem)
        {
            if (string.IsNullOrEmpty(errorItem?.File) || string.IsNullOrEmpty(errorItem?.ProjectFile))
            {
                return(false);
            }

            try
            {
                var projectItem = _viewModel.ProjectsList.FirstOrDefault(x => x.FullName == errorItem.ProjectFile);
                if (projectItem == null)
                {
                    return(false);
                }


                var project = _dte.Solution.GetProject(x => x.UniqueName == projectItem.UniqueName);
                if (project == null)
                {
                    return(false);
                }

                return(project.NavigateToErrorItem(errorItem));
            }
            catch (Exception ex)
            {
                ex.Trace("Navigate to error item exception");
                return(true);
            }
        }
Exemple #2
0
        private void BuildOutputLogger_OnErrorRaised(BuildProjectContextEntry projectEntry, object e, ErrorLevel errorLevel)
        {
            try
            {
                var projectItem = projectEntry.ProjectItem;
                if (projectItem == null)
                {
                    if (!TryGetProjectItem(projectEntry, out projectItem))
                    {
                        projectEntry.IsInvalid = true;
                        return;
                    }
                }

                var errorItem = new ErrorItem(errorLevel);
                switch (errorLevel)
                {
                case ErrorLevel.Message:
                    errorItem.Init((BuildMessageEventArgs)e);
                    break;

                case ErrorLevel.Warning:
                    errorItem.Init((BuildWarningEventArgs)e);
                    break;

                case ErrorLevel.Error:
                    errorItem.Init((BuildErrorEventArgs)e);
                    break;

                default:
                    break;
                }

                errorItem.VerifyValues();
                projectItem.AddErrorItem(errorItem);

                var  args            = new BuildErrorRaisedEventArgs(errorLevel, projectItem);
                bool buildNeedCancel = (args.ErrorLevel == ErrorLevel.Error && _packageSettingsProvider.Settings.GeneralSettings.StopBuildAfterFirstError);
                if (buildNeedCancel)
                {
                    _buildService.CancelBuildSolution();
                }

                bool navigateToBuildFailure = (args.ErrorLevel == ErrorLevel.Error && _packageSettingsProvider.Settings.GeneralSettings.NavigateToBuildFailureReason == NavigateToBuildFailureReasonCondition.OnErrorRaised);
                if (navigateToBuildFailure && !ErrorNavigationService.BuildErrorNavigated)
                {
                    _errorNavigationService.NavigateToErrorItem(errorItem);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Failed to fetch errormessage.");
            }
        }
 private void Init(ErrorItem item, BuildMessageEventArgs e)
 {
     item.Code            = e.Code;
     item.File            = e.File;
     item.ProjectFile     = e.ProjectFile;
     item.LineNumber      = e.LineNumber;
     item.ColumnNumber    = e.ColumnNumber;
     item.EndLineNumber   = e.EndLineNumber;
     item.EndColumnNumber = e.EndColumnNumber;
     item.Subcategory     = e.Subcategory;
     item.Message         = e.Message;
 }
Exemple #4
0
        /// <summary>
        /// Navigate to the Error Item in the Visual Studio Editor.
        /// </summary>
        /// <param name="project">The project - owner of the Error Item.</param>
        /// <param name="errorItem">The Error Item.</param>
        public static bool NavigateToErrorItem(this Project project, BuildVision.Contracts.ErrorItem errorItem)
        {
            try
            {
                if (project == null)
                {
                    throw new ArgumentNullException("project");
                }

                if (errorItem == null)
                {
                    throw new ArgumentNullException("errorItem");
                }

                if (!errorItem.CanNavigateTo)
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(errorItem.File))
                {
                    return(false);
                }

                string fullPath;

                // Check if path is absolute.
                if (Path.IsPathRooted(errorItem.File))
                {
                    // Foo VC++ projects errorItem.File contains full path.
                    fullPath = errorItem.File;
                }
                else
                {
                    var projectItemFile = project.FindProjectItem(errorItem.File);
                    if (projectItemFile == null)
                    {
                        return(false);
                    }

                    fullPath = projectItemFile.Properties.GetPropertyOrDefault <string>("FullPath");
                    if (fullPath == null)
                    {
                        throw new KeyNotFoundException("FullPath property not found.");
                    }
                }

                try
                {
                    var window = project.DTE.ItemOperations.OpenFile(fullPath, EnvDTE.Constants.vsViewKindAny);
                    if (window == null)
                    {
                        throw new NullReferenceException("Associated window is null reference.");
                    }

                    window.Activate();

                    var selection = (TextSelection)window.Selection;
                    selection.MoveToLineAndOffset(errorItem.LineNumber, errorItem.ColumnNumber);
                    selection.MoveToLineAndOffset(errorItem.EndLineNumber, errorItem.EndColumnNumber, true /*select text*/);
                }
                catch (Exception ex)
                {
                    var msg = string.Format("Navigate to error item exception (fullPath='{0}').", fullPath);
                    ex.Trace(msg);
                }
            }
            catch (Exception ex)
            {
                ex.Trace("Navigate to error item exception.");
            }

            return(true);
        }
        private void EventSource_ErrorRaised(BuildOutputLogger loggerSender, LazyFormattedBuildEventArgs e, ErrorLevel errorLevel)
        {
            try
            {
                bool verified = VerifyLoggerBuildEvent(loggerSender, e, errorLevel);
                if (!verified)
                {
                    return;
                }

                int projectInstanceId = e.BuildEventContext.ProjectInstanceId;
                int projectContextId  = e.BuildEventContext.ProjectContextId;

                var projectEntry = loggerSender.Projects.Find(t => t.InstanceId == projectInstanceId && t.ContextId == projectContextId);
                if (projectEntry == null)
                {
                    TraceManager.Trace(string.Format("Project entry not found by ProjectInstanceId='{0}' and ProjectContextId='{1}'.", projectInstanceId, projectContextId), EventLogEntryType.Warning);
                    return;
                }
                if (projectEntry.IsInvalid)
                {
                    return;
                }

                if (!GetProjectItem(projectEntry, out var projectItem))
                {
                    projectEntry.IsInvalid = true;
                    return;
                }

                BuildedProject buildedProject = BuildedProjects[projectItem];
                var            errorItem      = new ErrorItem(errorLevel, (eI) =>
                {
                    _packageContext.GetDTE().Solution.GetProject(x => x.UniqueName == projectItem.UniqueName).NavigateToErrorItem(eI);
                });

                switch (errorLevel)
                {
                case ErrorLevel.Message:
                    Init(errorItem, (BuildMessageEventArgs)e);
                    break;

                case ErrorLevel.Warning:
                    Init(errorItem, (BuildWarningEventArgs)e);
                    break;

                case ErrorLevel.Error:
                    Init(errorItem, (BuildErrorEventArgs)e);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("errorLevel");
                }
                errorItem.VerifyValues();
                buildedProject.ErrorsBox.Add(errorItem);
                OnErrorRaised(this, new BuildErrorRaisedEventArgs(errorLevel, buildedProject));
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
            }
        }