blob: 61dcbb0af7bb07b16eb8443b289d8fa19ee50f09 (
plain)
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
|
using System.Collections.Generic;
using System.Linq;
using System.Xml;
namespace TablesAndSymbols
{
class WixTableDefinition
{
public WixTableDefinition(string name, IEnumerable<WixColumnDefinition> columns, bool unreal, bool symbolless, string symbolDefinitionName, bool? symbolIdIsPrimaryKey)
{
this.Name = name;
this.VariableName = name.Replace("_", "");
this.Unreal = unreal;
this.Columns = columns?.ToArray();
this.Symbolless = symbolless;
this.SymbolDefinitionName = symbolless ? null : symbolDefinitionName ?? this.VariableName;
this.SymbolIdIsPrimaryKey = symbolIdIsPrimaryKey ?? DeriveSymbolIdIsPrimaryKey(this.Columns);
}
public string Name { get; }
public string VariableName { get; }
public string SymbolDefinitionName { get; }
public bool Unreal { get; }
public WixColumnDefinition[] Columns { get; }
public bool SymbolIdIsPrimaryKey { get; }
public bool Symbolless { get; }
static WixTableDefinition Read(XmlReader reader)
{
var empty = reader.IsEmptyElement;
string name = null;
string symbolDefinitionName = null;
var unreal = false;
bool? symbolIdIsPrimaryKey = null;
var symbolless = false;
while (reader.MoveToNextAttribute())
{
switch (reader.LocalName)
{
case "name":
name = reader.Value;
break;
case "symbolDefinitionName":
symbolDefinitionName = reader.Value;
break;
case "symbolIdIsPrimaryKey":
symbolIdIsPrimaryKey = reader.Value.Equals("yes");
break;
case "symbolless":
symbolless = reader.Value.Equals("yes");
break;
case "unreal":
unreal = reader.Value.Equals("yes");
break;
}
}
if (null == name)
{
throw new XmlException();
}
var columns = new List<WixColumnDefinition>();
// parse the child elements
if (!empty)
{
var done = false;
while (!done && reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.LocalName)
{
case "columnDefinition":
var columnDefinition = WixColumnDefinition.Read(reader);
columns.Add(columnDefinition);
break;
default:
throw new XmlException();
}
break;
case XmlNodeType.EndElement:
done = true;
break;
}
}
if (!done)
{
throw new XmlException();
}
}
return new WixTableDefinition(name, columns.ToArray(), unreal, symbolless, symbolDefinitionName, symbolIdIsPrimaryKey);
}
static bool DeriveSymbolIdIsPrimaryKey(WixColumnDefinition[] columns)
{
return columns[0].PrimaryKey &&
columns[0].Type == ColumnType.String &&
columns[0].Category == ColumnCategory.Identifier &&
!columns[0].Name.EndsWith("_") &&
(columns.Length == 1 || !columns.Skip(1).Any(t => t.PrimaryKey));
}
public static List<WixTableDefinition> LoadCollection(string inputPath)
{
using (var reader = XmlReader.Create(inputPath))
{
reader.MoveToContent();
if ("tableDefinitions" != reader.LocalName)
{
throw new XmlException();
}
var empty = reader.IsEmptyElement;
var tableDefinitions = new List<WixTableDefinition>();
while (reader.MoveToNextAttribute())
{
}
// parse the child elements
if (!empty)
{
var done = false;
while (!done && reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.LocalName)
{
case "tableDefinition":
tableDefinitions.Add(WixTableDefinition.Read(reader));
break;
default:
throw new XmlException();
}
break;
case XmlNodeType.EndElement:
done = true;
break;
}
}
if (!done)
{
throw new XmlException();
}
}
return tableDefinitions;
}
}
}
}
|