Пример #1
0
        private ConceptualTargetController()
        {
            _targetDirectories = new TargetDirectoryCollection();
            _targetStorage     = new Dictionary <string, TargetInfo>(
                CacheSize, StringComparer.OrdinalIgnoreCase);

            _storedDirectories = new Dictionary <string, bool>(
                StringComparer.OrdinalIgnoreCase);
        }
        //=====================================================================
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="assembler">A reference to the build assembler.</param>
        /// <param name="configuration">The configuration information</param>
        public ResolveConceptualLinksComponent(BuildAssembler assembler,
          XPathNavigator configuration)
            : base(assembler, configuration)
        {
            TargetDirectory targetDirectory;
            XPathExpression urlExp, textExp, linkTextExp;
            LinkType linkType = LinkType.None;
            string attribute, basePath;

            targetDirectories = new TargetDirectoryCollection();
            cache = new Dictionary<string, TargetInfo>(cacheSize);

            attribute = configuration.GetAttribute("showBrokenLinkText", String.Empty);

            if(!String.IsNullOrEmpty(attribute))
                showBrokenLinkText = Convert.ToBoolean(attribute, CultureInfo.InvariantCulture);

            foreach(XPathNavigator navigator in configuration.Select("targets"))
            {
                basePath = navigator.GetAttribute("base", String.Empty);

                if(String.IsNullOrEmpty(basePath))
                    base.WriteMessage(MessageLevel.Error, "Every targets " +
                        "element must have a base attribute that specifies " +
                        "the path to a directory of target metadata files.");

                basePath = Environment.ExpandEnvironmentVariables(basePath);
                if(!Directory.Exists(basePath))
                    base.WriteMessage(MessageLevel.Error, String.Format(
                        CultureInfo.InvariantCulture, "The specified target " +
                        "metadata directory '{0}' does not exist.", basePath));

                attribute = navigator.GetAttribute("url", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    urlExp = XPathExpression.Compile("concat(/metadata/topic/@id,'.htm')");
                else
                    urlExp = this.CompileXPathExpression(attribute);

                attribute = navigator.GetAttribute("text", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    textExp = XPathExpression.Compile("string(/metadata/topic/title)");
                else
                    textExp = this.CompileXPathExpression(attribute);

                // EFW - Added support for linkText option
                attribute = navigator.GetAttribute("linkText", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    linkTextExp = XPathExpression.Compile("string(/metadata/topic/linkText)");
                else
                    linkTextExp = this.CompileXPathExpression(attribute);

                attribute = navigator.GetAttribute("type", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    base.WriteMessage(MessageLevel.Error, "Every targets " +
                        "element must have a type attribute that specifies " +
                        "what kind of link to create to targets found in " +
                        "that directory.");

                try
                {
                    linkType = (LinkType)Enum.Parse(typeof(LinkType), attribute, true);
                }
                catch(ArgumentException)
                {
                    base.WriteMessage(MessageLevel.Error, String.Format(CultureInfo.InvariantCulture,
                        "'{0}' is not a valid link type.", attribute));
                }

                targetDirectory = new TargetDirectory(basePath, urlExp, textExp, linkTextExp, linkType);
                targetDirectories.Add(targetDirectory);
            }

            base.WriteMessage(MessageLevel.Info, String.Format(CultureInfo.InvariantCulture,
                "Collected {0} targets directories.", targetDirectories.Count));
        }
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            TargetDirectory    targetDirectory;
            XPathExpression    urlExp, textExp, linkTextExp;
            ConceptualLinkType linkType = ConceptualLinkType.None;
            string             attribute, basePath;

            targetDirectories = new TargetDirectoryCollection();

            // This is a simple cache.  If the cache size limit is reached, it clears the cache and starts over
            cache = new Dictionary <string, TargetInfo>(CacheSize);

            attribute = (string)configuration.Evaluate("string(showBrokenLinkText/@value)");

            if (!String.IsNullOrWhiteSpace(attribute))
            {
                showBrokenLinkText = Convert.ToBoolean(attribute, CultureInfo.InvariantCulture);
            }

            foreach (XPathNavigator navigator in configuration.Select("targets"))
            {
                basePath = navigator.GetAttribute("base", String.Empty);

                if (String.IsNullOrEmpty(basePath))
                {
                    base.WriteMessage(MessageLevel.Error, "Every targets element must have a base attribute " +
                                      "that specifies the path to a directory of target metadata files.");
                }

                basePath = Environment.ExpandEnvironmentVariables(basePath);

                if (!Directory.Exists(basePath))
                {
                    base.WriteMessage(MessageLevel.Error, "The specified target metadata directory '{0}' " +
                                      "does not exist.", basePath);
                }

                attribute = navigator.GetAttribute("url", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    urlExp = XPathExpression.Compile("concat(/metadata/topic/@id,'.htm')");
                }
                else
                {
                    urlExp = this.CompileXPathExpression(attribute);
                }

                attribute = navigator.GetAttribute("text", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    textExp = XPathExpression.Compile("string(/metadata/topic/title)");
                }
                else
                {
                    textExp = this.CompileXPathExpression(attribute);
                }

                // EFW - Added support for linkText option
                attribute = navigator.GetAttribute("linkText", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    linkTextExp = XPathExpression.Compile("string(/metadata/topic/linkText)");
                }
                else
                {
                    linkTextExp = this.CompileXPathExpression(attribute);
                }

                attribute = navigator.GetAttribute("type", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    base.WriteMessage(MessageLevel.Error, "Every targets element must have a type attribute " +
                                      "that specifies what kind of link to create to targets found in that directory.");
                }

                if (!Enum.TryParse <ConceptualLinkType>(attribute, true, out linkType))
                {
                    base.WriteMessage(MessageLevel.Error, "'{0}' is not a valid link type.", attribute);
                }

                targetDirectory = new TargetDirectory(basePath, urlExp, textExp, linkTextExp, linkType);
                targetDirectories.Add(targetDirectory);
            }

            base.WriteMessage(MessageLevel.Info, "Collected {0} targets directories.", targetDirectories.Count);
        }
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            TargetDirectory targetDirectory;
            XPathExpression urlExp, textExp, linkTextExp;
            ConceptualLinkType linkType = ConceptualLinkType.None;
            string attribute, basePath;

            targetDirectories = new TargetDirectoryCollection();

            // This is a simple cache.  If the cache size limit is reached, it clears the cache and starts over
            cache = new Dictionary<string, TargetInfo>(CacheSize);

            attribute = (string)configuration.Evaluate("string(showBrokenLinkText/@value)");

            if(!String.IsNullOrWhiteSpace(attribute))
                showBrokenLinkText = Convert.ToBoolean(attribute, CultureInfo.InvariantCulture);

            foreach(XPathNavigator navigator in configuration.Select("targets"))
            {
                basePath = navigator.GetAttribute("base", String.Empty);

                if(String.IsNullOrEmpty(basePath))
                    this.WriteMessage(MessageLevel.Error, "Every targets element must have a base attribute " +
                        "that specifies the path to a directory of target metadata files.");

                basePath = Environment.ExpandEnvironmentVariables(basePath);

                if(!Directory.Exists(basePath))
                    this.WriteMessage(MessageLevel.Error, "The specified target metadata directory '{0}' " +
                        "does not exist.", basePath);

                attribute = navigator.GetAttribute("url", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    urlExp = XPathExpression.Compile("concat(/metadata/topic/@id,'.htm')");
                else
                    urlExp = this.CompileXPathExpression(attribute);

                attribute = navigator.GetAttribute("text", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    textExp = XPathExpression.Compile("string(/metadata/topic/title)");
                else
                    textExp = this.CompileXPathExpression(attribute);

                // EFW - Added support for linkText option
                attribute = navigator.GetAttribute("linkText", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    linkTextExp = XPathExpression.Compile("string(/metadata/topic/linkText)");
                else
                    linkTextExp = this.CompileXPathExpression(attribute);

                attribute = navigator.GetAttribute("type", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    this.WriteMessage(MessageLevel.Error, "Every targets element must have a type attribute " +
                        "that specifies what kind of link to create to targets found in that directory.");

                if(!Enum.TryParse<ConceptualLinkType>(attribute, true, out linkType))
                    this.WriteMessage(MessageLevel.Error, "'{0}' is not a valid link type.", attribute);

                targetDirectory = new TargetDirectory(basePath, urlExp, textExp, linkTextExp, linkType);
                targetDirectories.Add(targetDirectory);
            }

            this.WriteMessage(MessageLevel.Info, "Collected {0} targets directories.", targetDirectories.Count);
        }