From 2bb37beda887d120a0ddabf874ad25357101faa1 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 1 Nov 2017 10:59:45 -0700 Subject: Update to WiX Intermediate Representation --- .../ObjectField.cs | 183 +++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 src/WixToolset.Data.WindowsInstaller/ObjectField.cs (limited to 'src/WixToolset.Data.WindowsInstaller/ObjectField.cs') diff --git a/src/WixToolset.Data.WindowsInstaller/ObjectField.cs b/src/WixToolset.Data.WindowsInstaller/ObjectField.cs new file mode 100644 index 00000000..42ef111b --- /dev/null +++ b/src/WixToolset.Data.WindowsInstaller/ObjectField.cs @@ -0,0 +1,183 @@ +// 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. + +namespace WixToolset.Data +{ + using System; + using System.Diagnostics; + using System.Globalization; + using System.Xml; + + /// + /// Field containing data for an object column in a row. + /// + public sealed class ObjectField : Field + { + /// + /// Instantiates a new Field. + /// + /// Column definition for this field. + internal ObjectField(ColumnDefinition columnDefinition) : + base(columnDefinition) + { + } + + /// + /// Gets or sets the index of the embedded file in a library. + /// + /// The index of the embedded file. + public int? EmbeddedFileIndex { get; set; } + + /// + /// Gets or sets the previous index of the embedded file in the library. + /// + /// The previous index of the embedded file. + public int? PreviousEmbeddedFileIndex { get; set; } + + /// + /// Gets or sets the path to the embedded cabinet of the previous file. + /// + /// The path of the cabinet containing the previous file. + public Uri PreviousBaseUri { get; set; } + + /// + /// Gets the base URI of the object field. + /// + /// The base URI of the object field. + public Uri BaseUri { get; private set; } + + /// + /// Gets or sets the unresolved data for this field. + /// + /// Unresolved Data in the field. + public string UnresolvedData { get; set; } + + /// + /// Gets or sets the unresolved previous data. + /// + /// The unresolved previous data. + public string UnresolvedPreviousData { get; set; } + + /// + /// Parse a field from the xml. + /// + /// XmlReader where the intermediate is persisted. + internal override void Read(XmlReader reader) + { + Debug.Assert("field" == reader.LocalName); + + bool empty = reader.IsEmptyElement; + + this.BaseUri = new Uri(reader.BaseURI); + + while (reader.MoveToNextAttribute()) + { + switch (reader.LocalName) + { + case "cabinetFileId": + this.EmbeddedFileIndex = Convert.ToInt32(reader.Value); + break; + case "modified": + this.Modified = reader.Value.Equals("yes"); + break; + case "previousData": + this.PreviousData = reader.Value; + break; + case "unresolvedPreviousData": + this.UnresolvedPreviousData = reader.Value; + break; + case "unresolvedData": + this.UnresolvedData = reader.Value; + break; + case "previousCabinetFileId": + this.PreviousEmbeddedFileIndex = Convert.ToInt32(reader.Value); + break; + } + } + + if (!empty) + { + bool done = false; + + while (!done && reader.Read()) + { + switch (reader.NodeType) + { + case XmlNodeType.Element: + throw new XmlException(); + case XmlNodeType.CDATA: + case XmlNodeType.Text: + if (0 < reader.Value.Length) + { + this.Data = reader.Value; + } + break; + case XmlNodeType.EndElement: + done = true; + break; + } + } + + if (!done) + { + throw new XmlException(); + } + } + } + + /// + /// Persists a field in an XML format. + /// + /// XmlWriter where the Field should persist itself as XML. + internal override void Write(XmlWriter writer) + { + writer.WriteStartElement("field", Intermediate.XmlNamespaceUri); + + if (this.EmbeddedFileIndex.HasValue) + { + writer.WriteStartAttribute("cabinetFileId"); + writer.WriteValue(this.EmbeddedFileIndex); + writer.WriteEndAttribute(); + } + + if (this.Modified) + { + writer.WriteAttributeString("modified", "yes"); + } + + if (null != this.UnresolvedPreviousData) + { + writer.WriteAttributeString("unresolvedPreviousData", this.UnresolvedPreviousData); + } + + if (null != this.PreviousData) + { + writer.WriteAttributeString("previousData", this.PreviousData); + } + + if (null != this.UnresolvedData) + { + writer.WriteAttributeString("unresolvedData", this.UnresolvedData); + } + + if (this.PreviousEmbeddedFileIndex.HasValue) + { + writer.WriteStartAttribute("previousCabinetFileId"); + writer.WriteValue(this.PreviousEmbeddedFileIndex); + writer.WriteEndAttribute(); + } + + // Convert the data to a string that will persist nicely (nulls as String.Empty). + string text = Convert.ToString(this.Data, CultureInfo.InvariantCulture); + if (this.Column.UseCData) + { + writer.WriteCData(text); + } + else + { + writer.WriteString(text); + } + + writer.WriteEndElement(); + } + } +} -- cgit v1.2.3-55-g6feb