Esempio n. 1
0
        protected override void OnReadContentXml(XmlReader reader)
        {
            if (!String.Equals(reader.Name, "content",
                               StringComparison.OrdinalIgnoreCase))
            {
                Debug.Assert(false, "The processing of the OnReadContentXml method failed.");
                return;
            }

            if (String.Equals(reader.GetAttribute("type"), "Conceptual",
                              StringComparison.OrdinalIgnoreCase))
            {
                if (_topicContent == null)
                {
                    _topicContent = new ConceptualContent();
                }
                if (reader.IsEmptyElement)
                {
                    string sourceFile = reader.GetAttribute("source");
                    if (!String.IsNullOrEmpty(sourceFile))
                    {
                        _topicContent.ContentFile = new BuildFilePath(sourceFile);
                        _topicContent.Load();
                    }
                }
                else
                {
                    if (reader.ReadToDescendant(ConceptualContent.TagName))
                    {
                        _topicContent.ReadXml(reader);
                    }
                }
            }
        }
        public override ConceptualContent Create(BuildGroupContext groupContext)
        {
            BuildExceptions.NotNull(groupContext, "groupContext");

            BuildContext context = groupContext.Context;
            BuildLogger  logger  = null;

            if (context != null)
            {
                logger = context.Logger;
            }

            if (!this.IsInitialized)
            {
                throw new BuildException(String.Format(
                                             "The content source '{0}' is not yet initialized.", this.Title));
            }
            if (!this.IsValid)
            {
                if (logger != null)
                {
                    logger.WriteLine(String.Format(
                                         "The content group source '{0}' is invalid.", this.Title),
                                     BuildLoggerLevel.Warn);
                }

                return(null);
            }

            ConceptualContent content = new ConceptualContent(_sourcePath);

            content.Load();

            return(content);
        }
Esempio n. 3
0
        public bool CreateContent(string contentsDir, string contentsFile)
        {
            if (String.IsNullOrEmpty(contentsDir))
            {
                return(false);
            }
            contentsDir = Path.GetFullPath(contentsDir);
            if (!Directory.Exists(contentsDir))
            {
                return(false);
            }
            if (String.IsNullOrEmpty(contentsFile))
            {
                return(false);
            }
            contentsFile = Path.GetFullPath(contentsFile);
            if (!File.Exists(contentsFile))
            {
                return(false);
            }

            _topicContent = new ConceptualContent(contentsFile, contentsDir);
            _topicContent.Load();

            return(_topicContent.IsLoaded);
        }
