/// <summary> /// Parse a table from the xml. /// </summary> /// <param name="reader">XmlReader where the intermediate is persisted.</param> /// <param name="section">Section to populate with persisted data.</param> /// <param name="tableDefinitions">TableDefinitions to use in the intermediate.</param> /// <returns>The parsed table.</returns> internal static Table Parse(XmlReader reader, Section section, TableDefinitionCollection tableDefinitions) { Debug.Assert("table" == reader.LocalName); bool empty = reader.IsEmptyElement; TableOperation operation = TableOperation.None; string name = null; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "name": name = reader.Value; break; case "op": switch (reader.Value) { case "add": operation = TableOperation.Add; break; case "drop": operation = TableOperation.Drop; break; default: throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", reader.Name, reader.Value, "Add", "Drop")); } break; default: if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal)) { throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", reader.Name)); } break; } } if (null == name) { throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", "name")); } TableDefinition tableDefinition = tableDefinitions[name]; Table table = new Table(section, tableDefinition); table.Operation = operation; if (!empty) { bool done = false; // loop through all the rows in a table while (!done && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "row": Row.Parse(reader, table); break; default: throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", reader.Name)); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "table")); } } return(table); }
/// <summary> /// Parse the root library element. /// </summary> /// <param name="reader">XmlReader with library persisted as Xml.</param> /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param> /// <param name="suppressVersionCheck">Suppresses check for wix.dll version mismatch.</param> /// <returns>The parsed Library.</returns> private static Library Parse(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck) { Debug.Assert("wixLibrary" == reader.LocalName); bool empty = reader.IsEmptyElement; Library library = new Library(); Version version = null; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "version": version = new Version(reader.Value); break; default: if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal)) { throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixLibrary", reader.Name)); } break; } } if (null != version && !suppressVersionCheck) { if (0 != currentVersion.CompareTo(version)) { throw new WixException(WixErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "library", version.ToString(), currentVersion.ToString())); } } if (!empty) { bool done = false; while (!done && (XmlNodeType.Element == reader.NodeType || reader.Read())) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "section": library.sections.Add(Section.Parse(reader, tableDefinitions)); break; case "WixLocalization": Localization localization = Localization.Parse(reader, tableDefinitions, true); library.localizations.Add(localization.Culture, localization); break; default: throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixLibrary", reader.Name)); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixLibrary")); } } return(library); }
/// <summary> /// Processes an XmlReader and builds up the output object. /// </summary> /// <param name="reader">Reader to get data from.</param> /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> /// <returns>The Output represented by the Xml.</returns> internal static Output Parse(XmlReader reader, bool suppressVersionCheck) { Debug.Assert("wixOutput" == reader.LocalName); bool empty = reader.IsEmptyElement; Output output = new Output(SourceLineNumber.CreateFromUri(reader.BaseURI)); SectionType sectionType = SectionType.Unknown; Version version = null; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "codepage": output.codepage = Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture.NumberFormat); break; case "type": switch (reader.Value) { case "Bundle": output.type = OutputType.Bundle; sectionType = SectionType.Bundle; break; case "Module": output.type = OutputType.Module; sectionType = SectionType.Module; break; case "Patch": output.type = OutputType.Patch; break; case "PatchCreation": output.type = OutputType.PatchCreation; sectionType = SectionType.PatchCreation; break; case "Product": output.type = OutputType.Product; sectionType = SectionType.Product; break; case "Transform": output.type = OutputType.Transform; break; default: throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput", reader.Name, reader.Value, "Module", "Patch", "PatchCreation", "Product", "Transform")); } break; case "version": version = new Version(reader.Value); break; default: if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal)) { throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput", reader.Name)); } break; } } if (null != version && !suppressVersionCheck) { if (0 != currentVersion.CompareTo(version)) { throw new WixException(WixErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput", version.ToString(), currentVersion.ToString())); } } // create a section for all the rows to belong to output.entrySection = new Section(null, sectionType, output.codepage); TableDefinitionCollection tableDefinitions = null; // loop through the rest of the xml building up the Output object if (!empty) { bool done = false; // loop through all the fields in a row while (!done && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "subStorage": output.SubStorages.Add(SubStorage.Parse(reader)); break; case "table": if (null == tableDefinitions) { throw new WixException(WixErrors.ExpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput", "tableDefinitions")); } output.Tables.Add(Table.Parse(reader, output.entrySection, tableDefinitions)); break; case "tableDefinitions": tableDefinitions = TableDefinitionCollection.Parse(reader); break; default: throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput", reader.Name)); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput")); } } return(output); }
/// <summary> /// Parse an intermediate from an XML format. /// </summary> /// <param name="reader">XmlReader where the intermediate is persisted.</param> /// <param name="tableDefinitions">TableDefinitions to use in the intermediate.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatch.</param> /// <returns>The parsed Intermediate.</returns> internal static Intermediate Parse(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck) { Debug.Assert("wixObject" == reader.LocalName); bool empty = reader.IsEmptyElement; Version objVersion = null; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "version": objVersion = new Version(reader.Value); break; default: if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal)) { throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixObject", reader.Name)); } break; } } if (null != objVersion && !suppressVersionCheck) { if (0 != currentVersion.CompareTo(objVersion)) { throw new WixException(WixErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "object", objVersion.ToString(), currentVersion.ToString())); } } Intermediate intermediate = new Intermediate(); // loop through the rest of the xml building up the SectionCollection if (!empty) { bool done = false; while (!done && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "section": intermediate.sections.Add(Section.Parse(reader, tableDefinitions)); break; default: throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixObject", reader.Name)); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixObject")); } } return(intermediate); }
/// <summary> /// Instantiate a new Librarian class. /// </summary> public Librarian() { this.tableDefinitions = Installer.GetTableDefinitions(); }