Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 352 lines (290 sloc) 9.55 kb
4d36eaa add initial gui-compare stuff
Chris Toshok authored
1
2 using System;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.Threading;
6 using System.IO;
7 using System.Xml;
8 using Mono.Cecil;
9 using Gtk;
10
11 namespace GuiCompare {
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
12
13 // A delegate used to load a CompAssembly
14 public delegate CompAssembly LoadCompAssembly ();
15
4d36eaa add initial gui-compare stuff
Chris Toshok authored
16 public class CompareContext
17 {
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
18 LoadCompAssembly reference_loader, target_loader;
19
20 public CompareContext (LoadCompAssembly reference, LoadCompAssembly target)
4d36eaa add initial gui-compare stuff
Chris Toshok authored
21 {
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
22 reference_loader = reference;
23 target_loader = target;
4d36eaa add initial gui-compare stuff
Chris Toshok authored
24 }
25
26 public ComparisonNode Comparison {
27 get { return comparison; }
28 }
29
30 public void Compare ()
31 {
32 if (t != null)
33 throw new InvalidOperationException ("compare already running");
34
35 t = new Thread (CompareThread);
36 t.Start ();
37 }
38
39 public void StopCompare ()
40 {
41 }
42
43 void CompareThread ()
44 {
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
45 ProgressOnGuiThread (Double.NaN, "Loading reference...");
4d36eaa add initial gui-compare stuff
Chris Toshok authored
46
47 try {
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
48 reference = reference_loader ();
4d36eaa add initial gui-compare stuff
Chris Toshok authored
49 }
50 catch (Exception e) {
51 ErrorOnGuiThread (e.ToString());
52 return;
53 }
54
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
55 ProgressOnGuiThread (Double.NaN, "Loading target...");
4d36eaa add initial gui-compare stuff
Chris Toshok authored
56
57 try {
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
58 target = target_loader ();
4d36eaa add initial gui-compare stuff
Chris Toshok authored
59 }
60 catch (Exception e) {
61 ErrorOnGuiThread (e.ToString());
62 return;
63 }
64
65 ProgressOnGuiThread (0.0, "Comparing...");
66
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
67 comparison = target.GetComparisonNode ();
4d36eaa add initial gui-compare stuff
Chris Toshok authored
68
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
69 CompareTypeLists (comparison, reference.GetNamespaces(), target.GetNamespaces());
4d36eaa add initial gui-compare stuff
Chris Toshok authored
70
71 FinishedOnGuiThread ();
72
b5aa04e 2007-12-07 Chris Toshok <toshok@ximian.com>
Chris Toshok authored
73 // DumpComparison (comparison, 0);
4d36eaa add initial gui-compare stuff
Chris Toshok authored
74 }
75
76 char StatusToChar (ComparisonStatus r)
77 {
78 switch (r) {
79 case ComparisonStatus.Missing: return '-';
80 case ComparisonStatus.Extra: return '+';
81 case ComparisonStatus.Todo: return 'o';
82 case ComparisonStatus.Error: return '!';
83 default:
84 case ComparisonStatus.None: return ' ';
85 }
86 }
87
88
89 void DumpComparison (ComparisonNode c, int indent)
90 {
91 for (int i = 0; i < indent; i ++)
92 Console.Write (" ");
93 Console.WriteLine ("{0} {1} {2}", StatusToChar (c.status), c.type, c.name);
94 foreach (ComparisonNode child in c.children) {
95 DumpComparison (child, indent + 2);
96 }
97 }
98
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
99 void CompareNestedTypes (ComparisonNode parent, ICompTypeContainer master_container, ICompTypeContainer assembly_container)
100 {
101 CompareTypeLists (parent,
102 master_container.GetNestedInterfaces(), assembly_container.GetNestedInterfaces());
103 CompareTypeLists (parent,
104 master_container.GetNestedClasses(), assembly_container.GetNestedClasses());
105 CompareTypeLists (parent,
106 master_container.GetNestedStructs(), assembly_container.GetNestedStructs());
107 CompareTypeLists (parent,
108 master_container.GetNestedEnums(), assembly_container.GetNestedEnums());
109 CompareTypeLists (parent,
110 master_container.GetNestedDelegates(), assembly_container.GetNestedDelegates());
111 }
112
113 void CompareTypeLists (ComparisonNode parent,
114 List<CompNamed> master_list,
115 List<CompNamed> assembly_list)
4d36eaa add initial gui-compare stuff
Chris Toshok authored
116 {
117 int m = 0, a = 0;
118
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
119 master_list.Sort (CompNamed.Compare);
120 assembly_list.Sort (CompNamed.Compare);
121
122 while (m < master_list.Count || a < assembly_list.Count) {
123 if (m == master_list.Count) {
124 AddExtra (parent, assembly_list[a]);
4d36eaa add initial gui-compare stuff
Chris Toshok authored
125 a++;
126 continue;
127 }
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
128 else if (a == assembly_list.Count) {
129 AddMissing (parent, master_list[m]);
4d36eaa add initial gui-compare stuff
Chris Toshok authored
130 m++;
131 continue;
132 }
133
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
134 int c = String.Compare (master_list[m].Name, assembly_list[a].Name);
4d36eaa add initial gui-compare stuff
Chris Toshok authored
135
136 if (c == 0) {
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
137 ProgressOnGuiThread (0.0, String.Format ("Comparing {0} {0}", master_list[m].Type, master_list[m].Name));
4d36eaa add initial gui-compare stuff
Chris Toshok authored
138
139 /* the names match, further investigation is required */
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
140 // Console.WriteLine ("{0} {1} is in both, doing more comparisons", master_list[m].Type, master_list[m].Name);
141 ComparisonNode comparison = master_list[m].GetComparisonNode();
4d36eaa add initial gui-compare stuff
Chris Toshok authored
142 parent.AddChild (comparison);
143
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
144 // compare nested types
145 if (master_list[m] is ICompTypeContainer && assembly_list[a] is ICompTypeContainer) {
146 CompareNestedTypes (comparison,
147 (ICompTypeContainer)master_list[m],
148 (ICompTypeContainer)assembly_list[a]);
149 }
150 if (master_list[m] is ICompMemberContainer && assembly_list[a] is ICompMemberContainer) {
151 CompareMembers (comparison,
152 (ICompMemberContainer)master_list[m],
153 (ICompMemberContainer)assembly_list[a]);
154 }
155
156 // XXX compare members
4d36eaa add initial gui-compare stuff
Chris Toshok authored
157 m++;
158 a++;
159 }
160 else if (c < 0) {
161 /* master name is before assembly name, master name is missing from assembly */
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
162 AddMissing (parent, master_list[m]);
4d36eaa add initial gui-compare stuff
Chris Toshok authored
163 m++;
164 }
165 else {
166 /* master name is after assembly name, assembly name is extra */
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
167 AddExtra (parent, assembly_list[a]);
4d36eaa add initial gui-compare stuff
Chris Toshok authored
168 a++;
169 }
170 }
171 }
172
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
173 void CompareMembers (ComparisonNode parent,
174 ICompMemberContainer master_container, ICompMemberContainer assembly_container)
b5aa04e 2007-12-07 Chris Toshok <toshok@ximian.com>
Chris Toshok authored
175 {
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
176 CompareMemberLists (parent,
177 master_container.GetInterfaces(), assembly_container.GetInterfaces());
178 CompareMemberLists (parent,
179 master_container.GetMethods(), assembly_container.GetMethods());
180 CompareMemberLists (parent,
181 master_container.GetProperties(), assembly_container.GetProperties());
182 CompareMemberLists (parent,
183 master_container.GetFields(), assembly_container.GetFields());
184 }
185
186 void CompareMemberLists (ComparisonNode parent,
187 List<CompNamed> master_list,
188 List<CompNamed> assembly_list)
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
189 {
190 int m = 0, a = 0;
191
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
192 master_list.Sort (CompNamed.Compare);
193 assembly_list.Sort (CompNamed.Compare);
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
194
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
195 while (m < master_list.Count || a < assembly_list.Count) {
196 if (m == master_list.Count) {
197 AddExtra (parent, assembly_list[a]);
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
198 a++;
199 continue;
200 }
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
201 else if (a == assembly_list.Count) {
202 AddMissing (parent, master_list[m]);
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
203 m++;
204 continue;
205 }
206
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
207 int c = String.Compare (master_list[m].Name, assembly_list[a].Name);
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
208
209 if (c == 0) {
210 /* the names match, further investigation is required */
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
211 // Console.WriteLine ("method {0} is in both, doing more comparisons", master_list[m].Name);
212 ComparisonNode comparison = master_list[m].GetComparisonNode();
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
213 parent.AddChild (comparison);
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
214 //CompareParameters (comparison, master_list[m], assembly_namespace [assembly_list[a]]);
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
215 m++;
216 a++;
217 }
218 else if (c < 0) {
219 /* master name is before assembly name, master name is missing from assembly */
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
220 AddMissing (parent, master_list[m]);
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
221 m++;
222 }
223 else {
224 /* master name is after assembly name, assembly name is extra */
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
225 AddExtra (parent, assembly_list[a]);
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
226 a++;
227 }
228 }
b5aa04e 2007-12-07 Chris Toshok <toshok@ximian.com>
Chris Toshok authored
229 }
230
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
231 void AddExtra (ComparisonNode parent, CompNamed item)
4d36eaa add initial gui-compare stuff
Chris Toshok authored
232 {
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
233 ComparisonNode node = item.GetComparisonNode ();
234 parent.AddChild (node);
235 node.status = ComparisonStatus.Extra;
236
237 if (item is ICompTypeContainer) {
238 ICompTypeContainer c = (ICompTypeContainer)item;
239 foreach (CompNamed ifc in c.GetNestedInterfaces ())
240 AddExtra (node, ifc);
241 foreach (CompNamed cls in c.GetNestedClasses())
242 AddExtra (node, cls);
243 foreach (CompNamed cls in c.GetNestedStructs())
244 AddExtra (node, cls);
245 foreach (CompNamed en in c.GetNestedEnums())
246 AddExtra (node, en);
4d36eaa add initial gui-compare stuff
Chris Toshok authored
247 }
248 }
249
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
250 void AddMissing (ComparisonNode parent, CompNamed item)
7b0ffca more stuff, including the counts in the treeview.
Chris Toshok authored
251 {
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
252 ComparisonNode node = item.GetComparisonNode ();
253 parent.AddChild (node);
254 node.status = ComparisonStatus.Missing;
255
256 if (item is ICompTypeContainer) {
257 ICompTypeContainer c = (ICompTypeContainer)item;
258
259 foreach (CompNamed ifc in c.GetNestedInterfaces ())
260 AddMissing (node, ifc);
261 foreach (CompNamed cls in c.GetNestedClasses())
262 AddMissing (node, cls);
263 foreach (CompNamed cls in c.GetNestedStructs())
264 AddMissing (node, cls);
265 foreach (CompNamed en in c.GetNestedEnums())
266 AddMissing (node, en);
267 }
4d36eaa add initial gui-compare stuff
Chris Toshok authored
268 }
269
9a8a18e @migueldeicaza * MainWindow.cs: New file, from MonoDevelop, copy mot of the code from
migueldeicaza authored
270 // This is the reference assembly that we will be comparing to.
271 CompAssembly reference;
272
273 // This is the new API.
274 CompAssembly target;
4d36eaa add initial gui-compare stuff
Chris Toshok authored
275
276 void ProgressOnGuiThread (double progress, string message)
277 {
278 Application.Invoke (delegate (object sender, EventArgs e) {
279 if (ProgressChanged != null)
280 ProgressChanged (this, new CompareProgressChangedEventArgs (message, progress));
281 });
282 }
283
284 void ErrorOnGuiThread (string message)
285 {
286 Application.Invoke (delegate (object sender, EventArgs e) {
287 if (Error != null)
288 Error (this, new CompareErrorEventArgs (message));
289 });
290 }
291
292 void FinishedOnGuiThread ()
293 {
294 Application.Invoke (delegate (object sender, EventArgs e) {
295 if (Finished != null)
296 Finished (this, EventArgs.Empty);
297 });
298 }
299
300 public event CompareProgressChangedEventHandler ProgressChanged;
301 public event CompareErrorEventHandler Error;
302 public event EventHandler Finished;
303
304 string masterinfoPath;
305 string assemblyPath;
278bd82 lots of work refactoring and cleaning things up
Chris Toshok authored
306 ComparisonNode comparison;
4d36eaa add initial gui-compare stuff
Chris Toshok authored
307 Thread t;
308 }
309
310
311
312
313
314
315 public delegate void CompareProgressChangedEventHandler (object sender, CompareProgressChangedEventArgs args);
316 public delegate void CompareErrorEventHandler (object sender, CompareErrorEventArgs args);
317
318 public class CompareProgressChangedEventArgs : EventArgs
319 {
320 public CompareProgressChangedEventArgs (string message, double progress)
321 {
322 this.message = message;
323 this.progress = progress;
324 }
325
326 public string Message {
327 get { return message; }
328 }
329
330 public double Progress {
331 get { return progress; }
332 }
333
334 string message;
335 double progress;
336 }
337
338 public class CompareErrorEventArgs : EventArgs
339 {
340 public CompareErrorEventArgs (string message)
341 {
342 this.message = message;
343 }
344
345 public string Message {
346 get { return message; }
347 }
348
349 string message;
350 }
351 }
Something went wrong with that request. Please try again.