Esempio n. 4
0
        private void ReadTopics(XmlReader reader, ConceptualContent content)
        {
            // 1. Grab the version information of the file format...
            float  version     = 1.0f;
            string versionText = reader.GetAttribute("version");

            if (String.IsNullOrEmpty(versionText) == false)
            {
                version = Convert.ToSingle(versionText);
            }

            XmlNodeType nodeType = reader.NodeType;
            string      nodeName = reader.Name;

            if (nodeType == XmlNodeType.Element && String.Equals(nodeName, "Topics"))
            {
                // handle the default topic id...
                string defaultTopic = reader.GetAttribute("default");
                if ((defaultTopic == null) ||
                    (defaultTopic != null && defaultTopic.Length == 36))
                {
                    content.DefaultTopic = defaultTopic;
                }
                // handle the items...
                ReadTopic(reader, content);
            }
            else
            {
                while (reader.Read())
                {
                    nodeType = reader.NodeType;
                    if (nodeType == XmlNodeType.Element)
                    {
                        nodeName = reader.Name;
                        if (String.Equals(nodeName, "Topics"))
                        {
                            // handle the default topic id...
                            string defaultTopic = reader.GetAttribute("default");
                            if ((defaultTopic == null) ||
                                (defaultTopic != null && defaultTopic.Length == 36))
                            {
                                content.DefaultTopic = defaultTopic;
                            }
                            // handle the items...
                            ReadTopic(reader, content);
                        }
                    }
                    else if (nodeType == XmlNodeType.EndElement)
                    {
                        if (String.Equals(reader.Name, "Topics"))
                        {
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public override void EndSources()
        {
            base.EndSources();

            if (_topicSource != null && _topicSource.IsValid)
            {
                // It was created from the source...
                _topicContent = null;
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConceptualGroup"/> class with
 /// parameters copied from the specified argument, a copy constructor.
 /// </summary>
 /// <param name="source">
 /// An instance of the <see cref="ConceptualGroup"/> class specifying the initial
 /// properties and states for this newly created instance.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// If the <paramref name="source"/> is <see langword="null"/>.
 /// </exception>
 public ConceptualGroup(ConceptualGroup source)
     : base(source)
 {
     _documentId      = source._documentId;
     _projectId       = source._projectId;
     _repositoryId    = source._repositoryId;
     _projectName     = source._projectName;
     _projectTitle    = source._projectTitle;
     _docWriter       = source._docWriter;
     _docEditor       = source._docEditor;
     _docManager      = source._docManager;
     _fileVersion     = source._fileVersion;
     _freshnessFormat = source._freshnessFormat;
     _freshnessDate   = source._freshnessDate;
     _topicSource     = source._topicSource;
     _topicContent    = source._topicContent;
     _changeHistory   = source._changeHistory;
 }
Esempio n. 7
0
        protected virtual void OnWriteMetadata(XmlWriter writer)
        {
            ConceptualContent content = this.Content as ConceptualContent;

            Debug.Assert(content != null);
            if (content == null)
            {
                throw new InvalidOperationException(
                          "A content is not associated with this topic.");
            }

            if (content.CompanionFiles)
            {
                string companionFile = Path.ChangeExtension(_filePath, ".cmp");
                this.OnCreateCompanionFile(companionFile, false);
            }
            else
            {
                this.OnWriteMetadata(writer, false, false);
            }
        }
Esempio n. 8
0
        private void ReadTopic(XmlReader reader, ConceptualContent content,
                               ConceptualItem parentItem)
        {
            XmlNodeType nodeType  = XmlNodeType.None;
            string      nodeName  = null;
            int         revNumber = 1;

            while (reader.Read())
            {
                nodeType = reader.NodeType;
                if (nodeType == XmlNodeType.Element)
                {
                    nodeName = reader.Name;
                    if (String.Equals(nodeName, "Topic"))
                    {
                        bool isVisible = true;

                        string docId = reader.GetAttribute("id");
                        if (ConceptualUtils.IsValidId(docId))
                        {
                            string textTemp = reader.GetAttribute("visible");
                            if (!String.IsNullOrEmpty(textTemp))
                            {
                                isVisible = Convert.ToBoolean(textTemp);
                            }

                            string docTitle = reader.GetAttribute("title");
                            if (!String.IsNullOrEmpty(docTitle))
                            {
                                string fullPath = Path.Combine(_contentDir,
                                                               docId + ".aml");
                                ConceptualTopic docItem = new ConceptualTopic(
                                    new BuildFilePath(fullPath), docTitle, docId);

                                docItem.Content = content;

                                docItem.BeginInit();

                                docItem.Visible        = isVisible;
                                docItem.TopicRevisions = revNumber;
                                //docItem.IncludesTopicId = true;

                                docItem.EndInit();

                                // handle the sub-item...
                                if (!reader.IsEmptyElement)
                                {
                                    ReadTopic(reader, content, docItem);
                                }

                                parentItem.Add(docItem);
                            }
                        }
                    }
                    else if (String.Equals(nodeName, "HelpKeyword"))
                    {
                        string index = reader.GetAttribute("index");
                        string term  = reader.GetAttribute("term");
                        if (!String.IsNullOrEmpty(index) &&
                            !String.IsNullOrEmpty(term))
                        {
                            KeywordItem keyword = new KeywordItem(
                                KeywordItem.ParseIndex(index), term);

                            parentItem.Keywords.Add(keyword);
                        }
                    }
                }
                else if (nodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, "Topic"))
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 9
0
        public override void BeginSources(BuildContext context)
        {
            base.BeginSources(context);

            BuildGroupContext groupContext = context.GroupContexts[this.Id];

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

            string workingDir = context.WorkingDirectory;

            if (!Directory.Exists(workingDir))
            {
                // If the base directory does not exists for some reason, we
                // create that first...
                string baseDir = context.BaseDirectory;
                if (!Directory.Exists(baseDir))
                {
                    Directory.CreateDirectory(baseDir);
                }
                Directory.CreateDirectory(workingDir);
            }

            BuildSettings settings = context.Settings;

            _projectTitle = settings.HelpTitle;
            _projectName  = settings.HelpName;

            string ddueXmlDir  = Path.Combine(workingDir, groupContext["$DdueXmlDir"]);
            string ddueCompDir = Path.Combine(workingDir, groupContext["$DdueXmlCompDir"]);
            string ddueHtmlDir = Path.Combine(workingDir, groupContext["$DdueHtmlDir"]);

            if (!Directory.Exists(ddueXmlDir))
            {
                Directory.CreateDirectory(ddueXmlDir);
            }
            if (!Directory.Exists(ddueCompDir))
            {
                Directory.CreateDirectory(ddueCompDir);
            }
            if (!Directory.Exists(ddueHtmlDir))
            {
                Directory.CreateDirectory(ddueHtmlDir);
            }

            if (_topicSource != null && _topicSource.IsValid)
            {
                string ddueMediaDir = Path.Combine(workingDir, groupContext["$DdueMedia"]);
                if (!Directory.Exists(ddueMediaDir))
                {
                    Directory.CreateDirectory(ddueMediaDir);
                }

                BuildSourceContext sourceContext = new BuildSourceContext();
                sourceContext.TopicsDir          = ddueXmlDir;
                sourceContext.TopicsCompanionDir = ddueCompDir;
                sourceContext.TopicsFile         = Path.Combine(workingDir,
                                                                groupContext["$ContentsFile"]);
                sourceContext.MediaDir  = ddueMediaDir;
                sourceContext.MediaFile = Path.Combine(workingDir,
                                                       groupContext["$MediaFile"]);

                sourceContext.Initialize(this.Name, workingDir, false);

                _topicSource.Initialize(sourceContext);
                _topicContent = _topicSource.Create(groupContext);
                _topicSource.Uninitialize();

                if (_topicContent == null)
                {
                    throw new BuildException(String.Format(
                                                 "The creation of the content for '{0}' failed.", this.Name));
                }

                groupContext["$OutputTopics"]  = Boolean.FalseString;
                groupContext["$ApplyVisitors"] = Boolean.FalseString;
            }
            else
            {
                groupContext["$OutputTopics"]  = Boolean.TrueString;
                groupContext["$ApplyVisitors"] = Boolean.TrueString;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Applies the processing operations defined by this visitor to the
        /// specified conceptual group.
        /// </summary>
        /// <param name="group">
        /// The <see cref="ConceptualGroup">conceptual group</see> to which
        /// the processing operations defined by this visitor will be applied.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="group"/> is <see langword="null"/>.
        /// </exception>
        protected override void OnVisit(ConceptualGroup group)
        {
            BuildExceptions.NotNull(group, "group");

            if (!this.IsInitialized)
            {
                throw new BuildException(
                          "ConceptualProjectVisitor: The conceptual table of contents generator is not initialized.");
            }

            BuildContext context = this.Context;
            BuildLogger  logger  = context.Logger;

            BuildGroupContext groupContext = context.GroupContexts[group.Id];

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

            if (logger != null)
            {
                logger.WriteLine("Begin - Creating Conceptual Resource Settings.",
                                 BuildLoggerLevel.Info);
            }

            _tocAdapter       = new ConceptualTocAdapter();
            _metadataAdapter  = new ConceptualMetadataAdapter();
            _manifestAdapters = new ConceptualManifestAdapter();

            try
            {
                _tocAdapter.Initialize(group, context);
                _metadataAdapter.Initialize(group, context);
                _manifestAdapters.Initialize(group, context);

                string workingDir = context.WorkingDirectory;

                _ddueXmlDir  = Path.Combine(workingDir, groupContext["$DdueXmlDir"]);
                _ddueCompDir = Path.Combine(workingDir, groupContext["$DdueXmlCompDir"]);
                _ddueHtmlDir = Path.Combine(workingDir, groupContext["$DdueHtmlDir"]);

                if (!Directory.Exists(_ddueXmlDir))
                {
                    Directory.CreateDirectory(_ddueXmlDir);
                }
                if (!Directory.Exists(_ddueCompDir))
                {
                    Directory.CreateDirectory(_ddueCompDir);
                }
                if (!Directory.Exists(_ddueHtmlDir))
                {
                    Directory.CreateDirectory(_ddueHtmlDir);
                }

                ConceptualContent content = group.Content;
                int itemCount             = content.Count;
                for (int i = 0; i < itemCount; i++)
                {
                    this.WriteTopic(content[i]);
                }

                IList <ConceptualRelatedTopic> relatedTopics = content.RelatedTopics;
                if (relatedTopics != null && relatedTopics.Count != 0)
                {
                    itemCount = relatedTopics.Count;
                    for (int i = 0; i < itemCount; i++)
                    {
                        ConceptualRelatedTopic topicItem = relatedTopics[i];
                        if (topicItem == null || topicItem.IsEmpty)
                        {
                            continue;
                        }

                        this.WriteTopic(topicItem);
                    }
                }
            }
            finally
            {
                _tocAdapter.Uninitialize();
                _metadataAdapter.Uninitialize();
                _manifestAdapters.Uninitialize();
            }

            if (logger != null)
            {
                logger.WriteLine("Completed - Creating Conceptual Resource Settings.",
                                 BuildLoggerLevel.Info);
            }
        }