aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data.WindowsInstaller/TableDefinitionCollection.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Data.WindowsInstaller/TableDefinitionCollection.cs')
-rw-r--r--src/WixToolset.Data.WindowsInstaller/TableDefinitionCollection.cs240
1 files changed, 0 insertions, 240 deletions
diff --git a/src/WixToolset.Data.WindowsInstaller/TableDefinitionCollection.cs b/src/WixToolset.Data.WindowsInstaller/TableDefinitionCollection.cs
deleted file mode 100644
index 26d56387..00000000
--- a/src/WixToolset.Data.WindowsInstaller/TableDefinitionCollection.cs
+++ /dev/null
@@ -1,240 +0,0 @@
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.Data
4{
5 using System;
6 using System.Collections;
7 using System.Collections.Generic;
8 using System.Linq;
9 using System.Xml;
10
11 /// <summary>
12 /// Collection for table definitions indexed by table name.
13 /// </summary>
14 public sealed class TableDefinitionCollection : ICollection<TableDefinition>
15 {
16 public const string XmlNamespaceUri = "http://wixtoolset.org/schemas/v4/wi/tables";
17
18 private Dictionary<string, TableDefinition> collection;
19
20 /// <summary>
21 /// Instantiate a new TableDefinitionCollection class.
22 /// </summary>
23 public TableDefinitionCollection()
24 {
25 this.collection = new Dictionary<string,TableDefinition>();
26 }
27
28 /// <summary>
29 /// Creates a shallow copy of the provided table definition collection.
30 /// </summary>
31 public TableDefinitionCollection(TableDefinitionCollection tableDefinitions)
32 {
33 this.collection = new Dictionary<string, TableDefinition>(tableDefinitions.collection);
34 }
35
36 /// <summary>
37 /// Gets the number of items in the collection.
38 /// </summary>
39 /// <value>Number of items in collection.</value>
40 public int Count
41 {
42 get { return this.collection.Count; }
43 }
44
45 /// <summary>
46 /// Table definition collections are never read-only.
47 /// </summary>
48 public bool IsReadOnly
49 {
50 get { return false; }
51 }
52
53 /// <summary>
54 /// Gets a table definition by name.
55 /// </summary>
56 /// <param name="tableName">Name of table to locate.</param>
57 public TableDefinition this[string tableName]
58 {
59 get
60 {
61 TableDefinition table;
62 if (!this.collection.TryGetValue(tableName, out table))
63 {
64 throw new WixMissingTableDefinitionException(WixDataErrors.MissingTableDefinition(tableName));
65 }
66
67 return table;
68 }
69 }
70
71 /// <summary>
72 /// Tries to get a table definition by name.
73 /// </summary>
74 /// <param name="tableName">Name of table to locate.</param>
75 /// <param name="table">Table definition if found.</param>
76 /// <returns>True if table definition was found otherwise false.</returns>
77 public bool TryGet(string tableName, out TableDefinition table)
78 {
79 return this.collection.TryGetValue(tableName, out table);
80 }
81
82 /// <summary>
83 /// Load a table definition collection from an XmlReader.
84 /// </summary>
85 /// <param name="reader">Reader to get data from.</param>
86 /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
87 /// <returns>The TableDefinitionCollection represented by the xml.</returns>
88 public static TableDefinitionCollection Load(XmlReader reader)
89 {
90 reader.MoveToContent();
91
92 return Read(reader);
93 }
94
95 /// <summary>
96 /// Adds a table definition to the collection.
97 /// </summary>
98 /// <param name="tableDefinition">Table definition to add to the collection.</param>
99 /// <value>Indexes by table definition name.</value>
100 public void Add(TableDefinition tableDefinition)
101 {
102 this.collection.Add(tableDefinition.Name, tableDefinition);
103 }
104
105 /// <summary>
106 /// Removes all table definitions from the collection.
107 /// </summary>
108 public void Clear()
109 {
110 this.collection.Clear();
111 }
112
113 /// <summary>
114 /// Checks if the collection contains a table name.
115 /// </summary>
116 /// <param name="tableName">The table to check in the collection.</param>
117 /// <returns>True if collection contains the table.</returns>
118 public bool Contains(string tableName)
119 {
120 return this.collection.ContainsKey(tableName);
121 }
122
123 /// <summary>
124 /// Checks if the collection contains a table.
125 /// </summary>
126 /// <param name="table">The table to check in the collection.</param>
127 /// <returns>True if collection contains the table.</returns>
128 public bool Contains(TableDefinition table)
129 {
130 return this.collection.ContainsKey(table.Name);
131 }
132
133 /// <summary>
134 /// Copies table definitions to an arry.
135 /// </summary>
136 /// <param name="array">Array to copy the table definitions to.</param>
137 /// <param name="index">Index in the array to start copying at.</param>
138 public void CopyTo(TableDefinition[] array, int index)
139 {
140 this.collection.Values.CopyTo(array, index);
141 }
142
143 /// <summary>
144 /// Removes a table definition from the collection.
145 /// </summary>
146 /// <param name="table">Table to remove from the collection.</param>
147 /// <returns>True if the table definition existed in the collection and was removed.</returns>
148 public bool Remove(TableDefinition table)
149 {
150 return this.collection.Remove(table.Name);
151 }
152
153 /// <summary>
154 /// Gets enumerator for the collection.
155 /// </summary>
156 /// <returns>Enumerator for the collection.</returns>
157 public IEnumerator<TableDefinition> GetEnumerator()
158 {
159 return this.collection.Values.GetEnumerator();
160 }
161
162 /// <summary>
163 /// Gets the untyped enumerator for the collection.
164 /// </summary>
165 /// <returns>Untyped enumerator for the collection.</returns>
166 IEnumerator IEnumerable.GetEnumerator()
167 {
168 return this.collection.Values.GetEnumerator();
169 }
170
171 /// <summary>
172 /// Loads a collection of table definitions from a XmlReader in memory.
173 /// </summary>
174 /// <param name="reader">Reader to get data from.</param>
175 /// <returns>The TableDefinitionCollection represented by the xml.</returns>
176 internal static TableDefinitionCollection Read(XmlReader reader)
177 {
178 if ("tableDefinitions" != reader.LocalName)
179 {
180 throw new XmlException();
181 }
182
183 bool empty = reader.IsEmptyElement;
184 TableDefinitionCollection tableDefinitionCollection = new TableDefinitionCollection();
185
186 while (reader.MoveToNextAttribute())
187 {
188 }
189
190 // parse the child elements
191 if (!empty)
192 {
193 bool done = false;
194
195 while (!done && reader.Read())
196 {
197 switch (reader.NodeType)
198 {
199 case XmlNodeType.Element:
200 switch (reader.LocalName)
201 {
202 case "tableDefinition":
203 tableDefinitionCollection.Add(TableDefinition.Read(reader));
204 break;
205 default:
206 throw new XmlException();
207 }
208 break;
209 case XmlNodeType.EndElement:
210 done = true;
211 break;
212 }
213 }
214
215 if (!done)
216 {
217 throw new XmlException();
218 }
219 }
220
221 return tableDefinitionCollection;
222 }
223
224 /// <summary>
225 /// Persists a TableDefinitionCollection in an XML format.
226 /// </summary>
227 /// <param name="writer">XmlWriter where the TableDefinitionCollection should persist itself as XML.</param>
228 internal void Write(XmlWriter writer)
229 {
230 writer.WriteStartElement("tableDefinitions", XmlNamespaceUri);
231
232 foreach (TableDefinition tableDefinition in this.collection.Values.OrderBy(t => t.Name))
233 {
234 tableDefinition.Write(writer);
235 }
236
237 writer.WriteEndElement();
238 }
239 }
240}