コード例 #1
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                Debug.Assert(false, String.Format(
                                 "The element name '{0}' does not match the expected '{1}'.",
                                 reader.Name, TagName));
                return;
            }

            // Read the version information of the file group...
            string tempText = reader.GetAttribute("version");

            if (!String.IsNullOrEmpty(tempText))
            {
                _version = new Version(tempText);
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            if (_listGroups == null || _listGroups.Count != 0)
            {
                _listGroups = new BuildKeyedList <BuildGroup>();
            }
            if (_listSources == null || _listSources.Count != 0)
            {
                _listSources = new BuildKeyedList <BuildGroupSource>();
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, BuildSettings.TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        if (_settings == null)
                        {
                            _settings = new BuildSettings();
                        }
                        _settings.ReadXml(reader);
                    }
                    else if (String.Equals(reader.Name, BuildGroup.TagName,
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        BuildGroup group = null;

                        tempText = reader.GetAttribute("type");

                        if (String.Equals(tempText, "Conceptual",
                                          StringComparison.OrdinalIgnoreCase))
                        {
                            group = new ConceptualGroup();
                        }
                        else if (String.Equals(tempText, "Reference",
                                               StringComparison.OrdinalIgnoreCase))
                        {
                            group = new ReferenceGroup();
                        }
                        else
                        {
                            throw new NotImplementedException(tempText);
                        }

                        if (reader.IsEmptyElement)
                        {
                            string sourceFile = reader.GetAttribute("source");
                            if (!String.IsNullOrEmpty(sourceFile))
                            {
                                group.ContentFile = new BuildFilePath(sourceFile);
                                group.Load();
                            }
                        }
                        else
                        {
                            group.ReadXml(reader);
                        }

                        _listGroups.Add(group);
                    }
                    else if (String.Equals(reader.Name, BuildGroupSource.TagName,
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        BuildGroupSource source = BuildGroupSource.CreateSource(
                            reader.GetAttribute("name"));

                        if (source == null)
                        {
                            throw new BuildException(String.Format(
                                                         "The creation of the group source '{0}' failed.",
                                                         reader.GetAttribute("name")));
                        }

                        source.ReadXml(reader);

                        _listSources.Add(source);
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }