示例#1
0
        public void Add(ConceptualTargetDirectory targetDir)
        {
            if (targetDir == null)
            {
                return;
            }

            string dirPath = StripEndBackSlash(targetDir.Directory);

            if (String.IsNullOrEmpty(dirPath))
            {
                return;
            }
            if (_storedDirectories.ContainsKey(dirPath))
            {
                return;
            }

            _targetDirectories.Add(targetDir);
            _storedDirectories.Add(dirPath, true);
        }
        public ConceptualLinkComponent(BuildAssembler assembler,
                                       XPathNavigator configuration)
            : base(assembler, configuration)
        {
            _baseLinkType     = ConceptualLinkType.Null;
            _targetController = ConceptualTargetController.GetInstance("conceptual");

            XPathNavigator optionsNode = configuration.SelectSingleNode("options");

            if (optionsNode != null)
            {
                string showBrokenLinkTextValue = configuration.GetAttribute(
                    "showBrokenLinkText", String.Empty);
                if (!String.IsNullOrEmpty(showBrokenLinkTextValue))
                {
                    _showBrokenLinkText = Convert.ToBoolean(showBrokenLinkTextValue);
                }

                string tempText = optionsNode.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(tempText))
                {
                    try
                    {
                        // convert the link type to an enumeration member
                        _baseLinkType = (ConceptualLinkType)Enum.Parse(typeof(ConceptualLinkType),
                                                                       tempText, true);
                    }
                    catch (ArgumentException)
                    {
                        this.WriteMessage(MessageLevel.Error, String.Format(
                                              "'{0}' is not a valid link type.", tempText));
                    }
                }

                tempText = optionsNode.GetAttribute("showText", String.Empty);
                if (!String.IsNullOrEmpty(tempText))
                {
                    _showText = tempText.Equals("true",
                                                StringComparison.OrdinalIgnoreCase);
                }
            }

            XPathNodeIterator targetsNodes = configuration.Select("targets");

            foreach (XPathNavigator targetsNode in targetsNodes)
            {
                // the base directory containing target; required
                string baseValue = targetsNode.GetAttribute("base", String.Empty);
                if (String.IsNullOrEmpty(baseValue))
                {
                    this.WriteMessage(MessageLevel.Error,
                                      "Every targets element must have a base attribute that specifies the path to a directory of target metadata files.");
                }

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

                // an xpath expression to construct a file name
                // (not currently used; pattern is hard-coded to $target.cmp.xml
                string filesValue = targetsNode.GetAttribute("files", String.Empty);

                // an xpath expression to construct a url
                string          urlValue = targetsNode.GetAttribute("url", String.Empty);
                XPathExpression urlExpression;
                if (String.IsNullOrEmpty(urlValue))
                {
                    urlExpression = XPathExpression.Compile(
                        "concat(/metadata/topic/@id,'.htm')");
                }
                else
                {
                    urlExpression = CompileXPathExpression(urlValue);
                }

                // an xpath expression to construct link text
                string          textValue = targetsNode.GetAttribute("text", String.Empty);
                XPathExpression textExpression;
                if (String.IsNullOrEmpty(textValue))
                {
                    textExpression = XPathExpression.Compile(
                        "string(/metadata/topic/title)");
                }
                else
                {
                    textExpression = CompileXPathExpression(textValue);
                }

                // the type of link to create to targets found in the directory; required
                string typeValue = targetsNode.GetAttribute("type", String.Empty);
                if (String.IsNullOrEmpty(typeValue))
                {
                    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.");
                }

                // convert the link type to an enumeration member
                ConceptualLinkType type = ConceptualLinkType.None;
                try
                {
                    type = (ConceptualLinkType)Enum.Parse(typeof(ConceptualLinkType), typeValue, true);
                }
                catch (ArgumentException)
                {
                    this.WriteMessage(MessageLevel.Error, String.Format(
                                          "'{0}' is not a valid link type.", typeValue));
                }

                // We have all the required information; create a TargetDirectory
                // and add it to our collection
                ConceptualTargetDirectory targetDirectory = new ConceptualTargetDirectory(baseValue,
                                                                                          urlExpression, textExpression, type);
                _targetController.Add(targetDirectory);
            }

            this.WriteMessage(MessageLevel.Info, String.Format(
                                  "Collected {0} targets directories.", _targetController.Count));
        }
示例#3
0
 public void Add(ConceptualTargetDirectory targetDirectory)
 {
     targetDirectories.Add(targetDirectory);
 }