Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new action table object and populates it from an Xml reader.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <returns>The parsed ActionTable.</returns>
        private static WixActionRowCollection Parse(XmlReader reader)
        {
            Debug.Assert("actions" == reader.LocalName);

            WixActionRowCollection actionRows = new WixActionRowCollection();
            bool empty = reader.IsEmptyElement;

            // there are no legal attributes
            while (reader.MoveToNextAttribute())
            {
                if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal))
                {
                    throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "actions", reader.Name));
                }
            }

            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 "action":
                            WixActionRow[] parsedActionRows = WixActionRow.Parse(reader);

                            foreach (WixActionRow actionRow in parsedActionRows)
                            {
                                actionRows.Add(actionRow);
                            }
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "actions", reader.Name));
                        }
                        break;

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

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

            return(actionRows);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads a library from a path on disk.
        /// </summary>
        /// <param name="stream">Stream containing the library file.</param>
        /// <param name="uri">Uri for finding this stream.</param>
        /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
        /// <returns>Returns the loaded library.</returns>
        /// <remarks>This method will set the Path and SourcePath properties to the appropriate values on successful load.</remarks>
        internal static Library Load(Stream stream, Uri uri, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck, bool suppressSchema)
        {
            XmlReader reader = null;

            // look for the Microsoft cabinet file header and skip past the cabinet data if found
            if ('M' == stream.ReadByte() && 'S' == stream.ReadByte() && 'C' == stream.ReadByte() && 'F' == stream.ReadByte())
            {
                long   offset       = 0;
                byte[] offsetBuffer = new byte[4];

                // skip the header checksum
                stream.Seek(4, SeekOrigin.Current);

                // read the cabinet file size
                stream.Read(offsetBuffer, 0, 4);
                offset = BitConverter.ToInt32(offsetBuffer, 0);

                // seek past the cabinet file to the xml
                stream.Seek(offset, SeekOrigin.Begin);
            }
            else // plain xml file - start reading xml at the beginning of the stream
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            // read the xml
            try
            {
                reader = new XmlTextReader(uri.AbsoluteUri, stream);
                reader.MoveToContent();

                if ("wixLibrary" != reader.LocalName)
                {
                    throw new WixNotLibraryException(WixErrors.InvalidDocumentElement(SourceLineNumber.CreateFromUri(reader.BaseURI), reader.Name, "library", "wixLibrary"));
                }

                return(Parse(reader, tableDefinitions, suppressVersionCheck));
            }
            catch (XmlException xe)
            {
                throw new WixException(WixErrors.InvalidXml(SourceLineNumber.CreateFromUri(reader.BaseURI), "object", xe.Message));
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                }
            }
        }
        /// <summary>
        /// Loads a collection of table definitions from a XmlReader in memory.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <returns>The TableDefinitionCollection represented by the xml.</returns>
        internal static TableDefinitionCollection Parse(XmlReader reader)
        {
            Debug.Assert("tableDefinitions" == reader.LocalName);

            bool empty = reader.IsEmptyElement;
            TableDefinitionCollection tableDefinitionCollection = new TableDefinitionCollection();

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

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

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

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "tableDefinitions", reader.Name));
                        }
                        break;

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

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

            return(tableDefinitionCollection);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Loads a localization file from a stream.
 /// </summary>
 /// <param name="stream">Stream containing the localization file.</param>
 /// <param name="uri">Uri for finding this stream.</param>
 /// <param name="tableDefinitions">Collection containing TableDefinitions to use when loading the localization file.</param>
 /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
 /// <returns>Returns the loaded localization file.</returns>
 internal static Localization Load(Stream stream, Uri uri, TableDefinitionCollection tableDefinitions, bool suppressSchema)
 {
     try
     {
         using (XmlReader reader = XmlReader.Create(stream, null, uri.AbsoluteUri))
         {
             return(Localization.Parse(reader, tableDefinitions, false));
         }
     }
     catch (XmlException xe)
     {
         throw new WixException(WixErrors.InvalidXml(SourceLineNumber.CreateFromUri(uri.AbsoluteUri), "localization", xe.Message));
     }
     catch (XmlSchemaException xse)
     {
         throw new WixException(WixErrors.SchemaValidationFailed(SourceLineNumber.CreateFromUri(uri.AbsoluteUri), xse.Message, xse.LineNumber, xse.LinePosition));
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Load an action table from an XmlReader.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
        /// <returns>The ActionRowCollection represented by the xml.</returns>
        internal static WixActionRowCollection Load(XmlReader reader, bool suppressSchema)
        {
            if (null == reader)
            {
                throw new ArgumentNullException("reader");
            }

            if (!suppressSchema)
            {
                reader = new XmlValidatingReader(reader);
                ((XmlValidatingReader)reader).Schemas.Add(GetSchemas());
            }

            reader.MoveToContent();

            if ("actions" != reader.LocalName)
            {
                throw new WixException(WixErrors.InvalidDocumentElement(SourceLineNumber.CreateFromUri(reader.BaseURI), reader.Name, "actions", "actions"));
            }

            return(Parse(reader));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads an intermediate from a path on disk.
        /// </summary>
        /// <param name="path">Path to intermediate file saved on disk.</param>
        /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediate.</param>
        /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param>
        /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
        /// <returns>Returns the loaded intermediate.</returns>
        public static Intermediate Load(string path, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck, bool suppressSchema)
        {
            XmlReader reader = null;

            try
            {
                reader = new XmlTextReader(path);

                if (!suppressSchema)
                {
                    reader = new XmlValidatingReader(reader);
                    ((XmlValidatingReader)reader).Schemas.Add(GetSchemas());
                }

                reader.MoveToContent();

                if ("wixObject" != reader.LocalName)
                {
                    throw new WixNotIntermediateException(WixErrors.InvalidDocumentElement(SourceLineNumber.CreateFromUri(reader.BaseURI), reader.Name, "object", "wixObject"));
                }

                return(Parse(reader, tableDefinitions, suppressVersionCheck));
            }
            catch (XmlException xe)
            {
                throw new WixNotIntermediateException(WixErrors.InvalidXml(SourceLineNumber.CreateFromUri(reader.BaseURI), "object", xe.Message));
            }
            catch (XmlSchemaException xse)
            {
                throw new WixNotIntermediateException(WixErrors.SchemaValidationFailed(SourceLineNumber.CreateFromUri(reader.BaseURI), xse.Message, xse.LineNumber, xse.LinePosition));
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                }
            }
        }
        /// <summary>
        /// Load a table definition collection from an XmlReader.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
        /// <returns>The TableDefinitionCollection represented by the xml.</returns>
        public static TableDefinitionCollection Load(XmlReader reader, bool suppressSchema)
        {
            if (null == reader)
            {
                throw new ArgumentNullException("reader");
            }

            if (!suppressSchema)
            {
                // validate the table definitions xml against its schema in debug
                reader = new XmlValidatingReader(reader);
                ((XmlValidatingReader)reader).Schemas.Add(GetSchemas());
            }

            reader.MoveToContent();

            if ("tableDefinitions" != reader.LocalName)
            {
                throw new WixException(WixErrors.InvalidDocumentElement(SourceLineNumber.CreateFromUri(reader.BaseURI), reader.Name, "table definitions", "tableDefinitions"));
            }

            return(Parse(reader));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads a pdb from a path on disk.
        /// </summary>
        /// <param name="stream">Stream containing the pdb file.</param>
        /// <param name="uri">Uri for finding this stream.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
        /// <returns>Returns the loaded pdb.</returns>
        /// <remarks>This method will set the Path and SourcePath properties to the appropriate values on successful load.</remarks>
        internal static Pdb Load(Stream stream, Uri uri, bool suppressVersionCheck, bool suppressSchema)
        {
            XmlReader reader  = null;
            string    cabPath = null;

            // look for the Microsoft cabinet file header and save the cabinet data if found
            if ('M' == stream.ReadByte() && 'S' == stream.ReadByte() && 'C' == stream.ReadByte() && 'F' == stream.ReadByte())
            {
                long   cabFileSize  = 0;
                byte[] offsetBuffer = new byte[4];
                using (TempFileCollection tempFileCollection = new TempFileCollection())
                {
                    cabPath = tempFileCollection.AddExtension("cab", true);
                }

                // skip the header checksum
                stream.Seek(4, SeekOrigin.Current);

                // get the cabinet file size
                stream.Read(offsetBuffer, 0, 4);
                cabFileSize = BitConverter.ToInt32(offsetBuffer, 0);

                stream.Seek(0, SeekOrigin.Begin);

                // Create the cab file from stream
                using (FileStream fs = File.Create(cabPath))
                {
                    for (int i = 0; i < cabFileSize; i++)
                    {
                        fs.WriteByte((byte)stream.ReadByte());
                    }
                }
            }
            else // plain xml file - start reading xml at the beginning of the stream
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            // read the xml
            try
            {
                reader = new XmlTextReader(uri.AbsoluteUri, stream);

                if (!suppressSchema)
                {
                    reader = new XmlValidatingReader(reader);
                    ((XmlValidatingReader)reader).Schemas.Add(GetSchemas());
                }

                reader.MoveToContent();

                if ("wixPdb" != reader.LocalName)
                {
                    throw new WixNotOutputException(WixErrors.InvalidDocumentElement(SourceLineNumber.CreateFromUri(reader.BaseURI), reader.Name, "pdb", "wixPdb"));
                }

                Pdb pdb = Parse(reader, suppressVersionCheck);

                if (null != cabPath)
                {
                    if (pdb.Output.TempFiles == null)
                    {
                        pdb.Output.TempFiles = new TempFileCollection();
                    }

                    pdb.Output.TempFiles.AddFile(cabPath, false);
                }

                return(pdb);
            }
            catch (XmlException xe)
            {
                throw new WixException(WixErrors.InvalidXml(SourceLineNumber.CreateFromUri(reader.BaseURI), "output", xe.Message));
            }
            catch (XmlSchemaException xse)
            {
                throw new WixException(WixErrors.SchemaValidationFailed(SourceLineNumber.CreateFromUri(reader.BaseURI), xse.Message, xse.LineNumber, xse.LinePosition));
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Processes an XmlReader and builds up the pdb object.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <returns>The Pdb represented by the Xml.</returns>
        internal static Pdb Parse(XmlReader reader, bool suppressVersionCheck)
        {
            Debug.Assert("wixPdb" == reader.LocalName);

            bool    empty   = reader.IsEmptyElement;
            Pdb     pdb     = new Pdb(SourceLineNumber.CreateFromUri(reader.BaseURI));
            Version version = null;

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

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

            if (null != version)
            {
                if (0 != currentVersion.CompareTo(version))
                {
                    throw new WixException(WixErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixPdb", version.ToString(), currentVersion.ToString()));
                }
            }

            // loop through the rest of the pdb 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 "wixOutput":
                            pdb.output = Output.Parse(reader, suppressVersionCheck);
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixPdb", reader.Name));
                        }
                        break;

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

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

            return(pdb);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Parse the root library element.
        /// </summary>
        /// <param name="reader">XmlReader with library persisted as Xml.</param>
        /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param>
        /// <param name="suppressVersionCheck">Suppresses check for wix.dll version mismatch.</param>
        /// <returns>The parsed Library.</returns>
        private static Library Parse(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck)
        {
            Debug.Assert("wixLibrary" == reader.LocalName);

            bool    empty   = reader.IsEmptyElement;
            Library library = new Library();
            Version version = null;

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

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

            if (null != version && !suppressVersionCheck)
            {
                if (0 != currentVersion.CompareTo(version))
                {
                    throw new WixException(WixErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "library", version.ToString(), currentVersion.ToString()));
                }
            }

            if (!empty)
            {
                bool done = false;

                while (!done && (XmlNodeType.Element == reader.NodeType || reader.Read()))
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "section":
                            library.sections.Add(Section.Parse(reader, tableDefinitions));
                            break;

                        case "WixLocalization":
                            Localization localization = Localization.Parse(reader, tableDefinitions, true);
                            library.localizations.Add(localization.Culture, localization);
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixLibrary", reader.Name));
                        }
                        break;

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

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

            return(library);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a Row from the XmlReader.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="table">Table for this row.</param>
        /// <returns>New row object.</returns>
        internal static Row Parse(XmlReader reader, Table table)
        {
            Debug.Assert("row" == reader.LocalName);

            bool             empty             = reader.IsEmptyElement;
            RowOperation     operation         = RowOperation.None;
            string           sectionId         = null;
            SourceLineNumber sourceLineNumbers = null;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "op":
                    switch (reader.Value)
                    {
                    case "add":
                        operation = RowOperation.Add;
                        break;

                    case "delete":
                        operation = RowOperation.Delete;
                        break;

                    case "modify":
                        operation = RowOperation.Modify;
                        break;

                    default:
                        throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumber.CreateFromUri(reader.BaseURI), "row", reader.Name, reader.Value, "Add", "Delete", "Modify"));
                    }
                    break;

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

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

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

            Row row = table.CreateRow(sourceLineNumbers);

            row.Operation = operation;
            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)
                            {
                                if (!reader.IsEmptyElement)
                                {
                                    throw new WixException(WixErrors.UnexpectedColumnCount(SourceLineNumber.CreateFromUri(reader.BaseURI), table.Name));
                                }
                            }
                            else
                            {
                                row.fields[field].Parse(reader);
                            }
                            ++field;
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "row", reader.Name));
                        }
                        break;

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

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

            return(row);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a SubStorage from the XmlReader.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <returns>New SubStorage object.</returns>
        internal static SubStorage Parse(XmlReader reader)
        {
            Debug.Assert("subStorage" == reader.LocalName);

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

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

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

            // loop through all the fields in a row
            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 "wixOutput":
                            data = Output.Parse(reader, true);
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "row", reader.Name));
                        }
                        break;

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

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

            return(new SubStorage(name, data));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Parse an intermediate from an XML format.
        /// </summary>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        /// <param name="tableDefinitions">TableDefinitions to use in the intermediate.</param>
        /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatch.</param>
        /// <returns>The parsed Intermediate.</returns>
        internal static Intermediate Parse(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck)
        {
            Debug.Assert("wixObject" == reader.LocalName);

            bool    empty      = reader.IsEmptyElement;
            Version objVersion = null;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "version":
                    objVersion = new Version(reader.Value);
                    break;

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

            if (null != objVersion && !suppressVersionCheck)
            {
                if (0 != currentVersion.CompareTo(objVersion))
                {
                    throw new WixException(WixErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "object", objVersion.ToString(), currentVersion.ToString()));
                }
            }

            Intermediate intermediate = new Intermediate();

            // loop through the rest of the xml building up the SectionCollection
            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "section":
                            intermediate.sections.Add(Section.Parse(reader, tableDefinitions));
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixObject", reader.Name));
                        }
                        break;

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

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

            return(intermediate);
        }
