Ejemplo n.º 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>
        protected virtual void WriteContents(XmlWriter writer)
        {
            BuildExceptions.NotNull(writer, "writer");

            // The various contents required for documentation
            writer.WriteComment(" The various contents required for documentation ");
            writer.WriteStartElement("contents");  // start - contents

            if (_commentContent != null)
            {
                BuildFilePath filePath = _commentContent.ContentFile;
                writer.WriteStartElement("content");
                writer.WriteAttributeString("type", "Comments");
                if (filePath != null && filePath.IsValid)
                {
                    BuildPathResolver resolver = BuildPathResolver.Resolver;

                    writer.WriteAttributeString("source",
                                                resolver.ResolveRelative(filePath));
                    _commentContent.Save();
                }
                else
                {
                    _commentContent.WriteXml(writer);
                }
                writer.WriteEndElement();
            }
            if (_tocContent != null)
            {
                writer.WriteStartElement("content");
                writer.WriteAttributeString("type", "HierarchicalToc");
                _tocContent.WriteXml(writer);
                writer.WriteEndElement();
            }

            this.OnWriteContents(writer);

            writer.WriteEndElement();              // end - contents
        }
Ejemplo n.º 2
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);
            writer.WriteAttributeString("version", _contentVersion.ToString(2));

            // 1. The content directory, if not the same as the content file.
            writer.WriteComment(
                " 1. The content directory, if not the same as the content file. ");
            writer.WriteStartElement("location"); // start - location
            if (_contentDir != null &&
                !_contentDir.IsDirectoryOf(_contentFile))
            {
                _contentDir.WriteXml(writer);
            }
            writer.WriteEndElement();             // end - location

            // 2. The general content settings
            writer.WriteComment(" 2. The general content settings ");
            writer.WriteStartElement("propertyGroup");  // start - propertyGroup
            writer.WriteAttributeString("name", "General");

            writer.WritePropertyElement("Id", _contentId);
            writer.WritePropertyElement("FrameworkType", _frameworkType.ToString());

            writer.WriteEndElement();                   // end - propertyGroup

            // 3. The reference items defining the API content
            writer.WriteComment(" 3. The reference items defining the API content ");
            writer.WriteStartElement("referenceItems");  // start - referenceItems
            for (int i = 0; i < this.Count; i++)
            {
                ReferenceItem item = this[i];
                if (item != null && !item.IsEmpty)
                {
                    item.WriteXml(writer);
                }
            }
            writer.WriteEndElement();                    // end - referenceItems

            // 4. The various contents required for documentation
            writer.WriteComment(" 4. The various contents required for documentation ");
            writer.WriteStartElement("contents");  // start - contents

            if (_commentContent != null)
            {
                BuildFilePath filePath = _commentContent.ContentFile;
                writer.WriteStartElement("content");
                writer.WriteAttributeString("type", "Comments");
                if (filePath != null && filePath.IsValid)
                {
                    BuildPathResolver resolver = BuildPathResolver.Resolver;
                    Debug.Assert(resolver != null && resolver.Id == _contentId);

                    writer.WriteAttributeString("source",
                                                resolver.ResolveRelative(filePath));
                    _commentContent.Save();
                }
                else
                {
                    _commentContent.WriteXml(writer);
                }
                writer.WriteEndElement();
            }
            if (_dependencies != null)
            {
                writer.WriteStartElement("content");
                writer.WriteAttributeString("type", "Dependencies");
                _dependencies.WriteXml(writer);
                writer.WriteEndElement();
            }
            if (_tocContent != null)
            {
                writer.WriteStartElement("content");
                writer.WriteAttributeString("type", "HierarchicalToc");
                _tocContent.WriteXml(writer);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();              // end - contents

            // 5. The API/attribute filters associated with the documentations
            writer.WriteComment(" 5. The API/attribute filters associated with the documentations ");
            writer.WriteStartElement("filters");  // start - filters
            if (_typeFilters != null)
            {
                _typeFilters.WriteXml(writer);
            }
            if (_attributeFilters != null)
            {
                _attributeFilters.WriteXml(writer);
            }
            writer.WriteEndElement();             // end - filters

            writer.WriteEndElement();
        }
