/// <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(SourceLineNumberCollection.FromUri(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 "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(SourceLineNumberCollection.FromUri(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/")) { throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumberCollection.FromUri(reader.BaseURI), "wixOutput", reader.Name)); } break; } } if (null != version && !suppressVersionCheck) { if (0 != currentVersion.CompareTo(version)) { throw new WixException(WixErrors.VersionMismatch(SourceLineNumberCollection.FromUri(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(SourceLineNumberCollection.FromUri(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(SourceLineNumberCollection.FromUri(reader.BaseURI), "wixOutput", reader.Name)); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumberCollection.FromUri(reader.BaseURI), "wixOutput")); } } return(output); }
/// <summary> /// Parse a section from the xml. /// </summary> /// <param name="reader">XmlReader where the intermediate is persisted.</param> /// <param name="tableDefinitions">TableDefinitions to use in the intermediate.</param> /// <returns>The parsed Section.</returns> internal static Section Parse(XmlReader reader, TableDefinitionCollection tableDefinitions) { Debug.Assert("section" == reader.LocalName); int codepage = 0; bool empty = reader.IsEmptyElement; string id = null; Section section = null; SectionType type = SectionType.Unknown; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "codepage": codepage = Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture); break; case "id": id = reader.Value; break; case "type": switch (reader.Value) { case "fragment": type = SectionType.Fragment; break; case "module": type = SectionType.Module; break; case "patchCreation": type = SectionType.PatchCreation; break; case "product": type = SectionType.Product; break; case "patch": type = SectionType.Patch; break; default: throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumberCollection.FromUri(reader.BaseURI), "section", reader.Name, reader.Value, "fragment", "module", "patchCreation", "product", "patch")); } break; default: if (!reader.NamespaceURI.StartsWith("http://www.w3.org/")) { throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumberCollection.FromUri(reader.BaseURI), "section", reader.Name)); } break; } } if (null == id && (SectionType.Unknown != type && SectionType.Fragment != type)) { throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumberCollection.FromUri(reader.BaseURI), "section", "id", "type", type.ToString())); } if (SectionType.Unknown == type) { throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumberCollection.FromUri(reader.BaseURI), "section", "type")); } section = new Section(id, type, codepage); section.sourceLineNumbers = SourceLineNumberCollection.FromUri(reader.BaseURI); if (!empty) { bool done = false; while (!done && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "table": section.Tables.Add(Table.Parse(reader, section, tableDefinitions)); break; default: throw new WixException(WixErrors.UnexpectedElement(SourceLineNumberCollection.FromUri(reader.BaseURI), "section", reader.Name)); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumberCollection.FromUri(reader.BaseURI), "section")); } } return(section); }