Example #1
0
        /// <summary>
        /// Parses table definition from xml reader.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <returns>The TableDefintion represented by the Xml.</returns>
        internal static TableDefinition Parse(XmlReader reader)
        {
            Debug.Assert("tableDefinition" == reader.LocalName);

            bool   empty               = reader.IsEmptyElement;
            bool   createSymbols       = false;
            bool   hasPrimaryKeyColumn = false;
            string name   = null;
            bool   unreal = false;
            bool   bootstrapperApplicationData = false;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "createSymbols":
                    createSymbols = Common.IsYes(SourceLineNumberCollection.FromUri(reader.BaseURI), "createSymbols", reader.Name, reader.Value);
                    break;

                case "name":
                    name = reader.Value;
                    break;

                case "unreal":
                    unreal = Common.IsYes(SourceLineNumberCollection.FromUri(reader.BaseURI), "tableDefinition", reader.Name, reader.Value);
                    break;

                case "bootstrapperApplicationData":
                    bootstrapperApplicationData = Common.IsYes(SourceLineNumberCollection.FromUri(reader.BaseURI), "tableDefinition", reader.Name, reader.Value);
                    break;

                default:
                    if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal))
                    {
                        throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumberCollection.FromUri(reader.BaseURI), "tableDefinition", reader.Name));
                    }
                    break;
                }
            }

            if (null == name)
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumberCollection.FromUri(reader.BaseURI), "tableDefinition", "name"));
            }

            TableDefinition tableDefinition = new TableDefinition(name, createSymbols, unreal, bootstrapperApplicationData);

            // parse the child elements
            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "columnDefinition":
                            ColumnDefinition columnDefinition = ColumnDefinition.Parse(reader);
                            tableDefinition.columns.Add(columnDefinition);

                            if (columnDefinition.IsLocalizable)
                            {
                                tableDefinition.localizable = true;
                            }

                            if (columnDefinition.IsPrimaryKey)
                            {
                                hasPrimaryKeyColumn = true;
                            }
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumberCollection.FromUri(reader.BaseURI), "tableDefinition", reader.Name));
                        }
                        break;

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

                if (!unreal && !bootstrapperApplicationData && !hasPrimaryKeyColumn)
                {
                    throw new WixException(WixErrors.RealTableMissingPrimaryKeyColumn(SourceLineNumberCollection.FromUri(reader.BaseURI), name));
                }

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

            return(tableDefinition);
        }
Example #2
0
        /// <summary>
        /// Parses table definition from xml reader.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <returns>The TableDefintion represented by the Xml.</returns>
        internal static TableDefinition Parse(XmlReader reader)
        {
            Debug.Assert("tableDefinition" == reader.LocalName);

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

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

                case "unreal":
                    unreal = Common.IsYes(reader.Value, null, "tableDefinition", reader.Name, name);
                    break;

                case "xmlns":
                    break;

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

            if (null == name)
            {
                throw new WixParseException("The tableDefinition/@name attribute was not found; it is required.");
            }

            TableDefinition tableDefinition = new TableDefinition(name, unreal);

            // parse the child elements
            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "columnDefinition":
                            tableDefinition.columns.Add(ColumnDefinition.Parse(reader));
                            break;

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

            return(tableDefinition);
        }