Ejemplo n.º 15
0
        /// <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 "bundle":
                        type = SectionType.Bundle;
                        break;

                    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(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", reader.Name, reader.Value, "fragment", "module", "patchCreation", "product", "patch"));
                    }
                    break;

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

            if (null == id && (SectionType.Unknown != type && SectionType.Fragment != type))
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", "id", "type", type.ToString()));
            }

            if (SectionType.Unknown == type)
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", "type"));
            }

            section = new Section(id, type, codepage);
            section.sourceLineNumbers = SourceLineNumber.CreateFromUri(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(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", reader.Name));
                        }
                        break;

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

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

            return(section);
        }
Ejemplo n.º 16
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"));
                }
            }
        }
Ejemplo n.º 17
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(SourceLineNumber.CreateFromUri(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(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", reader.Name));
                    }
                    break;
                }
            }

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

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

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

            return(table);
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
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"));
                }
            }
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        /// <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(SourceLineNumber.CreateFromUri(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 "Bundle":
                        output.type = OutputType.Bundle;
                        sectionType = SectionType.Bundle;
                        break;

                    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(SourceLineNumber.CreateFromUri(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/", StringComparison.Ordinal))
                    {
                        throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput", reader.Name));
                    }
                    break;
                }
            }

            if (null != version && !suppressVersionCheck)
            {
                if (0 != currentVersion.CompareTo(version))
                {
                    throw new WixException(WixErrors.VersionMismatch(SourceLineNumber.CreateFromUri(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(SourceLineNumber.CreateFromUri(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(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput", reader.Name));
                        }
                        break;

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

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

            return(output);
        }