Use TupleIdIsPrimaryKey to filter out the first column. Update the column name to Ref when appropriate. Use the TableDefinitions from the TableDefinition.cs generation.
Use TupleIdIsPrimaryKey to filter out the first column. Update the column name to Ref when appropriate. Use the TableDefinitions from the TableDefinition.cs generation.
Sean Hall committed
Apr 5, 2020 at 20:56 UTC
3a63c9ef430bd587302a7cd9dbe217d4d19f8810
1 file changed
+22
-15
src/TablesAndTuples/Program.cs
+22
-15
@@ -11,12 +11,6 @@ namespace TablesAndTuples
11
{
12
class Program
13
{
14
- static readonly XNamespace ns = "http://wixtoolset.org/schemas/v4/wi/tables";
15
- static readonly XName TableDefinition = ns + "tableDefinition";
16
- static readonly XName ColumnDefinition = ns + "columnDefinition";
17
- static readonly XName Name = "name";
18
- static readonly XName Type = "type";
19
-
14
static void Main(string[] args)
15
{
16
if (args.Length == 0)
@@ -65,22 +59,34 @@ namespace TablesAndTuples
59
60
private static void ReadXmlWriteJson(string inputPath, string outputPath, string csOutputPath, string prefix)
61
{
68
- ReadXmlWriteCs(inputPath, csOutputPath, prefix);
69
-
70
- var doc = XDocument.Load(inputPath);
62
+ var tableDefinitions = ReadXmlWriteCs(inputPath, csOutputPath, prefix);
63
64
var array = new JsonArray();
65
74
- foreach (var tableDefinition in doc.Descendants(TableDefinition))
66
+ foreach (var tableDefinition in tableDefinitions)
67
{
76
- var tupleType = tableDefinition.Attribute(Name).Value;
68
+ var tupleType = tableDefinition.Name;
69
70
var fields = new JsonArray();
71
+ var firstField = true;
72
80
- foreach (var columnDefinition in tableDefinition.Elements(ColumnDefinition))
73
+ foreach (var columnDefinition in tableDefinition.Columns)
74
{
82
- var fieldName = columnDefinition.Attribute(Name).Value;
83
- var type = columnDefinition.Attribute(Type).Value;
75
+ if (firstField)
76
+ {
77
+ firstField = false;
78
+ if (tableDefinition.TupleIdIsPrimaryKey)
79
+ {
80
+ continue;
81
+ }
82
+ }
83
+
84
+ var fieldName = columnDefinition.Name;
85
+ fieldName = Regex.Replace(fieldName, "^([^_]+)_([^_]*)$", x =>
86
+ {
87
+ return $"{x.Groups[2].Value}{x.Groups[1].Value}Ref";
88
+ });
89
+ var type = columnDefinition.Type.ToString().ToLower();
90
91
if (type == "localized")
92
{
@@ -115,12 +121,13 @@ namespace TablesAndTuples
121
File.WriteAllText(outputPath, json);
122
}
123
118
- private static void ReadXmlWriteCs(string inputPath, string outputPath, string prefix)
124
+ private static List<WixTableDefinition> ReadXmlWriteCs(string inputPath, string outputPath, string prefix)
125
{
126
var tableDefinitions = WixTableDefinition.LoadCollection(inputPath);
127
var text = GenerateCsTableDefinitionsFileText(prefix, tableDefinitions);
128
Console.WriteLine("Writing: {0}", outputPath);
129
File.WriteAllText(outputPath, text);
130
+ return tableDefinitions;
131
}
132
133
private static void ReadJsonWriteCs(string inputPath, string outputFolder, string prefix)