Exemple #1
0
        /// <summary>
        /// This writes the current state or attributes of this object,
        /// in the <c>XML</c> format, to the media or storage accessible by the given writer.
        /// </summary>
        /// <param name="writer">
        /// The <c>XML</c> writer with which the <c>XML</c> format of this object's state
        /// is written.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void WriteXml(XmlWriter writer)
        {
            BuildExceptions.NotNull(writer, "writer");

            writer.WriteStartElement(TagName);  // start - TagName
            writer.WriteAttributeString("version", _version.ToString(2));

            //  1. Documentation: Settings of the documentation
            writer.WriteComment(" 1. Documentation: Settings of the documentation ");
            if (_settings != null)
            {
                _settings.WriteXml(writer);
            }

            // 2. Documentation: Group sources of the documentation
            writer.WriteComment(" 2. Documentation: Group sources of the documentation ");
            writer.WriteStartElement("documentSources"); // start - documentSources
            if (_listSources != null && _listSources.Count != 0)
            {
                for (int i = 0; i < _listSources.Count; i++)
                {
                    _listSources[i].WriteXml(writer);
                }
            }
            writer.WriteEndElement();                    // end - documentSources

            // 3. Documentation: Groups of the documentation
            writer.WriteComment(" 3. Documentation: Groups of the documentation ");
            writer.WriteStartElement("documentGroups"); // start - documentGroups
            if (_listGroups != null && _listGroups.Count != 0)
            {
                BuildPathResolver resolver = BuildPathResolver.Resolver;
                Debug.Assert(resolver != null && resolver.Id == _documentId);

                for (int i = 0; i < _listGroups.Count; i++)
                {
                    BuildGroup group = _listGroups[i];

                    BuildFilePath filePath = group.ContentFile;
                    if (filePath != null && filePath.IsValid)
                    {
                        writer.WriteStartElement(BuildGroup.TagName);
                        writer.WriteAttributeString("type", group.GroupType.ToString());
                        writer.WriteAttributeString("source", resolver.ResolveRelative(filePath));
                        writer.WriteEndElement();

                        group.Save();
                    }
                    else
                    {
                        group.WriteXml(writer);
                    }
                }
            }
            writer.WriteEndElement();           // end - documentGroups

            writer.WriteEndElement();           // end - TagName
        }
        public static string Push(BuildPathResolver resolver)
        {
            BuildExceptions.NotNull(resolver, "resolver");

            lock (_synchObject)
            {
                _resolvers.Push(resolver);

                return(resolver.Id);
            }
        }
Exemple #3
0
        public void Save()
        {
            if (String.IsNullOrEmpty(_documentFile))
            {
                return;
            }

            BuildPathResolver resolver = BuildPathResolver.Create(
                Path.GetDirectoryName(_documentFile), _documentId);

            this.Save(resolver);
        }
Exemple #4
0
        public void Save(BuildPathResolver resolver)
        {
            BuildExceptions.NotNull(resolver, "resolver");

            // If this is not yet located, and the contents is empty, we
            // will simply not continue from here...
            if (_documentFile != null && _documentFile.Exists)
            {
                if (!this._isLoaded && this.IsEmpty)
                {
                    return;
                }
            }

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent             = true;
            settings.IndentChars        = new string(' ', 4);
            settings.Encoding           = Encoding.UTF8;
            settings.OmitXmlDeclaration = false;

            XmlWriter writer = null;

            try
            {
                writer = XmlWriter.Create(_documentFile, settings);

                string resolverId = BuildPathResolver.Push(resolver);
                {
                    writer.WriteStartDocument();

                    this.WriteXml(writer);

                    writer.WriteEndDocument();

                    BuildPathResolver.Pop(resolverId);
                }

                // The file content is now same as the memory, so it can be
                // considered loaded...
                _isLoaded = true;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    writer = null;
                }
            }
        }
