Пример #1
0
        /// <summary>
        /// Parses ActionRows from the Xml reader.
        /// </summary>
        /// <param name="reader">Xml reader that contains serialized ActionRows.</param>
        /// <returns>The parsed ActionRows.</returns>
        internal static WixActionRow[] Parse(XmlReader reader)
        {
            Debug.Assert("action" == reader.LocalName);

            string id            = null;
            string condition     = null;
            bool   empty         = reader.IsEmptyElement;
            int    sequence      = int.MinValue;
            int    sequenceCount = 0;

            SequenceTable[] sequenceTables = new SequenceTable[Enum.GetValues(typeof(SequenceTable)).Length];

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

                case "AdminExecuteSequence":
                    if (Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", reader.Name, reader.Value))
                    {
                        sequenceTables[sequenceCount] = SequenceTable.AdminExecuteSequence;
                        ++sequenceCount;
                    }
                    break;

                case "AdminUISequence":
                    if (Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", reader.Name, reader.Value))
                    {
                        sequenceTables[sequenceCount] = SequenceTable.AdminUISequence;
                        ++sequenceCount;
                    }
                    break;

                case "AdvtExecuteSequence":
                    if (Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", reader.Name, reader.Value))
                    {
                        sequenceTables[sequenceCount] = SequenceTable.AdvtExecuteSequence;
                        ++sequenceCount;
                    }
                    break;

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

                case "InstallExecuteSequence":
                    if (Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", reader.Name, reader.Value))
                    {
                        sequenceTables[sequenceCount] = SequenceTable.InstallExecuteSequence;
                        ++sequenceCount;
                    }
                    break;

                case "InstallUISequence":
                    if (Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", reader.Name, reader.Value))
                    {
                        sequenceTables[sequenceCount] = SequenceTable.InstallUISequence;
                        ++sequenceCount;
                    }
                    break;

                case "sequence":
                    sequence = Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture);
                    break;

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

            if (null == id)
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", "name"));
            }

            if (int.MinValue == sequence)
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", "sequence"));
            }
            else if (1 > sequence)
            {
                throw new WixException(WixErrors.IntegralValueOutOfRange(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", "sequence", sequence, 1, int.MaxValue));
            }

            if (0 == sequenceCount)
            {
                throw new WixException(WixErrors.ExpectedAttributes(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", "AdminExecuteSequence", "AdminUISequence", "AdvtExecuteSequence", "InstallExecuteSequence", "InstallUISequence"));
            }

            if (!empty && reader.Read() && XmlNodeType.EndElement != reader.MoveToContent())
            {
                throw new WixException(WixErrors.UnexpectedContentNode(SourceLineNumber.CreateFromUri(reader.BaseURI), "action", reader.NodeType.ToString()));
            }

            // create the actions
            WixActionRow[] actionRows = new WixActionRow[sequenceCount];
            for (int i = 0; i < sequenceCount; i++)
            {
                WixActionRow actionRow = new WixActionRow(sequenceTables[i], id, condition, sequence);
                actionRows[i] = actionRow;
            }

            return(actionRows);
        }
Пример #2
0
        /// <summary>
        /// Parses a column definition in a table definition.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <returns>The ColumnDefintion represented by the Xml.</returns>
        internal static ColumnDefinition Parse(XmlReader reader)
        {
            Debug.Assert("columnDefinition" == reader.LocalName);

            bool                 added               = false;
            ColumnCategory       category            = ColumnCategory.Unknown;
            string               description         = null;
            bool                 empty               = reader.IsEmptyElement;
            bool                 escapeIdtCharacters = false;
            int                  keyColumn           = -1;
            bool                 keyColumnSet        = false;
            string               keyTable            = null;
            int                  length              = -1;
            bool                 localizable         = false;
            int                  maxValue            = 0;
            bool                 maxValueSet         = false;
            int                  minValue            = 0;
            bool                 minValueSet         = false;
            ColumnModularizeType modularize          = ColumnModularizeType.None;
            string               name          = null;
            bool                 nullable      = false;
            string               possibilities = null;
            bool                 primaryKey    = false;
            ColumnType           type          = ColumnType.Unknown;
            bool                 useCData      = false;

            // parse the attributes
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "added":
                    added = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value);
                    break;

                case "category":
                    switch (reader.Value)
                    {
                    case "anyPath":
                        category = ColumnCategory.AnyPath;
                        break;

                    case "binary":
                        category = ColumnCategory.Binary;
                        break;

                    case "cabinet":
                        category = ColumnCategory.Cabinet;
                        break;

                    case "condition":
                        category = ColumnCategory.Condition;
                        break;

                    case "customSource":
                        category = ColumnCategory.CustomSource;
                        break;

                    case "defaultDir":
                        category = ColumnCategory.DefaultDir;
                        break;

                    case "doubleInteger":
                        category = ColumnCategory.DoubleInteger;
                        break;

                    case "filename":
                        category = ColumnCategory.Filename;
                        break;

                    case "formatted":
                        category = ColumnCategory.Formatted;
                        break;

                    case "formattedSddl":
                        category = ColumnCategory.FormattedSDDLText;
                        break;

                    case "guid":
                        category = ColumnCategory.Guid;
                        break;

                    case "identifier":
                        category = ColumnCategory.Identifier;
                        break;

                    case "integer":
                        category = ColumnCategory.Integer;
                        break;

                    case "language":
                        category = ColumnCategory.Language;
                        break;

                    case "lowerCase":
                        category = ColumnCategory.LowerCase;
                        break;

                    case "path":
                        category = ColumnCategory.Path;
                        break;

                    case "paths":
                        category = ColumnCategory.Paths;
                        break;

                    case "property":
                        category = ColumnCategory.Property;
                        break;

                    case "regPath":
                        category = ColumnCategory.RegPath;
                        break;

                    case "shortcut":
                        category = ColumnCategory.Shortcut;
                        break;

                    case "template":
                        category = ColumnCategory.Template;
                        break;

                    case "text":
                        category = ColumnCategory.Text;
                        break;

                    case "timeDate":
                        category = ColumnCategory.TimeDate;
                        break;

                    case "upperCase":
                        category = ColumnCategory.UpperCase;
                        break;

                    case "version":
                        category = ColumnCategory.Version;
                        break;

                    case "wildCardFilename":
                        category = ColumnCategory.WildCardFilename;
                        break;

                    default:
                        throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value, "anyPath", "binary", "cabinet", "condition", "customSource", "defaultDir", "doubleInteger", "filename", "formatted", "formattedSddl", "guid", "identifier", "integer", "language", "lowerCase", "path", "paths", "property", "regPath", "shortcut", "template", "text", "timeDate", "upperCase", "version", "wildCardFilename"));
                    }
                    break;

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

                case "escapeIdtCharacters":
                    escapeIdtCharacters = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value);
                    break;

                case "keyColumn":
                    keyColumnSet = true;
                    keyColumn    = Convert.ToInt32(reader.Value, 10);
                    break;

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

                case "length":
                    length = Convert.ToInt32(reader.Value, 10);
                    break;

                case "localizable":
                    localizable = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value);
                    break;

                case "maxValue":
                    maxValueSet = true;
                    maxValue    = Convert.ToInt32(reader.Value, 10);
                    break;

                case "minValue":
                    minValueSet = true;
                    minValue    = Convert.ToInt32(reader.Value, 10);
                    break;

                case "modularize":
                    switch (reader.Value)
                    {
                    case "column":
                        modularize = ColumnModularizeType.Column;
                        break;

                    case "companionFile":
                        modularize = ColumnModularizeType.CompanionFile;
                        break;

                    case "condition":
                        modularize = ColumnModularizeType.Condition;
                        break;

                    case "controlEventArgument":
                        modularize = ColumnModularizeType.ControlEventArgument;
                        break;

                    case "controlText":
                        modularize = ColumnModularizeType.ControlText;
                        break;

                    case "icon":
                        modularize = ColumnModularizeType.Icon;
                        break;

                    case "none":
                        modularize = ColumnModularizeType.None;
                        break;

                    case "property":
                        modularize = ColumnModularizeType.Property;
                        break;

                    case "semicolonDelimited":
                        modularize = ColumnModularizeType.SemicolonDelimited;
                        break;

                    default:
                        throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value, "column", "companionFile", "condition", "controlEventArgument", "controlText", "icon", "property", "semicolonDelimited"));
                    }
                    break;

                case "name":
                    switch (reader.Value)
                    {
                    case "CREATE":
                    case "DELETE":
                    case "DROP":
                    case "INSERT":
                        throw new WixException(WixErrors.IllegalColumnName(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value));

                    default:
                        name = reader.Value;
                        break;
                    }
                    break;

                case "nullable":
                    nullable = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value);
                    break;

                case "primaryKey":
                    primaryKey = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value);
                    break;

                case "set":
                    possibilities = reader.Value;
                    break;

                case "type":
                    switch (reader.Value)
                    {
                    case "localized":
                        type = ColumnType.Localized;
                        break;

                    case "number":
                        type = ColumnType.Number;
                        break;

                    case "object":
                        type = ColumnType.Object;
                        break;

                    case "string":
                        type = ColumnType.String;
                        break;

                    case "preserved":
                        type = ColumnType.Preserved;
                        break;

                    default:
                        throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value, "localized", "number", "object", "string"));
                    }
                    break;

                case "useCData":
                    useCData = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name, reader.Value);
                    break;

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

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

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition", reader.Name));

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

                if (!done)
                {
                    throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "columnDefinition"));
                }
            }

            ColumnDefinition columnDefinition = new ColumnDefinition(name, type, length, primaryKey, nullable, modularize, localizable, minValueSet, minValue, maxValueSet, maxValue, keyTable, keyColumnSet, keyColumn, category, possibilities, description, escapeIdtCharacters, useCData);

            columnDefinition.Added = added;

            return(columnDefinition);
        }
