private void ProjectStarted(object sender, ProjectStartedEventArgs e)
        {
            // We only want to register the outermost project build
            if (!DataSource.IsLogging || e.ParentProjectBuildEventContext.ProjectInstanceId != -1)
            {
                return;
            }

            var dimensions = GatherDimensions(e.GlobalProperties);

            var build = new Build(e.ProjectFile, dimensions.ToArray(), e.TargetNames?.Split(';'), _isDesignTime ? BuildType.DesignTimeBuild : BuildType.Build, e.Timestamp);

            _build             = build;
            _projectInstanceId = e.BuildEventContext.ProjectInstanceId;
            DataSource.AddEntry(_build);
        }
Exemple #2
0
        private void AnyEvent(object sender, BuildEventArgs args)
        {
            if (args.BuildEventContext.EvaluationId == BuildEventContext.InvalidEvaluationId)
            {
                return;
            }

            switch (args)
            {
            case ProjectEvaluationStartedEventArgs evaluationStarted:
            {
                if (!DataSource.IsLogging || evaluationStarted.ProjectFile == "(null)")
                {
                    return;
                }

                var logPath      = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.binlog");
                var binaryLogger = new BinaryLogger
                {
                    Parameters            = logPath,
                    Verbosity             = LoggerVerbosity.Diagnostic,
                    CollectProjectImports = BinaryLogger.ProjectImportsCollectionMode.None
                };
                var wrapper = new EventWrapper(binaryLogger);
                var build   = new Build(evaluationStarted.ProjectFile, Array.Empty <string>(), Array.Empty <string>(),
                                        BuildType.Evaluation, args.Timestamp);
                _evaluations[evaluationStarted.BuildEventContext.EvaluationId] = new Evaluation
                {
                    Wrapper = wrapper,
                    Build   = build,
                    LogPath = logPath
                };
                wrapper.RaiseEvent(sender, args);
                DataSource.AddEntry(build);
            }
            break;

            case ProjectEvaluationFinishedEventArgs _:
            {
                if (_evaluations.TryGetValue(args.BuildEventContext.EvaluationId, out var evaluation))
                {
                    evaluation.Build.Finish(true, args.Timestamp);
                    evaluation.Wrapper.RaiseEvent(sender, args);
                    evaluation.Wrapper.BinaryLogger.Shutdown();
                    evaluation.Build.SetLogPath(GetLogPath(evaluation.Build));
                    Copy(evaluation.LogPath, evaluation.Build.LogPath);
                    DataSource.NotifyChange();
                }
            }
            break;

            default:
            {
                if (_evaluations.TryGetValue(args.BuildEventContext.EvaluationId, out var evaluation))
                {
                    evaluation.Wrapper.RaiseEvent(sender, args);
                }
            }
            break;
            }
        }