Ejemplo n.º 1
0
        /// <summary>
        /// Reads a media row entry out of the xml.
        /// </summary>
        /// <param name="output">Output object to add the row.</param>
        /// <param name="reader">Reader to get data from.</param>
        private static void ParseMedia(Output output, XmlReader reader)
        {
            Debug.Assert("media" == reader.LocalName);

            TableDefinition mediaTableDefinition = null;
            bool            empty = reader.IsEmptyElement;

            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 "tableDefinition":
                            mediaTableDefinition = TableDefinition.Parse(reader);
                            break;

                        case "tuple":
                            if (null == mediaTableDefinition)
                            {
                                throw new WixParseException("The merge element is missing a tableDefinition child element.");
                            }
                            output.mediaRows.Add((MediaRow)Row.Parse(reader, output.entrySection, mediaTableDefinition));
                            break;

                        default:
                            throw new WixParseException(String.Format("The media element contains an unexpected child element {0}.", reader.Name));
                        }
                        break;

                    case XmlNodeType.EndElement:
                        done = true;
                        break;
                    }
                }

                if (!done)
                {
                    throw new WixParseException("Missing end element while processing the media element.");
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes an XmlReader and builds up the output table object.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="section">Section to add loaded rows into.</param>
        /// <returns>Output table.</returns>
        internal static OutputTable Parse(XmlReader reader, Section section)
        {
            Debug.Assert("outputTable" == reader.LocalName);

            string name  = null;
            bool   empty = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "name":
                    name = reader.Value;
                    break;

                default:
                    throw new WixParseException(String.Format("The outputTable element contains an unexpected attribute {0}.", reader.Name));
                }
            }
            if (null == name)
            {
                throw new WixParseException("The outputTable/@name attribute was not found; it is required.");
            }

            OutputTable outputTable = null;

            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 "tableDefinition":
                            outputTable = new OutputTable(TableDefinition.Parse(reader));
                            break;

                        case "tuple":
                            if (null == outputTable)
                            {
                                throw new WixParseException("The outputTable element is missing a tableDefinition child element.");
                            }
                            outputTable.outputRows.Add(new OutputRow(Row.Parse(reader, section, outputTable.tableDef)));
                            break;

                        default:
                            throw new WixParseException(String.Format("The outputTable element contains an unexpected child element {0}.", reader.Name));
                        }
                        break;

                    case XmlNodeType.EndElement:
                        done = true;
                        break;
                    }
                }

                if (!done)
                {
                    throw new WixParseException("Missing end element while processing the outputTable element.");
                }
            }

            return(outputTable);
        }
Ejemplo n.º 3
0
        /// <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(SourceLineNumberCollection.FromUri(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(SourceLineNumberCollection.FromUri(reader.BaseURI), "table", reader.Name));
                    }
                    break;
                }
            }

            if (null == name)
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumberCollection.FromUri(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(SourceLineNumberCollection.FromUri(reader.BaseURI), "table", reader.Name));
                        }
                        break;

                    case XmlNodeType.EndElement:
                        done = true;
                        break;
                    }
                }

                if (!done)
                {
                    throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumberCollection.FromUri(reader.BaseURI), "table"));
                }
            }

            return(table);
        }