Пример #3
0
        /// <summary>
        /// Parse a field from the xml.
        /// </summary>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        internal override void Parse(XmlReader reader)
        {
            Debug.Assert("field" == reader.LocalName);

            bool empty = reader.IsEmptyElement;

            this.baseUri = reader.BaseURI;

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

                case "modified":
                    this.Modified = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "field", reader.Name, reader.Value);
                    break;

                case "previousData":
                    this.PreviousData = reader.Value;
                    break;

                case "unresolvedPreviousData":
                    this.unresolvedPreviousData = reader.Value;
                    break;

                case "unresolvedData":
                    this.unresolvedData = reader.Value;
                    break;

                case "previousCabinetFileId":
                    this.previousCabinetFileId = reader.Value;
                    break;

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

            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "field", reader.Name));

                    case XmlNodeType.CDATA:
                    case XmlNodeType.Text:
                        if (0 < reader.Value.Length)
                        {
                            this.Data = reader.Value;
                        }
                        break;

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

                if (!done)
                {
                    throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "field"));
                }
            }
        }
Пример #4
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(SourceLineNumber.CreateFromUri(reader.BaseURI), "createSymbols", reader.Name, reader.Value);
                    break;

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

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

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

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

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

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

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

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

            return(tableDefinition);
        }
Пример #5
0
        /// <summary>
        /// Parse a field from the xml.
        /// </summary>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        internal virtual void Parse(XmlReader reader)
        {
            Debug.Assert("field" == reader.LocalName);

            bool empty = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "modified":
                    this.modified = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "field", reader.Name, reader.Value);
                    break;

                case "previousData":
                    this.previousData = reader.Value;
                    break;

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

            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "field", reader.Name));

                    case XmlNodeType.CDATA:
                    case XmlNodeType.Text:
                    case XmlNodeType.SignificantWhitespace:
                        if (0 < reader.Value.Length)
                        {
                            if (ColumnType.Number == this.columnDefinition.Type && !this.columnDefinition.IsLocalizable)
                            {
                                // older wix files could persist data as a long value (which would overflow an int)
                                // since the Convert class always throws exceptions for overflows, read in integral
                                // values as a long to avoid the overflow, then cast it to an int (this operation can
                                // overflow without throwing an exception inside an unchecked block)
                                this.data = unchecked ((int)Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture));
                            }
                            else
                            {
                                this.data = reader.Value;
                            }
                        }
                        break;

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

                if (!done)
                {
                    throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "field"));
                }
            }
        }