diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/TablesAndTuples/Program.cs | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/TablesAndTuples/Program.cs b/src/TablesAndTuples/Program.cs index bcec604c..cb0f70ea 100644 --- a/src/TablesAndTuples/Program.cs +++ b/src/TablesAndTuples/Program.cs | |||
| @@ -11,12 +11,6 @@ namespace TablesAndTuples | |||
| 11 | { | 11 | { |
| 12 | class Program | 12 | class Program |
| 13 | { | 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 | |||
| 20 | static void Main(string[] args) | 14 | static void Main(string[] args) |
| 21 | { | 15 | { |
| 22 | if (args.Length == 0) | 16 | if (args.Length == 0) |
| @@ -65,22 +59,34 @@ namespace TablesAndTuples | |||
| 65 | 59 | ||
| 66 | private static void ReadXmlWriteJson(string inputPath, string outputPath, string csOutputPath, string prefix) | 60 | private static void ReadXmlWriteJson(string inputPath, string outputPath, string csOutputPath, string prefix) |
| 67 | { | 61 | { |
| 68 | ReadXmlWriteCs(inputPath, csOutputPath, prefix); | 62 | var tableDefinitions = ReadXmlWriteCs(inputPath, csOutputPath, prefix); |
| 69 | |||
| 70 | var doc = XDocument.Load(inputPath); | ||
| 71 | 63 | ||
| 72 | var array = new JsonArray(); | 64 | var array = new JsonArray(); |
| 73 | 65 | ||
| 74 | foreach (var tableDefinition in doc.Descendants(TableDefinition)) | 66 | foreach (var tableDefinition in tableDefinitions) |
| 75 | { | 67 | { |
| 76 | var tupleType = tableDefinition.Attribute(Name).Value; | 68 | var tupleType = tableDefinition.Name; |
| 77 | 69 | ||
| 78 | var fields = new JsonArray(); | 70 | var fields = new JsonArray(); |
| 71 | var firstField = true; | ||
| 79 | 72 | ||
| 80 | foreach (var columnDefinition in tableDefinition.Elements(ColumnDefinition)) | 73 | foreach (var columnDefinition in tableDefinition.Columns) |
| 81 | { | 74 | { |
| 82 | var fieldName = columnDefinition.Attribute(Name).Value; | 75 | if (firstField) |
| 83 | var type = columnDefinition.Attribute(Type).Value; | 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(); | ||
| 84 | 90 | ||
| 85 | if (type == "localized") | 91 | if (type == "localized") |
| 86 | { | 92 | { |
| @@ -115,12 +121,13 @@ namespace TablesAndTuples | |||
| 115 | File.WriteAllText(outputPath, json); | 121 | File.WriteAllText(outputPath, json); |
| 116 | } | 122 | } |
| 117 | 123 | ||
| 118 | private static void ReadXmlWriteCs(string inputPath, string outputPath, string prefix) | 124 | private static List<WixTableDefinition> ReadXmlWriteCs(string inputPath, string outputPath, string prefix) |
| 119 | { | 125 | { |
| 120 | var tableDefinitions = WixTableDefinition.LoadCollection(inputPath); | 126 | var tableDefinitions = WixTableDefinition.LoadCollection(inputPath); |
| 121 | var text = GenerateCsTableDefinitionsFileText(prefix, tableDefinitions); | 127 | var text = GenerateCsTableDefinitionsFileText(prefix, tableDefinitions); |
| 122 | Console.WriteLine("Writing: {0}", outputPath); | 128 | Console.WriteLine("Writing: {0}", outputPath); |
| 123 | File.WriteAllText(outputPath, text); | 129 | File.WriteAllText(outputPath, text); |
| 130 | return tableDefinitions; | ||
| 124 | } | 131 | } |
| 125 | 132 | ||
| 126 | private static void ReadJsonWriteCs(string inputPath, string outputFolder, string prefix) | 133 | private static void ReadJsonWriteCs(string inputPath, string outputFolder, string prefix) |