Ejemplo n.º 3
0
        private bool OnExecuteSingle(BuildContext context)
        {
            BuildLogger logger = context.Logger;

            ReferenceGroupContext groupContext =
                context.GroupContexts[_group.Id] as ReferenceGroupContext;

            if (groupContext == null)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

            ReferenceContent content = _group.Content;

            if (content == null)
            {
                if (logger != null)
                {
                    logger.WriteLine("StepReferenceInit: There is no content associated with the reference group.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            BuildFrameworkType frameworkType = content.FrameworkType;

            if (frameworkType == BuildFrameworkType.Null ||
                frameworkType == BuildFrameworkType.None)
            {
                if (logger != null)
                {
                    logger.WriteLine("StepReferenceInit: There is no valid framework type specified for this reference group.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            BuildFramework framework = BuildFrameworks.GetFramework(frameworkType);

            if (framework == null)
            {
                if (logger != null)
                {
                    logger.WriteLine("StepReferenceInit: The specified framework type for this reference group is not installed.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            string workingDir = context.WorkingDirectory;

            groupContext.Framework = framework;

            string commentDir  = groupContext.CommentFolder;
            string assemblyDir = groupContext.AssemblyFolder;

            if (String.IsNullOrEmpty(commentDir))
            {
                commentDir = "Comments";
            }
            if (!Path.IsPathRooted(commentDir))
            {
                commentDir = Path.Combine(workingDir, commentDir);
            }
            if (!Directory.Exists(commentDir))
            {
                Directory.CreateDirectory(commentDir);
            }

            if (String.IsNullOrEmpty(assemblyDir))
            {
                assemblyDir = "Assemblies";
            }
            if (!Path.IsPathRooted(assemblyDir))
            {
                assemblyDir = Path.Combine(workingDir, assemblyDir);
            }
            if (!Directory.Exists(assemblyDir))
            {
                Directory.CreateDirectory(assemblyDir);
            }

            string dependencyDir = groupContext.DependencyFolder;

            if (String.IsNullOrEmpty(dependencyDir))
            {
                dependencyDir = "Dependencies";
            }
            if (!Path.IsPathRooted(dependencyDir))
            {
                dependencyDir = Path.Combine(workingDir, dependencyDir);
            }
            if (!Directory.Exists(dependencyDir))
            {
                Directory.CreateDirectory(dependencyDir);
            }

            groupContext.CommentDir    = commentDir;
            groupContext.AssemblyDir   = assemblyDir;
            groupContext.DependencyDir = dependencyDir;

            // Copy the comments to the expected directory...
            int           itemCount    = content.Count;
            List <string> commentFiles = new List <string>(itemCount);

            CommentContent commentContent = content.Comments;

            if (commentContent != null && !commentContent.IsEmpty)
            {
                string commentFile = Path.Combine(commentDir,
                                                  groupContext["$CommentsFile"]);

                // If there is a valid file or there is an attached file...
                BuildFilePath filePath = commentContent.ContentFile;
                if (filePath != null && filePath.Exists)
                {
                    if (commentContent.IsLoaded)
                    {
                        commentContent.Save();
                    }

                    File.Copy(filePath.Path, commentFile);
                }
                else
                {
                    commentContent.SaveCopyAs(commentFile);
                }
                File.SetAttributes(commentFile, FileAttributes.Normal);

                commentFiles.Add(commentFile);
            }

            for (int i = 0; i < itemCount; i++)
            {
                ReferenceItem item = content[i];
                if (item == null || item.IsEmpty)
                {
                    continue;
                }

                string commentsFile = item.Comments;
                if (!String.IsNullOrEmpty(commentsFile))
                {
                    string fileName = Path.GetFileName(commentsFile);
                    fileName = Path.Combine(commentDir, fileName);
                    if (commentsFile.Length != fileName.Length ||
                        String.Equals(commentsFile, fileName,
                                      StringComparison.OrdinalIgnoreCase) == false)
                    {
                        File.Copy(commentsFile, fileName, true);
                        File.SetAttributes(fileName, FileAttributes.Normal);

                        commentFiles.Add(fileName);
                    }
                }

                string assemblyFile = item.Assembly;
                if (!String.IsNullOrEmpty(assemblyFile))
                {
                    string fileName = Path.GetFileName(assemblyFile);
                    fileName = Path.Combine(assemblyDir, fileName);
                    if (assemblyFile.Length != fileName.Length ||
                        String.Equals(assemblyFile, fileName,
                                      StringComparison.OrdinalIgnoreCase) == false)
                    {
                        File.Copy(assemblyFile, fileName, true);
                        File.SetAttributes(fileName, FileAttributes.Normal);
                    }
                }
            }

            // Finally, store the list of extracted comment file to its context...
            groupContext.CommentFiles = commentFiles;

            // 1. Copy the dependencies to the expected directory...
            ReferenceProjectVisitor dependencyResolver =
                new ReferenceProjectVisitor();

            dependencyResolver.Initialize(context);
            dependencyResolver.Visit(_group);
            dependencyResolver.Uninitialize();

            return(true);
        }