-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
75 lines (54 loc) · 1.41 KB
/
Program.cs
File metadata and controls
75 lines (54 loc) · 1.41 KB
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
/* Tool to post-process an XML comment file to process the conditional tags.
*
* Author: OrdinaSoft
* Patrick Lanz
* Lausanne
* info@ordinasoft.ch
*
* First version: November 18, 2021
*/
using System.Diagnostics;
using System.Xml.Linq;
// File name
if (args.Length == 0)
{
Console.WriteLine ("You must supply the name of the XML file to process.");
return -1;
}
var fileName = args [0];
// Defined symbols
var symbols = new HashSet <String> ();
for (var i = 1; i < args.Length; i ++)
symbols.Add (args [i]);
// Processes the file
var stopwatch = new Stopwatch ();
stopwatch.Start ();
var nbConditionals = 0;
try
{
var doc = XDocument.Load (fileName, LoadOptions.PreserveWhitespace);
foreach (var elmt in doc.Descendants ("if").ToArray ())
{
nbConditionals ++;
var symbol = (String?) elmt.Attribute ("symbol");
if (symbol is null)
{
Console.WriteLine ("Found <if> without Symbol attribute.");
symbol = String.Empty;
}
if (symbols.Contains (symbol))
elmt.AddAfterSelf (new XElement (elmt).Nodes ());
elmt.Remove ();
}
doc.Save (fileName);
}
catch (Exception ex)
{
Console.WriteLine ("Error during file processing.");
Console.WriteLine (ex.Message);
return -1;
}
stopwatch.Stop ();
// Indicates successful run
Console.WriteLine ($"Successfully processed {nbConditionals} conditions in {stopwatch.Elapsed}.");
return 0;