aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Rows/WixActionRowCollection.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Rows/WixActionRowCollection.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Rows/WixActionRowCollection.cs328
1 files changed, 328 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Rows/WixActionRowCollection.cs b/src/WixToolset.Core.WindowsInstaller/Rows/WixActionRowCollection.cs
new file mode 100644
index 00000000..d72198ee
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/Rows/WixActionRowCollection.cs
@@ -0,0 +1,328 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Core.WindowsInstaller.Rows
4{
5 using System;
6 using System.Collections;
7 using System.Diagnostics;
8 using System.Globalization;
9 using System.Xml;
10 using WixToolset.Data.Tuples;
11 using WixToolset.Data.WindowsInstaller.Rows;
12
13 /// <summary>
14 /// A collection of action rows sorted by their sequence table and action name.
15 /// </summary>
16 internal sealed class WixActionRowCollection : ICollection
17 {
18 private SortedList collection;
19
20 /// <summary>
21 /// Creates a new action table object.
22 /// </summary>
23 public WixActionRowCollection()
24 {
25 this.collection = new SortedList();
26 }
27
28 /// <summary>
29 /// Gets the number of items in the collection.
30 /// </summary>
31 /// <value>Number of items in collection.</value>
32 public int Count
33 {
34 get { return this.collection.Count; }
35 }
36
37 /// <summary>
38 /// Gets if the collection has been synchronized.
39 /// </summary>
40 /// <value>True if the collection has been synchronized.</value>
41 public bool IsSynchronized
42 {
43 get { return this.collection.IsSynchronized; }
44 }
45
46 /// <summary>
47 /// Gets the object used to synchronize the collection.
48 /// </summary>
49 /// <value>Oject used the synchronize the collection.</value>
50 public object SyncRoot
51 {
52 get { return this; }
53 }
54
55 /// <summary>
56 /// Get an ActionRow by its sequence table and action name.
57 /// </summary>
58 /// <param name="sequenceTable">The sequence table of the ActionRow.</param>
59 /// <param name="action">The action name of the ActionRow.</param>
60 public WixActionRow this[SequenceTable sequenceTable, string action]
61 {
62 get { return (WixActionRow)this.collection[GetKey(sequenceTable, action)]; }
63 }
64
65 /// <summary>
66 /// Add an ActionRow to the collection.
67 /// </summary>
68 /// <param name="actionRow">The ActionRow to add.</param>
69 /// <param name="overwrite">true to overwrite an existing ActionRow; false otherwise.</param>
70 public void Add(WixActionRow actionRow, bool overwrite)
71 {
72 string key = GetKey(actionRow.SequenceTable, actionRow.Action);
73
74 if (overwrite)
75 {
76 this.collection[key] = actionRow;
77 }
78 else
79 {
80 this.collection.Add(key, actionRow);
81 }
82 }
83
84 /// <summary>
85 /// Add an ActionRow to the collection.
86 /// </summary>
87 /// <param name="actionRow">The ActionRow to add.</param>
88 public void Add(WixActionRow actionRow)
89 {
90 this.Add(actionRow, false);
91 }
92
93 /// <summary>
94 /// Determines if the collection contains an ActionRow with a specific sequence table and name.
95 /// </summary>
96 /// <param name="sequenceTable">The sequence table of the ActionRow.</param>
97 /// <param name="action">The action name of the ActionRow.</param>
98 /// <returns>true if the ActionRow was found; false otherwise.</returns>
99 public bool Contains(SequenceTable sequenceTable, string action)
100 {
101 return this.collection.Contains(GetKey(sequenceTable, action));
102 }
103
104 /// <summary>
105 /// Copies the collection into an array.
106 /// </summary>
107 /// <param name="array">Array to copy the collection into.</param>
108 /// <param name="index">Index to start copying from.</param>
109 public void CopyTo(System.Array array, int index)
110 {
111 this.collection.Values.CopyTo(array, index);
112 }
113
114 /// <summary>
115 /// Gets the enumerator for the collection.
116 /// </summary>
117 /// <returns>The enumerator for the collection.</returns>
118 public IEnumerator GetEnumerator()
119 {
120 return this.collection.Values.GetEnumerator();
121 }
122
123 /// <summary>
124 /// Remove an ActionRow from the collection.
125 /// </summary>
126 /// <param name="sequenceTable">The sequence table of the ActionRow.</param>
127 /// <param name="action">The action name of the ActionRow.</param>
128 public void Remove(SequenceTable sequenceTable, string action)
129 {
130 this.collection.Remove(GetKey(sequenceTable, action));
131 }
132
133 /// <summary>
134 /// Load an action table from an XmlReader.
135 /// </summary>
136 /// <param name="reader">Reader to get data from.</param>
137 /// <returns>The ActionRowCollection represented by the xml.</returns>
138 internal static WixActionRowCollection Load(XmlReader reader)
139 {
140 reader.MoveToContent();
141
142 return Parse(reader);
143 }
144
145 /// <summary>
146 /// Creates a new action table object and populates it from an Xml reader.
147 /// </summary>
148 /// <param name="reader">Reader to get data from.</param>
149 /// <returns>The parsed ActionTable.</returns>
150 private static WixActionRowCollection Parse(XmlReader reader)
151 {
152 if (!reader.LocalName.Equals("actions"))
153 {
154 throw new XmlException();
155 }
156
157 WixActionRowCollection actionRows = new WixActionRowCollection();
158 bool empty = reader.IsEmptyElement;
159
160 while (reader.MoveToNextAttribute())
161 {
162 }
163
164 if (!empty)
165 {
166 bool done = false;
167
168 // loop through all the fields in a row
169 while (!done && reader.Read())
170 {
171 switch (reader.NodeType)
172 {
173 case XmlNodeType.Element:
174 switch (reader.LocalName)
175 {
176 case "action":
177 WixActionRow[] parsedActionRows = ParseActions(reader);
178
179 foreach (WixActionRow actionRow in parsedActionRows)
180 {
181 actionRows.Add(actionRow);
182 }
183 break;
184 default:
185 throw new XmlException();
186 }
187 break;
188 case XmlNodeType.EndElement:
189 done = true;
190 break;
191 }
192 }
193
194 if (!done)
195 {
196 throw new XmlException();
197 }
198 }
199
200 return actionRows;
201 }
202
203 /// <summary>
204 /// Get the key for storing an ActionRow.
205 /// </summary>
206 /// <param name="sequenceTable">The sequence table of the ActionRow.</param>
207 /// <param name="action">The action name of the ActionRow.</param>
208 /// <returns>The string key.</returns>
209 private static string GetKey(SequenceTable sequenceTable, string action)
210 {
211 return GetKey(sequenceTable.ToString(), action);
212 }
213
214 /// <summary>
215 /// Get the key for storing an ActionRow.
216 /// </summary>
217 /// <param name="sequenceTable">The sequence table of the ActionRow.</param>
218 /// <param name="action">The action name of the ActionRow.</param>
219 /// <returns>The string key.</returns>
220 private static string GetKey(string sequenceTable, string action)
221 {
222 return String.Concat(sequenceTable, '/', action);
223 }
224
225 /// <summary>
226 /// Parses ActionRows from the Xml reader.
227 /// </summary>
228 /// <param name="reader">Xml reader that contains serialized ActionRows.</param>
229 /// <returns>The parsed ActionRows.</returns>
230 internal static WixActionRow[] ParseActions(XmlReader reader)
231 {
232 Debug.Assert("action" == reader.LocalName);
233
234 string id = null;
235 string condition = null;
236 bool empty = reader.IsEmptyElement;
237 int sequence = int.MinValue;
238 int sequenceCount = 0;
239 SequenceTable[] sequenceTables = new SequenceTable[Enum.GetValues(typeof(SequenceTable)).Length];
240
241 while (reader.MoveToNextAttribute())
242 {
243 switch (reader.Name)
244 {
245 case "name":
246 id = reader.Value;
247 break;
248 case "AdminExecuteSequence":
249 if (reader.Value.Equals("yes"))
250 {
251 sequenceTables[sequenceCount] = SequenceTable.AdminExecuteSequence;
252 ++sequenceCount;
253 }
254 break;
255 case "AdminUISequence":
256 if (reader.Value.Equals("yes"))
257 {
258 sequenceTables[sequenceCount] = SequenceTable.AdminUISequence;
259 ++sequenceCount;
260 }
261 break;
262 case "AdvtExecuteSequence":
263 if (reader.Value.Equals("yes"))
264 {
265 sequenceTables[sequenceCount] = SequenceTable.AdvtExecuteSequence;
266 ++sequenceCount;
267 }
268 break;
269 case "condition":
270 condition = reader.Value;
271 break;
272 case "InstallExecuteSequence":
273 if (reader.Value.Equals("yes"))
274 {
275 sequenceTables[sequenceCount] = SequenceTable.InstallExecuteSequence;
276 ++sequenceCount;
277 }
278 break;
279 case "InstallUISequence":
280 if (reader.Value.Equals("yes"))
281 {
282 sequenceTables[sequenceCount] = SequenceTable.InstallUISequence;
283 ++sequenceCount;
284 }
285 break;
286 case "sequence":
287 sequence = Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture);
288 break;
289 }
290 }
291
292 if (null == id)
293 {
294 throw new XmlException();
295 }
296
297 if (int.MinValue == sequence)
298 {
299 throw new XmlException();
300 }
301 else if (1 > sequence)
302 {
303 throw new XmlException();
304 }
305
306 if (0 == sequenceCount)
307 {
308 throw new XmlException();
309 }
310
311 if (!empty && reader.Read() && XmlNodeType.EndElement != reader.MoveToContent())
312 {
313 throw new XmlException();
314 }
315
316 // create the actions
317 WixActionRow[] actionRows = new WixActionRow[sequenceCount];
318 for (int i = 0; i < sequenceCount; i++)
319 {
320 //WixActionRow actionRow = new WixActionRow(sequenceTables[i], id, condition, sequence);
321 //actionRows[i] = actionRow;
322 throw new NotImplementedException();
323 }
324
325 return actionRows;
326 }
327 }
328}