diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-11-01 10:59:45 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-11-01 10:59:45 -0700 |
| commit | 2bb37beda887d120a0ddabf874ad25357101faa1 (patch) | |
| tree | c35e97b03274b86cfc9ff7fd2caeee211165a140 /src/WixToolset.Data.WindowsInstaller/Rows/WixActionRowCollection.cs | |
| parent | df7413aeed3aea3425dff20ae0c8b1be3a3ab525 (diff) | |
| download | wix-2bb37beda887d120a0ddabf874ad25357101faa1.tar.gz wix-2bb37beda887d120a0ddabf874ad25357101faa1.tar.bz2 wix-2bb37beda887d120a0ddabf874ad25357101faa1.zip | |
Update to WiX Intermediate Representation
Diffstat (limited to 'src/WixToolset.Data.WindowsInstaller/Rows/WixActionRowCollection.cs')
| -rw-r--r-- | src/WixToolset.Data.WindowsInstaller/Rows/WixActionRowCollection.cs | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/src/WixToolset.Data.WindowsInstaller/Rows/WixActionRowCollection.cs b/src/WixToolset.Data.WindowsInstaller/Rows/WixActionRowCollection.cs new file mode 100644 index 00000000..513a104f --- /dev/null +++ b/src/WixToolset.Data.WindowsInstaller/Rows/WixActionRowCollection.cs | |||
| @@ -0,0 +1,222 @@ | |||
| 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 | |||
| 3 | namespace WixToolset.Data.Rows | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections; | ||
| 7 | using System.Diagnostics; | ||
| 8 | using System.Xml; | ||
| 9 | |||
| 10 | /// <summary> | ||
| 11 | /// A collection of action rows sorted by their sequence table and action name. | ||
| 12 | /// </summary> | ||
| 13 | public sealed class WixActionRowCollection : ICollection | ||
| 14 | { | ||
| 15 | private SortedList collection; | ||
| 16 | |||
| 17 | /// <summary> | ||
| 18 | /// Creates a new action table object. | ||
| 19 | /// </summary> | ||
| 20 | public WixActionRowCollection() | ||
| 21 | { | ||
| 22 | this.collection = new SortedList(); | ||
| 23 | } | ||
| 24 | |||
| 25 | /// <summary> | ||
| 26 | /// Gets the number of items in the collection. | ||
| 27 | /// </summary> | ||
| 28 | /// <value>Number of items in collection.</value> | ||
| 29 | public int Count | ||
| 30 | { | ||
| 31 | get { return this.collection.Count; } | ||
| 32 | } | ||
| 33 | |||
| 34 | /// <summary> | ||
| 35 | /// Gets if the collection has been synchronized. | ||
| 36 | /// </summary> | ||
| 37 | /// <value>True if the collection has been synchronized.</value> | ||
| 38 | public bool IsSynchronized | ||
| 39 | { | ||
| 40 | get { return this.collection.IsSynchronized; } | ||
| 41 | } | ||
| 42 | |||
| 43 | /// <summary> | ||
| 44 | /// Gets the object used to synchronize the collection. | ||
| 45 | /// </summary> | ||
| 46 | /// <value>Oject used the synchronize the collection.</value> | ||
| 47 | public object SyncRoot | ||
| 48 | { | ||
| 49 | get { return this; } | ||
| 50 | } | ||
| 51 | |||
| 52 | /// <summary> | ||
| 53 | /// Get an ActionRow by its sequence table and action name. | ||
| 54 | /// </summary> | ||
| 55 | /// <param name="sequenceTable">The sequence table of the ActionRow.</param> | ||
| 56 | /// <param name="action">The action name of the ActionRow.</param> | ||
| 57 | public WixActionRow this[SequenceTable sequenceTable, string action] | ||
| 58 | { | ||
| 59 | get { return (WixActionRow)this.collection[GetKey(sequenceTable, action)]; } | ||
| 60 | } | ||
| 61 | |||
| 62 | /// <summary> | ||
| 63 | /// Add an ActionRow to the collection. | ||
| 64 | /// </summary> | ||
| 65 | /// <param name="actionRow">The ActionRow to add.</param> | ||
| 66 | /// <param name="overwrite">true to overwrite an existing ActionRow; false otherwise.</param> | ||
| 67 | public void Add(WixActionRow actionRow, bool overwrite) | ||
| 68 | { | ||
| 69 | string key = GetKey(actionRow.SequenceTable, actionRow.Action); | ||
| 70 | |||
| 71 | if (overwrite) | ||
| 72 | { | ||
| 73 | this.collection[key] = actionRow; | ||
| 74 | } | ||
| 75 | else | ||
| 76 | { | ||
| 77 | this.collection.Add(key, actionRow); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | /// <summary> | ||
| 82 | /// Add an ActionRow to the collection. | ||
| 83 | /// </summary> | ||
| 84 | /// <param name="actionRow">The ActionRow to add.</param> | ||
| 85 | public void Add(WixActionRow actionRow) | ||
| 86 | { | ||
| 87 | this.Add(actionRow, false); | ||
| 88 | } | ||
| 89 | |||
| 90 | /// <summary> | ||
| 91 | /// Determines if the collection contains an ActionRow with a specific sequence table and name. | ||
| 92 | /// </summary> | ||
| 93 | /// <param name="sequenceTable">The sequence table of the ActionRow.</param> | ||
| 94 | /// <param name="action">The action name of the ActionRow.</param> | ||
| 95 | /// <returns>true if the ActionRow was found; false otherwise.</returns> | ||
| 96 | public bool Contains(SequenceTable sequenceTable, string action) | ||
| 97 | { | ||
| 98 | return this.collection.Contains(GetKey(sequenceTable, action)); | ||
| 99 | } | ||
| 100 | |||
| 101 | /// <summary> | ||
| 102 | /// Copies the collection into an array. | ||
| 103 | /// </summary> | ||
| 104 | /// <param name="array">Array to copy the collection into.</param> | ||
| 105 | /// <param name="index">Index to start copying from.</param> | ||
| 106 | public void CopyTo(System.Array array, int index) | ||
| 107 | { | ||
| 108 | this.collection.Values.CopyTo(array, index); | ||
| 109 | } | ||
| 110 | |||
| 111 | /// <summary> | ||
| 112 | /// Gets the enumerator for the collection. | ||
| 113 | /// </summary> | ||
| 114 | /// <returns>The enumerator for the collection.</returns> | ||
| 115 | public IEnumerator GetEnumerator() | ||
| 116 | { | ||
| 117 | return this.collection.Values.GetEnumerator(); | ||
| 118 | } | ||
| 119 | |||
| 120 | /// <summary> | ||
| 121 | /// Remove an ActionRow from the collection. | ||
| 122 | /// </summary> | ||
| 123 | /// <param name="sequenceTable">The sequence table of the ActionRow.</param> | ||
| 124 | /// <param name="action">The action name of the ActionRow.</param> | ||
| 125 | public void Remove(SequenceTable sequenceTable, string action) | ||
| 126 | { | ||
| 127 | this.collection.Remove(GetKey(sequenceTable, action)); | ||
| 128 | } | ||
| 129 | |||
| 130 | /// <summary> | ||
| 131 | /// Load an action table from an XmlReader. | ||
| 132 | /// </summary> | ||
| 133 | /// <param name="reader">Reader to get data from.</param> | ||
| 134 | /// <returns>The ActionRowCollection represented by the xml.</returns> | ||
| 135 | internal static WixActionRowCollection Load(XmlReader reader) | ||
| 136 | { | ||
| 137 | reader.MoveToContent(); | ||
| 138 | |||
| 139 | return Parse(reader); | ||
| 140 | } | ||
| 141 | |||
| 142 | /// <summary> | ||
| 143 | /// Creates a new action table object and populates it from an Xml reader. | ||
| 144 | /// </summary> | ||
| 145 | /// <param name="reader">Reader to get data from.</param> | ||
| 146 | /// <returns>The parsed ActionTable.</returns> | ||
| 147 | private static WixActionRowCollection Parse(XmlReader reader) | ||
| 148 | { | ||
| 149 | if (!reader.LocalName.Equals("actions")) | ||
| 150 | { | ||
| 151 | throw new XmlException(); | ||
| 152 | } | ||
| 153 | |||
| 154 | WixActionRowCollection actionRows = new WixActionRowCollection(); | ||
| 155 | bool empty = reader.IsEmptyElement; | ||
| 156 | |||
| 157 | while (reader.MoveToNextAttribute()) | ||
| 158 | { | ||
| 159 | } | ||
| 160 | |||
| 161 | if (!empty) | ||
| 162 | { | ||
| 163 | bool done = false; | ||
| 164 | |||
| 165 | // loop through all the fields in a row | ||
| 166 | while (!done && reader.Read()) | ||
| 167 | { | ||
| 168 | switch (reader.NodeType) | ||
| 169 | { | ||
| 170 | case XmlNodeType.Element: | ||
| 171 | switch (reader.LocalName) | ||
| 172 | { | ||
| 173 | case "action": | ||
| 174 | WixActionRow[] parsedActionRows = WixActionRow.Parse(reader); | ||
| 175 | |||
| 176 | foreach (WixActionRow actionRow in parsedActionRows) | ||
| 177 | { | ||
| 178 | actionRows.Add(actionRow); | ||
| 179 | } | ||
| 180 | break; | ||
| 181 | default: | ||
| 182 | throw new XmlException(); | ||
| 183 | } | ||
| 184 | break; | ||
| 185 | case XmlNodeType.EndElement: | ||
| 186 | done = true; | ||
| 187 | break; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | if (!done) | ||
| 192 | { | ||
| 193 | throw new XmlException(); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | return actionRows; | ||
| 198 | } | ||
| 199 | |||
| 200 | /// <summary> | ||
| 201 | /// Get the key for storing an ActionRow. | ||
| 202 | /// </summary> | ||
| 203 | /// <param name="sequenceTable">The sequence table of the ActionRow.</param> | ||
| 204 | /// <param name="action">The action name of the ActionRow.</param> | ||
| 205 | /// <returns>The string key.</returns> | ||
| 206 | private static string GetKey(SequenceTable sequenceTable, string action) | ||
| 207 | { | ||
| 208 | return GetKey(sequenceTable.ToString(), action); | ||
| 209 | } | ||
| 210 | |||
| 211 | /// <summary> | ||
| 212 | /// Get the key for storing an ActionRow. | ||
| 213 | /// </summary> | ||
| 214 | /// <param name="sequenceTable">The sequence table of the ActionRow.</param> | ||
| 215 | /// <param name="action">The action name of the ActionRow.</param> | ||
| 216 | /// <returns>The string key.</returns> | ||
| 217 | private static string GetKey(string sequenceTable, string action) | ||
| 218 | { | ||
| 219 | return String.Concat(sequenceTable, '/', action); | ||
| 220 | } | ||
| 221 | } | ||
| 222 | } | ||
