Пример #1
0
 public void WriteLinePrefix(BuildEventContext e, DateTime eventTimeStamp, bool isMessagePrefix)
 {
     WriteLinePrefix(_context.GetFullProjectKey(e).ToString(_context.Verbosity), eventTimeStamp, isMessagePrefix);
 }
        public void Handle(ProjectFinishedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            var projectStartedEvent = _buildEventManager.GetProjectStartedEvent(e.BuildEventContext);

            // ReSharper disable once LocalizableElement
            if (projectStartedEvent == null)
            {
                throw new ArgumentException($"Project finished event for {e.ProjectFile} received without matching start event", nameof(e));
            }
            if (_context.Parameters.ShowPerfSummary)
            {
                _performanceCounterFactory.GetOrCreatePerformanceCounter(e.ProjectFile, _context.ProjectPerformanceCounters).AddEventFinished(projectStartedEvent.TargetNames, e.BuildEventContext, e.Timestamp);
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Normal) && projectStartedEvent.ShowProjectFinishedEvent)
            {
                _context.LastProjectFullKey = _context.GetFullProjectKey(e.BuildEventContext);
                if (!_context.Parameters.ShowOnlyErrors && !_context.Parameters.ShowOnlyWarnings)
                {
                    _messageWriter.WriteLinePrefix(e.BuildEventContext, e.Timestamp, false);
                    _logWriter.SetColor(Color.BuildStage);
                    var targetNames = projectStartedEvent.TargetNames;
                    var projectFile = projectStartedEvent.ProjectFile ?? string.Empty;
                    if (string.IsNullOrEmpty(targetNames))
                    {
                        if (e.Succeeded)
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectFinishedPrefixWithDefaultTargetsMultiProc", projectFile), true);
                            _hierarchicalMessageWriter.FinishBlock();
                        }
                        else
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectFinishedPrefixWithDefaultTargetsMultiProcFailed", projectFile), true);
                            _hierarchicalMessageWriter.FinishBlock();
                        }
                    }
                    else
                    {
                        if (e.Succeeded)
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectFinishedPrefixWithTargetNamesMultiProc", projectFile, targetNames), true);
                            _hierarchicalMessageWriter.FinishBlock();
                        }
                        else
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectFinishedPrefixWithTargetNamesMultiProcFailed", projectFile, targetNames), true);
                            _hierarchicalMessageWriter.FinishBlock();
                        }
                    }
                }

                _deferredMessageWriter.ShownBuildEventContext(projectStartedEvent.ProjectBuildEventContext);
                _logWriter.ResetColor();
            }

            _buildEventManager.RemoveProjectStartedEvent(e.BuildEventContext);
        }
        public void Handle(TargetFinishedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.BuildEventContext == null)
            {
                throw new ArgumentException(nameof(e));
            }
            if (_context.Parameters.ShowPerfSummary)
            {
                _performanceCounterFactory.GetOrCreatePerformanceCounter(e.TargetName, _context.TargetPerformanceCounters).AddEventFinished(null, e.BuildEventContext, e.Timestamp);
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Detailed))
            {
                _deferredMessageWriter.DisplayDeferredTargetStartedEvent(e.BuildEventContext);
                var targetStartedEvent = _buildEventManager.GetTargetStartedEvent(e.BuildEventContext);
                // ReSharper disable once NotResolvedInText
                if (targetStartedEvent == null)
                {
                    throw new ArgumentNullException("Started event should not be null in the finished event handler");
                }
                if (targetStartedEvent.ShowTargetFinishedEvent)
                {
                    if (_context.Parameters.ShowTargetOutputs)
                    {
                        var targetOutputs = e.TargetOutputs;
                        if (targetOutputs != null)
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetOutputItemsHeader"), false);
                            foreach (ITaskItem taskItem in targetOutputs)
                            {
                                _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetOutputItem", taskItem.ItemSpec), false);
                                foreach (DictionaryEntry dictionaryEntry in taskItem.CloneCustomMetadata())
                                {
                                    _messageWriter.WriteMessageAligned(new string(' ', 8) + dictionaryEntry.Key + " = " + taskItem.GetMetadata((string)dictionaryEntry.Key), false);
                                }
                            }
                        }
                    }

                    if (!_context.Parameters.ShowOnlyErrors && !_context.Parameters.ShowOnlyWarnings)
                    {
                        _context.LastProjectFullKey = _context.GetFullProjectKey(e.BuildEventContext);
                        _messageWriter.WriteLinePrefix(e.BuildEventContext, e.Timestamp, false);
                        _logWriter.SetColor(Color.BuildStage);
                        if (_context.IsVerbosityAtLeast(LoggerVerbosity.Diagnostic) || (_context.Parameters.ShowEventId ?? false))
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetMessageWithId", (object)e.Message, (object)e.BuildEventContext.TargetId), true);
                        }
                        else
                        {
                            _messageWriter.WriteMessageAligned(e.Message, true);
                        }

                        _logWriter.ResetColor();
                    }

                    _deferredMessageWriter.ShownBuildEventContext(e.BuildEventContext);
                    _hierarchicalMessageWriter.FinishBlock();
                }
            }

            _buildEventManager.RemoveTargetStartedEvent(e.BuildEventContext);
        }