-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugLogger.cs
105 lines (96 loc) · 3.41 KB
/
DebugLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using Microsoft.Build.Framework;
using System;
namespace MsBuildDebugger
{
public class DebugLogger : ILogger
{
public LoggerVerbosity Verbosity { get; set; }
public string Parameters { get; set; }
private IEventSource3 source;
private Debugger debugger;
public void Initialize(IEventSource eventSource)
{
source = eventSource as IEventSource3;
//source.ProjectStarted += OnProjectStarted;
//source.ProjectFinished += OnProjectFinished;
//source.BuildStarted += OnBuildStarted;
//source.BuildFinished += OnBuildFinished;
source.AnyEventRaised += OnAnyEvent;
}
public void Shutdown()
{
if (source != null)
{
source.ProjectStarted -= OnProjectStarted;
source.ProjectFinished -= OnProjectFinished;
source.BuildStarted -= OnBuildStarted;
source.BuildFinished -= OnBuildFinished;
source.AnyEventRaised -= OnAnyEvent;
}
}
private void OnAnyEvent(object sender, BuildEventArgs args)
{
if (args is TargetStartedEventArgs targetStartedArgs)
{
debugger.OnTargetEnter(targetStartedArgs.TargetName);
}
else if (args is TargetFinishedEventArgs targetFinishedArgs)
{
debugger.OnTargetLeave(targetFinishedArgs.TargetName);
}
else if (args is BuildMessageEventArgs)
{
//Console.WriteLine("Message: " + ((BuildMessageEventArgs)args).Message);
}
else if (args is TaskStartedEventArgs)
{
// Nothing to do
}
else if (args is TaskFinishedEventArgs)
{
// Nothing to do
}
else if (args is BuildStartedEventArgs buildStartedArgs)
{
OnBuildStarted(sender, buildStartedArgs);
}
else if (args is BuildFinishedEventArgs buildFinishedArgs)
{
OnBuildFinished(sender, buildFinishedArgs);
}
else if (args is ProjectEvaluationStartedEventArgs)
{
// Nothing to do
}
else if (args is ProjectEvaluationFinishedEventArgs)
{
// Nothing to do
}
else if (args is ProjectStartedEventArgs projectStartedArgs)
{
OnProjectStarted(sender, projectStartedArgs);
}
else if (args is ProjectFinishedEventArgs projectFinishedArgs)
{
OnProjectFinished(sender, projectFinishedArgs);
}
else
{
Console.WriteLine("Unknown event: " + args.GetType().Name);
}
}
private void OnProjectStarted(object sender, ProjectStartedEventArgs args) {
debugger = new Debugger(args.ProjectFile, Helper.SplitValue(args.TargetNames));
debugger.SetUI(new ConsoleUI(debugger));
}
private void OnProjectFinished(object sender, ProjectFinishedEventArgs args)
{
}
private void OnBuildStarted(object sender, BuildStartedEventArgs args)
{
}
private void OnBuildFinished(object sender, BuildFinishedEventArgs args)
{
}
}
}