diff options
Diffstat (limited to 'src')
5 files changed, 94 insertions, 14 deletions
diff --git a/src/WixToolset.Data/WindowsInstaller/SubStorage.cs b/src/WixToolset.Data/WindowsInstaller/SubStorage.cs index e24839c0..76b1b795 100644 --- a/src/WixToolset.Data/WindowsInstaller/SubStorage.cs +++ b/src/WixToolset.Data/WindowsInstaller/SubStorage.cs | |||
| @@ -36,8 +36,9 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 36 | /// Creates a SubStorage from the XmlReader. | 36 | /// Creates a SubStorage from the XmlReader. |
| 37 | /// </summary> | 37 | /// </summary> |
| 38 | /// <param name="reader">Reader to get data from.</param> | 38 | /// <param name="reader">Reader to get data from.</param> |
| 39 | /// <param name="tableDefinitions">Table definitions to use for strongly-typed rows.</param> | ||
| 39 | /// <returns>New SubStorage object.</returns> | 40 | /// <returns>New SubStorage object.</returns> |
| 40 | internal static SubStorage Read(XmlReader reader) | 41 | internal static SubStorage Read(XmlReader reader, TableDefinitionCollection tableDefinitions) |
| 41 | { | 42 | { |
| 42 | if (reader.LocalName != "subStorage") | 43 | if (reader.LocalName != "subStorage") |
| 43 | { | 44 | { |
| @@ -71,7 +72,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 71 | switch (reader.LocalName) | 72 | switch (reader.LocalName) |
| 72 | { | 73 | { |
| 73 | case WindowsInstallerData.XmlElementName: | 74 | case WindowsInstallerData.XmlElementName: |
| 74 | data = WindowsInstallerData.Read(reader, true); | 75 | data = WindowsInstallerData.Read(reader, tableDefinitions, true); |
| 75 | break; | 76 | break; |
| 76 | default: | 77 | default: |
| 77 | throw new XmlException(); | 78 | throw new XmlException(); |
diff --git a/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs b/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs index 9ec37895..214544ca 100644 --- a/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs +++ b/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs | |||
| @@ -156,12 +156,16 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 156 | /// Parses table definition from xml reader. | 156 | /// Parses table definition from xml reader. |
| 157 | /// </summary> | 157 | /// </summary> |
| 158 | /// <param name="reader">Reader to get data from.</param> | 158 | /// <param name="reader">Reader to get data from.</param> |
| 159 | /// <param name="tableDefinitions">Table definitions to use for strongly-typed rows.</param> | ||
| 159 | /// <returns>The TableDefintion represented by the Xml.</returns> | 160 | /// <returns>The TableDefintion represented by the Xml.</returns> |
| 160 | internal static TableDefinition Read(XmlReader reader) | 161 | internal static TableDefinition Read(XmlReader reader, TableDefinitionCollection tableDefinitions) |
| 161 | { | 162 | { |
| 162 | var empty = reader.IsEmptyElement; | 163 | var empty = reader.IsEmptyElement; |
| 163 | string name = null; | 164 | string name = null; |
| 165 | IntermediateTupleDefinition tupleDefinition = null; | ||
| 164 | var unreal = false; | 166 | var unreal = false; |
| 167 | var tupleIdIsPrimaryKey = false; | ||
| 168 | Type strongRowType = null; | ||
| 165 | 169 | ||
| 166 | while (reader.MoveToNextAttribute()) | 170 | while (reader.MoveToNextAttribute()) |
| 167 | { | 171 | { |
| @@ -181,6 +185,13 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 181 | throw new XmlException(); | 185 | throw new XmlException(); |
| 182 | } | 186 | } |
| 183 | 187 | ||
| 188 | if (tableDefinitions.TryGet(name, out var tableDefinition)) | ||
| 189 | { | ||
| 190 | tupleDefinition = tableDefinition.TupleDefinition; | ||
| 191 | tupleIdIsPrimaryKey = tableDefinition.TupleIdIsPrimaryKey; | ||
| 192 | strongRowType = tableDefinition.StrongRowType; | ||
| 193 | } | ||
| 194 | |||
| 184 | var columns = new List<ColumnDefinition>(); | 195 | var columns = new List<ColumnDefinition>(); |
| 185 | var hasPrimaryKeyColumn = false; | 196 | var hasPrimaryKeyColumn = false; |
| 186 | 197 | ||
| @@ -226,7 +237,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 226 | } | 237 | } |
| 227 | } | 238 | } |
| 228 | 239 | ||
| 229 | return new TableDefinition(name, null, columns.ToArray(), unreal); | 240 | return new TableDefinition(name, tupleDefinition, columns.ToArray(), unreal, tupleIdIsPrimaryKey, strongRowType); |
| 230 | } | 241 | } |
| 231 | 242 | ||
| 232 | /// <summary> | 243 | /// <summary> |
diff --git a/src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs b/src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs index 91385d74..fcc2b1f6 100644 --- a/src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs +++ b/src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs | |||
| @@ -132,8 +132,9 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 132 | /// Loads a collection of table definitions from a XmlReader in memory. | 132 | /// Loads a collection of table definitions from a XmlReader in memory. |
| 133 | /// </summary> | 133 | /// </summary> |
| 134 | /// <param name="reader">Reader to get data from.</param> | 134 | /// <param name="reader">Reader to get data from.</param> |
| 135 | /// <param name="tableDefinitions">Table definitions to use for strongly-typed rows.</param> | ||
| 135 | /// <returns>The TableDefinitionCollection represented by the xml.</returns> | 136 | /// <returns>The TableDefinitionCollection represented by the xml.</returns> |
| 136 | internal static TableDefinitionCollection Read(XmlReader reader) | 137 | internal static TableDefinitionCollection Read(XmlReader reader, TableDefinitionCollection tableDefinitions) |
| 137 | { | 138 | { |
| 138 | if ("tableDefinitions" != reader.LocalName) | 139 | if ("tableDefinitions" != reader.LocalName) |
| 139 | { | 140 | { |
| @@ -160,7 +161,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 160 | switch (reader.LocalName) | 161 | switch (reader.LocalName) |
| 161 | { | 162 | { |
| 162 | case "tableDefinition": | 163 | case "tableDefinition": |
| 163 | tableDefinitionCollection.Add(TableDefinition.Read(reader)); | 164 | tableDefinitionCollection.Add(TableDefinition.Read(reader, tableDefinitions)); |
| 164 | break; | 165 | break; |
| 165 | default: | 166 | default: |
| 166 | throw new XmlException(); | 167 | throw new XmlException(); |
diff --git a/src/WixToolset.Data/WindowsInstaller/WindowsInstallerData.cs b/src/WixToolset.Data/WindowsInstaller/WindowsInstallerData.cs index e30be598..67a074c6 100644 --- a/src/WixToolset.Data/WindowsInstaller/WindowsInstallerData.cs +++ b/src/WixToolset.Data/WindowsInstaller/WindowsInstallerData.cs | |||
| @@ -113,9 +113,22 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 113 | /// <returns>Output object.</returns> | 113 | /// <returns>Output object.</returns> |
| 114 | public static WindowsInstallerData Load(string path, bool suppressVersionCheck = false) | 114 | public static WindowsInstallerData Load(string path, bool suppressVersionCheck = false) |
| 115 | { | 115 | { |
| 116 | var tableDefinitions = new TableDefinitionCollection(WindowsInstallerTableDefinitions.All); | ||
| 117 | return WindowsInstallerData.Load(path, tableDefinitions, suppressVersionCheck); | ||
| 118 | } | ||
| 119 | |||
| 120 | /// <summary> | ||
| 121 | /// Loads an output from a path on disk. | ||
| 122 | /// </summary> | ||
| 123 | /// <param name="path">Path to output file saved on disk.</param> | ||
| 124 | /// <param name="tableDefinitions">Table definitions to use for creating strongly-typed rows.</param> | ||
| 125 | /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> | ||
| 126 | /// <returns>Output object.</returns> | ||
| 127 | public static WindowsInstallerData Load(string path, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck = false) | ||
| 128 | { | ||
| 116 | using (var wixOutput = WixOutput.Read(path)) | 129 | using (var wixOutput = WixOutput.Read(path)) |
| 117 | { | 130 | { |
| 118 | return WindowsInstallerData.Load(wixOutput, suppressVersionCheck); | 131 | return WindowsInstallerData.Load(wixOutput, tableDefinitions, suppressVersionCheck); |
| 119 | } | 132 | } |
| 120 | } | 133 | } |
| 121 | 134 | ||
| @@ -127,13 +140,26 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 127 | /// <returns>Output object.</returns> | 140 | /// <returns>Output object.</returns> |
| 128 | public static WindowsInstallerData Load(WixOutput wixOutput, bool suppressVersionCheck = false) | 141 | public static WindowsInstallerData Load(WixOutput wixOutput, bool suppressVersionCheck = false) |
| 129 | { | 142 | { |
| 143 | var tableDefinitions = new TableDefinitionCollection(WindowsInstallerTableDefinitions.All); | ||
| 144 | return WindowsInstallerData.Load(wixOutput, tableDefinitions, suppressVersionCheck); | ||
| 145 | } | ||
| 146 | |||
| 147 | /// <summary> | ||
| 148 | /// Loads an output from a WixOutput object. | ||
| 149 | /// </summary> | ||
| 150 | /// <param name="wixOutput">WixOutput object.</param> | ||
| 151 | /// <param name="tableDefinitions">Table definitions to use for creating strongly-typed rows.</param> | ||
| 152 | /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> | ||
| 153 | /// <returns>Output object.</returns> | ||
| 154 | public static WindowsInstallerData Load(WixOutput wixOutput, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck = false) | ||
| 155 | { | ||
| 130 | using (var stream = wixOutput.GetDataStream(WixOutputStreamName)) | 156 | using (var stream = wixOutput.GetDataStream(WixOutputStreamName)) |
| 131 | using (var reader = XmlReader.Create(stream, null, wixOutput.Uri.AbsoluteUri)) | 157 | using (var reader = XmlReader.Create(stream, null, wixOutput.Uri.AbsoluteUri)) |
| 132 | { | 158 | { |
| 133 | try | 159 | try |
| 134 | { | 160 | { |
| 135 | reader.MoveToContent(); | 161 | reader.MoveToContent(); |
| 136 | return WindowsInstallerData.Read(reader, suppressVersionCheck); | 162 | return WindowsInstallerData.Read(reader, tableDefinitions, suppressVersionCheck); |
| 137 | } | 163 | } |
| 138 | catch (XmlException xe) | 164 | catch (XmlException xe) |
| 139 | { | 165 | { |
| @@ -146,9 +172,10 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 146 | /// Processes an XmlReader and builds up the output object. | 172 | /// Processes an XmlReader and builds up the output object. |
| 147 | /// </summary> | 173 | /// </summary> |
| 148 | /// <param name="reader">Reader to get data from.</param> | 174 | /// <param name="reader">Reader to get data from.</param> |
| 175 | /// <param name="tableDefinitions">Table definitions to use for creating strongly-typed rows.</param> | ||
| 149 | /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> | 176 | /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> |
| 150 | /// <returns>The Output represented by the Xml.</returns> | 177 | /// <returns>The Output represented by the Xml.</returns> |
| 151 | internal static WindowsInstallerData Read(XmlReader reader, bool suppressVersionCheck) | 178 | internal static WindowsInstallerData Read(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck) |
| 152 | { | 179 | { |
| 153 | if (!reader.LocalName.Equals(WindowsInstallerData.XmlElementName)) | 180 | if (!reader.LocalName.Equals(WindowsInstallerData.XmlElementName)) |
| 154 | { | 181 | { |
| @@ -203,7 +230,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 203 | } | 230 | } |
| 204 | 231 | ||
| 205 | // loop through the rest of the xml building up the Output object | 232 | // loop through the rest of the xml building up the Output object |
| 206 | TableDefinitionCollection tableDefinitions = null; | 233 | TableDefinitionCollection xmlTableDefinitions = null; |
| 207 | var tables = new List<Table>(); | 234 | var tables = new List<Table>(); |
| 208 | if (!empty) | 235 | if (!empty) |
| 209 | { | 236 | { |
| @@ -218,17 +245,17 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 218 | switch (reader.LocalName) | 245 | switch (reader.LocalName) |
| 219 | { | 246 | { |
| 220 | case "subStorage": | 247 | case "subStorage": |
| 221 | output.SubStorages.Add(SubStorage.Read(reader)); | 248 | output.SubStorages.Add(SubStorage.Read(reader, tableDefinitions)); |
| 222 | break; | 249 | break; |
| 223 | case "table": | 250 | case "table": |
| 224 | if (null == tableDefinitions) | 251 | if (null == xmlTableDefinitions) |
| 225 | { | 252 | { |
| 226 | throw new XmlException(); | 253 | throw new XmlException(); |
| 227 | } | 254 | } |
| 228 | tables.Add(Table.Read(reader, tableDefinitions)); | 255 | tables.Add(Table.Read(reader, xmlTableDefinitions)); |
| 229 | break; | 256 | break; |
| 230 | case "tableDefinitions": | 257 | case "tableDefinitions": |
| 231 | tableDefinitions = TableDefinitionCollection.Read(reader); | 258 | xmlTableDefinitions = TableDefinitionCollection.Read(reader, tableDefinitions); |
| 232 | break; | 259 | break; |
| 233 | default: | 260 | default: |
| 234 | throw new XmlException(); | 261 | throw new XmlException(); |
diff --git a/src/test/WixToolsetTest.Data/SerializeFixture.cs b/src/test/WixToolsetTest.Data/SerializeFixture.cs index 6e224438..198b2571 100644 --- a/src/test/WixToolsetTest.Data/SerializeFixture.cs +++ b/src/test/WixToolsetTest.Data/SerializeFixture.cs | |||
| @@ -8,8 +8,11 @@ namespace WixToolsetTest.Data | |||
| 8 | using WixToolset.Data; | 8 | using WixToolset.Data; |
| 9 | using WixToolset.Data.Bind; | 9 | using WixToolset.Data.Bind; |
| 10 | using WixToolset.Data.Tuples; | 10 | using WixToolset.Data.Tuples; |
| 11 | using WixToolset.Data.WindowsInstaller.Rows; | ||
| 11 | using Xunit; | 12 | using Xunit; |
| 12 | 13 | ||
| 14 | using Wid = WixToolset.Data.WindowsInstaller; | ||
| 15 | |||
| 13 | public class SerializeFixture | 16 | public class SerializeFixture |
| 14 | { | 17 | { |
| 15 | [Fact] | 18 | [Fact] |
| @@ -383,5 +386,42 @@ namespace WixToolsetTest.Data | |||
| 383 | File.Delete(path); | 386 | File.Delete(path); |
| 384 | } | 387 | } |
| 385 | } | 388 | } |
| 389 | |||
| 390 | [Fact] | ||
| 391 | public void CanSaveAndLoadWindowsInstallerData() | ||
| 392 | { | ||
| 393 | var sln = new SourceLineNumber("test.wxs", 1); | ||
| 394 | var windowsInstallerData = new Wid.WindowsInstallerData(sln) | ||
| 395 | { | ||
| 396 | Type = OutputType.Product, | ||
| 397 | }; | ||
| 398 | |||
| 399 | var fileTable = windowsInstallerData.EnsureTable(Wid.WindowsInstallerTableDefinitions.File); | ||
| 400 | var fileRow = (FileRow)fileTable.CreateRow(sln); | ||
| 401 | fileRow.File = "TestFile"; | ||
| 402 | |||
| 403 | var path = Path.GetTempFileName(); | ||
| 404 | try | ||
| 405 | { | ||
| 406 | using (var wixout = WixOutput.Create(path)) | ||
| 407 | { | ||
| 408 | windowsInstallerData.Save(wixout); | ||
| 409 | } | ||
| 410 | |||
| 411 | var loaded = Wid.WindowsInstallerData.Load(path); | ||
| 412 | |||
| 413 | var loadedTable = Assert.Single(loaded.Tables); | ||
| 414 | Assert.Equal(Wid.WindowsInstallerTableDefinitions.File.Name, loadedTable.Name); | ||
| 415 | |||
| 416 | var loadedRow = Assert.Single(loadedTable.Rows); | ||
| 417 | var loadedFileRow = Assert.IsType<FileRow>(loadedRow); | ||
| 418 | |||
| 419 | Assert.Equal("TestFile", loadedFileRow.File); | ||
| 420 | } | ||
| 421 | finally | ||
| 422 | { | ||
| 423 | File.Delete(path); | ||
| 424 | } | ||
| 425 | } | ||
| 386 | } | 426 | } |
| 387 | } | 427 | } |
