Exemple #1
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>
        /// <param name="path">The path to display in an error message.</param>
        /// <returns>The Output represented by the Xml.</returns>
        private static Output Parse(XmlReader reader, bool suppressVersionCheck, string path)
        {
            Debug.Assert("wixOutput" == reader.LocalName);

            Output output = new Output();

            output.path = path;
            string      entrySectionId = null;
            SectionType sectionType    = SectionType.Unknown;
            Version     objVersion     = null;
            bool        empty          = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "type":
                    switch (reader.Value)
                    {
                    case "Module":
                        output.type = OutputType.Module;
                        sectionType = SectionType.Module;
                        break;

                    case "Product":
                        output.type = OutputType.Product;
                        sectionType = SectionType.Product;
                        break;

                    case "PatchCreation":
                        output.type = OutputType.PatchCreation;
                        sectionType = SectionType.PatchCreation;
                        break;

                    default:
                        throw new WixParseException(String.Format("The wixOutput/@type attribute contains an unexpected value '{0}'.", reader.Value));
                    }
                    break;

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

                case "compressed":
                    output.compressed = Common.IsYes(reader.Value, null, "wixOutput", reader.Name, null);
                    break;

                case "longFileNames":
                    output.longFileNames = Common.IsYes(reader.Value, null, "wixOutput", reader.Name, null);
                    break;

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

                case "moduleGuid":
                    output.moduleGuid = reader.Value;
                    break;

                case "output":
                    output.path = reader.Value;
                    break;

                case "suppressAdminSequence":
                    output.suppressAdminSequence = Common.IsYes(reader.Value, null, "wixOutput", reader.Name, null);
                    break;

                case "suppressAdvertiseSequence":
                    output.suppressAdvertiseSequence = Common.IsYes(reader.Value, null, "wixOutput", reader.Name, null);
                    break;

                case "suppressUISequence":
                    output.suppressUISequence = Common.IsYes(reader.Value, null, "wixOutput", reader.Name, null);
                    break;

                case "version":
                    objVersion = new Version(reader.Value);
                    break;

                case "xmlns":
                    break;

                default:
                    throw new WixParseException(String.Format("The wixOutput element contains an unexpected attribute {0}.", reader.Name));
                }
            }
            if (null == entrySectionId)
            {
                throw new WixParseException("The wixOutput/@entrySectionId attribute was not found; it is required.");
            }
            if (null != objVersion && !suppressVersionCheck)
            {
                Version currentVersion = Common.OutputFormatVersion;
                if (0 != currentVersion.CompareTo(objVersion))
                {
                    throw new WixVersionMismatchException(currentVersion, objVersion, "Output", output.Path);
                }
            }

            // create a section for all the rows to belong to
            Intermediate intermediate = new Intermediate();

            output.entrySection = new Section(intermediate, entrySectionId, sectionType, output.codepage);

            // 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 "outputTable":
                            output.outputTables.Add(OutputTable.Parse(reader, output.entrySection));
                            break;

                        case "importStream":
                            output.importStreams.Add(ImportStream.Parse(reader));
                            break;

                        case "componentsToFeatures":
                        case "featuresToFeatures":
                        case "modulesToFeatures":
                            ParseConnectToFeatures(output, reader);
                            break;

                        case "merge":
                            ParseMerge(output, reader);
                            break;

                        case "fileMediaInformation":
                            output.fileMediaInfoCollection.Add(FileMediaInformation.Parse(reader));
                            break;

                        case "media":
                            ParseMedia(output, reader);
                            break;

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

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

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

            return(output);
        }