-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project.cs
215 lines (187 loc) · 5.67 KB
/
Project.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace DepAnalyzer
{
internal static class ProjectExtentions
{
public static bool AddUnique(this List<Project> projects, Project proj)
{
if (!projects.Has(proj))
{
projects.Add(proj);
return true;
}
return false;
}
public static bool Has(this List<Project> projects, Project proj)
{
return projects.Exists(p => p.Name == proj.Name);
}
}
internal class Project
{
public enum BuildStatus
{
Wait = 0,
Progress = 1,
Success = 2,
Failed = 3
}
public Project(string name, string path, string guid, bool isExternal)
{
Name = name;
GUID = guid;
File = String.IsNullOrEmpty(path) ? null : new FileInfo(path);
IsExternal = isExternal;
Status = BuildStatus.Wait;
Log = String.Empty;
mPreviousLog = String.Empty;
mPreviousLogFormatted = String.Empty;
ClearDepGraph();
}
public string Name { get; set; }
public FileInfo File { get; private set; }
public string GUID { get; private set; }
public bool IsExternal { get; private set; }
private List<string> DepGUIDs { get; set; }
private string mPreviousLog;
private string mPreviousLogFormatted;
public Project Parent
{
get; private set;
}
public List<Project> DepProjects
{
get; private set;
}
public bool HasChildren
{
get { return DepProjects.Count != 0; }
}
public bool HasParent
{
get { return Parent != null; }
}
public List<Project> ProjectTree
{
// Return all dependency projects from tree including current root node (this)
get
{
List<Project> projs = new List<Project>();
projs.Add(this);
foreach (Project depProj in DepProjects)
{
foreach (Project depDepProj in depProj.ProjectTree)
{
projs.AddUnique(depDepProj);
}
}
return projs;
}
}
public List<Project> Parents
{
// Return all dependency parents excluding current node (this)
get
{
List<Project> projs = new List<Project>();
if (HasParent)
{
projs.Add(Parent);
projs.AddRange(Parent.Parents);
}
return projs;
}
}
public event EventHandler StatusChanged;
private BuildStatus mStatus;
public BuildStatus Status
{
get
{
return mStatus;
}
set
{
if (mStatus != value)
{
mStatus = value;
if (StatusChanged != null)
StatusChanged(this, EventArgs.Empty);
}
}
}
public bool IsBuilt
{
get { return Status == BuildStatus.Failed || Status == BuildStatus.Success; }
}
public event EventHandler LogChanged;
public string Log { get; private set; }
public string GetLogFormatted(out string appending)
{
// If not found previous log in current log then reset cache
if (!Log.StartsWith(mPreviousLog))
{
mPreviousLog = String.Empty;
mPreviousLogFormatted = String.Empty;
}
// Find appending text (diff)
string logAdd = Log.Substring(mPreviousLog.Length, Log.Length - mPreviousLog.Length);
// Format appending text
string logAddFormatted = RtfUtils.GetLogFormatted(logAdd);
// Append formatted appending text to previous formatted text and cache results
mPreviousLog = Log;
mPreviousLogFormatted = RtfUtils.MergeRtf(mPreviousLogFormatted, logAddFormatted);
appending = logAddFormatted;
return mPreviousLogFormatted;
}
public bool HasLog
{
get { return !String.IsNullOrEmpty(Log); }
}
public override string ToString()
{
return Name;
}
public void ClearDepGraph()
{
Parent = null;
DepProjects = null;
DepGUIDs = new List<string>();
}
public void AddDepGUID(string depGUID)
{
if (!DepGUIDs.Contains(depGUID))
{
DepGUIDs.Add(depGUID);
}
}
public void ResolveDeps(Dictionary<string, Project> guidTable)
{
DepProjects = new List<Project>();
foreach (string guid in DepGUIDs)
{
Project depProj;
if (guidTable.TryGetValue(guid, out depProj))
{
depProj.Parent = this;
DepProjects.Add(depProj);
}
}
}
public void ClearLog()
{
Log = String.Empty;
}
public void AppendLog(string text)
{
Log += text + "\r\n";
if (LogChanged != null)
LogChanged(this, EventArgs.Empty);
}
}
}