Exemple #5
0
        public void Load(BuildPathResolver resolver)
        {
            BuildExceptions.NotNull(resolver, "resolver");

            if (_isLoaded)
            {
                return;
            }

            if (String.IsNullOrEmpty(_documentFile) ||
                File.Exists(_documentFile) == false)
            {
                return;
            }

            XmlReader reader = null;

            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();

                settings.IgnoreComments               = true;
                settings.IgnoreWhitespace             = true;
                settings.IgnoreProcessingInstructions = true;

                reader = XmlReader.Create(_documentFile, settings);

                reader.MoveToContent();

                string resolverId = BuildPathResolver.Push(resolver);
                {
                    this.ReadXml(reader);

                    BuildPathResolver.Pop(resolverId);
                }

                _isLoaded = true;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                    reader = null;
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// This writes the current state or attributes of this object,
        /// in the <c>XML</c> format, to the media or storage accessible by the given writer.
        /// </summary>
        /// <param name="writer">
        /// The <c>XML</c> writer with which the <c>XML</c> format of this object's state
        /// is written.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void WriteXml(XmlWriter writer)
        {
            BuildExceptions.NotNull(writer, "writer");

            writer.WriteStartElement(TagName);
            string hintPath = this.HintPath;

            if (String.IsNullOrEmpty(hintPath))
            {
                BuildPathResolver resolver = BuildPathResolver.Resolver;
                writer.WriteAttributeString("value",
                                            resolver.ResolveRelative(this.Path));
            }
            else
            {
                writer.WriteAttributeString("value", this.Name);
                writer.WriteString(hintPath);
            }
            writer.WriteEndElement();
        }
Exemple #7
0
        private void OnUpdatePath(string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                _path = path;
                return;
            }

            BuildPathResolver resolver = BuildPathResolver.Resolver;

            Debug.Assert(resolver != null);

            string absolutePath = path;

            if (resolver != null)
            {
                absolutePath = resolver.ResolveAbsolute(path);
            }

            _path = absolutePath;
        }
        public static BuildPathResolver Pop(string resolverId)
        {
            lock (_synchObject)
            {
                // The current provider must match the id provided...
                BuildPathResolver resolver = BuildPathResolver.Resolver;
                if (resolver != null)
                {
                    if (String.Equals(resolver.Id, resolverId,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        resolver = _resolvers.Pop();
                    }
                    else
                    {
                        // Something went wrong...
                        throw new BuildException(
                                  "The operation is invalid. The resolver ID does not match the current resolver.");
                    }
                }

                return(resolver);
            }
        }
Exemple #9
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");

            BuildPathResolver resolver = BuildPathResolver.Resolver;
            string            nodeName = reader.Name;

            if (String.Equals(nodeName, TagName,
                              StringComparison.OrdinalIgnoreCase))
            {
                if (reader.IsEmptyElement)
                {
                    _path = resolver.ResolveAbsolute(
                        reader.GetAttribute("value"));
                }
                else
                {
                    _path = reader.GetAttribute("value");
                    string hintPath = reader.ReadString();

                    if (String.IsNullOrEmpty(hintPath))
                    {
                        _path = resolver.ResolveAbsolute(_path);
                    }
                    else
                    {
                        base.HintPath = hintPath;
                    }
                }
            }
            else
            {
                nodeName = reader.Name;
                XmlNodeType nodeType = XmlNodeType.None;
                while (reader.Read())
                {
                    nodeType = reader.NodeType;
                    if (nodeType == XmlNodeType.Element && String.Equals(
                            nodeName, TagName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (reader.IsEmptyElement)
                        {
                            _path = resolver.ResolveAbsolute(
                                reader.GetAttribute("value"));
                        }
                        else
                        {
                            _path = reader.GetAttribute("value");
                            string hintPath = reader.ReadString();

                            if (String.IsNullOrEmpty(hintPath))
                            {
                                _path = resolver.ResolveAbsolute(_path);
                            }
                            else
                            {
                                base.HintPath = hintPath;
                            }
                        }
                    }
                }
            }
        }