Ejemplo n.º 1
0
        /// <summary>
        /// Parse a tuple from the xml.
        /// </summary>
        /// <param name="intermediate">Intermediate to populate with persisted data.</param>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        /// <param name="section">Section to populate with persisted data.</param>
        /// <param name="tableDef">Table definition of the tuple to parse.</param>
        private static void ParseTuple(Intermediate intermediate, XmlReader reader, Section section, TableDefinition tableDef)
        {
            bool empty = reader.IsEmptyElement;
            SourceLineNumberCollection sourceLineNumbers = null;
            int field = 0;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "sourceLineNumber":
                    sourceLineNumbers = new SourceLineNumberCollection(reader.Value);
                    break;
                }
            }

            Row row = Common.CreateRowInSection(sourceLineNumbers, section, tableDef);

            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 "field":
                            row[field] = Field.Parse(reader);
                            ++field;
                            break;

                        default:
                            throw new WixInvalidIntermediateException(SourceLineNumberCollection.FromFileName(intermediate.Path), String.Format("Unexpected element while processing 'tuple': '{0}'", reader.LocalName));
                        }
                        break;

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

                if (!done)
                {
                    throw new WixInvalidIntermediateException(SourceLineNumberCollection.FromFileName(intermediate.Path), String.Format("Missing end element while processing 'tuple'."));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a Row from the XmlReader
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="section">Section the row is added to.</param>
        /// <param name="tableDef">Table definition for this row.</param>
        /// <returns>New row object.</returns>
        internal static Row Parse(XmlReader reader, Section section, TableDefinition tableDef)
        {
            Debug.Assert("tuple" == reader.LocalName);

            bool   empty     = reader.IsEmptyElement;
            string sectionId = null;
            SourceLineNumberCollection sourceLineNumbers = null;

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

                case "sourceLineNumber":
                    sourceLineNumbers = new SourceLineNumberCollection(reader.Value);
                    break;

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

            Row row = Common.CreateRowInSection(sourceLineNumbers, section, tableDef);

            row.sectionId = sectionId;

            // loop through all the fields in a row
            if (!empty)
            {
                bool done  = false;
                int  field = 0;

                // loop through all the fields in a row
                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "field":
                            if (row.Fields.Length <= field)
                            {
                                throw new WixParseException(String.Format("This tuple has more fields for table '{0}' than are defined. This is potentially because a standard table is being redefined as a custom table.", tableDef.Name));
                            }
                            row[field] = Field.Parse(reader);
                            ++field;
                            break;

                        default:
                            throw new WixParseException(String.Format("The tuple 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 tuple element.");
                }
            }

            return(row);
        }