//===================================================================== /// <inheritdoc /> public override void Initialize(XPathNavigator configuration) { // get the condition XPathNavigator condition_element = configuration.SelectSingleNode("switch"); if (condition_element == null) { throw new ConfigurationErrorsException("You must specify a condition using the <switch> statement with a 'value' attribute."); } string condition_value = condition_element.GetAttribute("value", String.Empty); if (String.IsNullOrEmpty(condition_value)) { throw new ConfigurationErrorsException("The switch statement must have a 'value' attribute, which is an xpath expression."); } condition = XPathExpression.Compile(condition_value); // load the component stacks for each case XPathNodeIterator case_elements = configuration.Select("case"); foreach (XPathNavigator case_element in case_elements) { string case_value = case_element.GetAttribute("value", String.Empty); cases.Add(case_value, BuildAssembler.LoadComponents(case_element)); } }
public CopyFromFilesComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNodeIterator copy_nodes = configuration.Select("copy"); foreach (XPathNavigator copy_node in copy_nodes) { string root_value = copy_node.GetAttribute("base", String.Empty); if (String.IsNullOrEmpty(root_value)) { root_value = Environment.CurrentDirectory; } root_value = Environment.ExpandEnvironmentVariables(root_value); if (!Directory.Exists(root_value)) { WriteMessage(MessageLevel.Error, String.Format("The base directory '{0}' does not exist.", root_value)); } string file_value = copy_node.GetAttribute("file", String.Empty); if (String.IsNullOrEmpty(file_value)) { WriteMessage(MessageLevel.Error, "Each copy element must have a file attribute specifying the file to copy from."); } string source_value = copy_node.GetAttribute("source", String.Empty); string target_value = copy_node.GetAttribute("target", String.Empty); CopyFromFilesCommand copy_command = new CopyFromFilesCommand(root_value, file_value, source_value, target_value); copy_commands.Add(copy_command); } WriteMessage(MessageLevel.Info, String.Format("Loaded {0} copy commands.", copy_commands.Count)); }
public ResolveArtLinksComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNodeIterator targets_nodes = configuration.Select("targets"); foreach (XPathNavigator targets_node in targets_nodes) { string input = targets_node.GetAttribute("input", String.Empty); if (String.IsNullOrEmpty(input)) { WriteMessage(MessageLevel.Error, "Each targets element must have an input attribute specifying a directory containing art files."); } input = Environment.ExpandEnvironmentVariables(input); if (!Directory.Exists(input)) { WriteMessage(MessageLevel.Error, String.Format("The art input directory '{0}' does not exist.", input)); } string baseOutputPath = targets_node.GetAttribute("baseOutput", String.Empty); if (!String.IsNullOrEmpty(baseOutputPath)) { baseOutputPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(baseOutputPath)); } string outputPath_value = targets_node.GetAttribute("outputPath", string.Empty); if (string.IsNullOrEmpty(outputPath_value)) { WriteMessage(MessageLevel.Error, "Each targets element must have an output attribute specifying a directory in which to place referenced art files."); } XPathExpression output_XPath = XPathExpression.Compile(outputPath_value); string linkValue = targets_node.GetAttribute("link", String.Empty); if (String.IsNullOrEmpty(linkValue)) { linkValue = "../art"; } //linkValue = Environment.ExpandEnvironmentVariables(linkValue); string map = targets_node.GetAttribute("map", String.Empty); if (String.IsNullOrEmpty(map)) { WriteMessage(MessageLevel.Error, "Each targets element must have a map attribute specifying a file that maps art ids to files in the input directory."); } map = Environment.ExpandEnvironmentVariables(map); if (!File.Exists(map)) { WriteMessage(MessageLevel.Error, String.Format("The art map file '{0}' does not exist.", map)); } string format = targets_node.GetAttribute("format", String.Empty); XPathExpression format_xpath = String.IsNullOrEmpty(format) ? null : XPathExpression.Compile(format); string relative_to = targets_node.GetAttribute("relative-to", String.Empty); XPathExpression relative_to_xpath = String.IsNullOrEmpty(relative_to) ? null : XPathExpression.Compile(relative_to); AddTargets(map, input, baseOutputPath, output_XPath, linkValue, format_xpath, relative_to_xpath); } WriteMessage(MessageLevel.Info, String.Format("Indexed {0} art targets.", targets.Count)); }
public SaveComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { // load the target path format XPathNavigator save_node = configuration.SelectSingleNode("save"); if (save_node == null) { throw new ConfigurationErrorsException("When instantiating a save component, you must specify a the target file using the <save> element."); } string base_value = save_node.GetAttribute("base", String.Empty); if (!String.IsNullOrEmpty(base_value)) { basePath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(base_value)); } string path_value = save_node.GetAttribute("path", String.Empty); if (String.IsNullOrEmpty(path_value)) { WriteMessage(MessageLevel.Error, "Each save element must have a path attribute specifying an XPath that evaluates to the location to save the file."); } path_expression = XPathExpression.Compile(path_value); string select_value = save_node.GetAttribute("select", String.Empty); if (!String.IsNullOrEmpty(select_value)) { select_expression = XPathExpression.Compile(select_value); } settings.Encoding = Encoding.UTF8; string indent_value = save_node.GetAttribute("indent", String.Empty); if (!String.IsNullOrEmpty(indent_value)) { settings.Indent = Convert.ToBoolean(indent_value); } string omit_value = save_node.GetAttribute("omit-xml-declaration", String.Empty); if (!String.IsNullOrEmpty(omit_value)) { settings.OmitXmlDeclaration = Convert.ToBoolean(omit_value); } linkPath = save_node.GetAttribute("link", String.Empty); if (String.IsNullOrEmpty(linkPath)) { linkPath = "../html"; } // encoding settings.CloseOutput = true; }
public DisplayComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNavigator xpath_format_node = configuration.SelectSingleNode("xpath"); if (xpath_format_node != null) { xpath_format = xpath_format_node.Value; } }
public TransformComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { // load the transforms XPathNodeIterator transform_nodes = configuration.Select("transform"); foreach (XPathNavigator transform_node in transform_nodes) { // load the transform string file = transform_node.GetAttribute("file", String.Empty); if (String.IsNullOrEmpty(file)) { WriteMessage(MessageLevel.Error, "Each transform element must specify a file attribute."); } file = Environment.ExpandEnvironmentVariables(file); Transform transform = null; try { transform = new Transform(file); } catch (IOException e) { WriteMessage(MessageLevel.Error, String.Format("The transform file '{0}' could not be loaded. The error message is: {1}", file, BuildComponentUtilities.GetExceptionMessage(e))); } catch (XmlException e) { WriteMessage(MessageLevel.Error, String.Format("The transform file '{0}' is not a valid XML file. The error message is: {1}", file, BuildComponentUtilities.GetExceptionMessage(e))); } catch (XsltException e) { WriteMessage(MessageLevel.Error, String.Format("The XSL transform '{0}' contains an error. The error message is: {1}", file, BuildComponentUtilities.GetExceptionMessage(e))); } transforms.Add(transform); // load any arguments XPathNodeIterator argument_nodes = transform_node.Select("argument"); foreach (XPathNavigator argument_node in argument_nodes) { string key = argument_node.GetAttribute("key", String.Empty); if ((key == null) || (key.Length == 0)) { WriteMessage(MessageLevel.Error, "When creating a transform argument, you must specify a key using the key attribute"); } // set "expand-value" attribute to true to expand environment variables embedded in "value". string expand_attr = argument_node.GetAttribute("expand-value", String.Empty); bool expand_value = String.IsNullOrEmpty(expand_attr) ? false : Convert.ToBoolean(expand_attr); string value = argument_node.GetAttribute("value", String.Empty); if ((value != null) && (value.Length > 0)) { transform.Arguments.AddParam(key, String.Empty, expand_value ? Environment.ExpandEnvironmentVariables(value) : value); } else { transform.Arguments.AddParam(key, String.Empty, argument_node.Clone()); } } } }
public CloneComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNodeIterator branch_nodes = configuration.Select("branch"); foreach (XPathNavigator branch_node in branch_nodes) { BuildComponent[] branch = BuildAssembler.LoadComponents(branch_node); branches.Add(branch); } }
public ValidateComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNodeIterator schema_nodes = configuration.Select("schema"); foreach (XPathNavigator schema_node in schema_nodes) { string file = schema_node.GetAttribute("file", String.Empty); schemas.Add(null, file); } }
// instantiation logic public ResolveReferenceLinksComponent2(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { // base-url is an xpath expression applied against the current document to pick up the save location of the // document. If specified, local links will be made relative to the base-url. string baseUrlValue = configuration.GetAttribute("base-url", String.Empty); if (!String.IsNullOrEmpty(baseUrlValue)) { baseUrl = XPathExpression.Compile(baseUrlValue); } // url-format is a string format that is used to format the value of local href attributes. The default is // "{0}.htm" for backwards compatibility. string hrefFormatValue = configuration.GetAttribute("href-format", String.Empty); if (!String.IsNullOrEmpty(hrefFormatValue)) { hrefFormat = hrefFormatValue; } // the container XPath can be replaced; this is useful string containerValue = configuration.GetAttribute("container", String.Empty); if (!String.IsNullOrEmpty(containerValue)) { XmlTargetCollectionUtilities.ContainerExpression = containerValue; } targets = new TargetCollection(); resolver = new LinkTextResolver(targets); XPathNodeIterator targets_nodes = configuration.Select("targets"); foreach (XPathNavigator targets_node in targets_nodes) { ProcessTargetsNode(targets_node); } WriteMessage(MessageLevel.Info, String.Format("Loaded {0} reference targets.", targets.Count)); string locale_value = configuration.GetAttribute("locale", String.Empty); if (!String.IsNullOrEmpty(locale_value) && msdn != null) { msdn.Locale = locale_value; } string target_value = configuration.GetAttribute("linkTarget", String.Empty); if (!String.IsNullOrEmpty(target_value)) { linkTarget = target_value; } }
// instantiation logic public ExampleComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNodeIterator contentNodes = configuration.Select("examples"); foreach (XPathNavigator contentNode in contentNodes) { string file = contentNode.GetAttribute("file", String.Empty); file = Environment.ExpandEnvironmentVariables(file); if (String.IsNullOrEmpty(file)) { WriteMessage(MessageLevel.Error, String.Format("Each examples element must contain a file attribute.")); } LoadContent(file); } WriteMessage(MessageLevel.Info, String.Format("Loaded {0} code snippets", snippets.Count)); XPathNodeIterator colorsNodes = configuration.Select("colors"); foreach (XPathNavigator colorsNode in colorsNodes) { string language = colorsNode.GetAttribute("language", String.Empty); List <ColorizationRule> rules = new List <ColorizationRule>(); XPathNodeIterator colorNodes = colorsNode.Select("color"); foreach (XPathNavigator colorNode in colorNodes) { string pattern = colorNode.GetAttribute("pattern", String.Empty); string region = colorNode.GetAttribute("region", String.Empty); string name = colorNode.GetAttribute("class", String.Empty); if (String.IsNullOrEmpty(region)) { rules.Add(new ColorizationRule(pattern, name)); } else { rules.Add(new ColorizationRule(pattern, region, name)); } } colorization[language] = rules; WriteMessage(MessageLevel.Info, String.Format("Loaded {0} colorization rules for the language '{1}'.", rules.Count, language)); } context.AddNamespace("ddue", "http://ddue.schemas.microsoft.com/authoring/2003/5"); selector = XPathExpression.Compile("//ddue:codeReference"); selector.SetContext(context); }
/// <summary> /// Creates an instance of InheritDocumentationComponent class. /// </summary> /// <param name="configuration">Configuration section to be parsed.</param> /// <param name="data">A dictionary object with string as key and object as value.</param> public InheritDocumentationComponent(XPathNavigator configuration, Dictionary <string, object> data) : base(configuration, data) { // get the copy commands XPathNodeIterator copy_nodes = configuration.Select("copy"); foreach (XPathNavigator copy_node in copy_nodes) { // get the comments info string source_name = copy_node.GetAttribute("name", string.Empty); if (String.IsNullOrEmpty(source_name)) { throw new ConfigurationErrorsException("Each copy command must specify an index to copy from."); } // get the reflection info string reflection_name = copy_node.GetAttribute("use", String.Empty); if (String.IsNullOrEmpty(reflection_name)) { throw new ConfigurationErrorsException("Each copy command must specify an index to get reflection information from."); } this.index = (IndexedDocumentCache)data[source_name]; this.reflectionIndex = (IndexedDocumentCache)data[reflection_name]; } // Retrieve a message writer... if (index != null && index.Component != null) { if (_messageWriter == null) { BuildAssembler assembler = index.Component.BuildAssembler; if (assembler != null) { _messageWriter = assembler.MessageWriter; } } } if (_messageWriter == null && (reflectionIndex != null && reflectionIndex.Component != null)) { BuildAssembler assembler = reflectionIndex.Component.BuildAssembler; if (assembler != null) { _messageWriter = assembler.MessageWriter; } } }
public HxfGeneratorComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { // get configuration data inputValue = configuration.GetAttribute("input", String.Empty); if (!String.IsNullOrEmpty(inputValue)) { inputValue = Environment.ExpandEnvironmentVariables(inputValue); } outputValue = configuration.GetAttribute("output", String.Empty); if (!String.IsNullOrEmpty(outputValue)) { outputValue = Environment.ExpandEnvironmentVariables(outputValue); } // subscribe to component events assembler.ComponentEvent += new EventHandler(FileCreatedHandler); }
/// <summary> /// Creates a new instance of the <see cref="MHSComponent"/> class. /// </summary> /// <param name="assembler">The active <see cref="BuildAssembler"/>.</param> /// <param name="configuration">The current <see cref="XPathNavigator"/> of the configuration.</param> public MSHCComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { string tocFile = MHSDefault.TocFile; XPathNavigator data = configuration.SelectSingleNode(ConfigurationTag.Data); if (data != null) { string value = data.GetAttribute(ConfigurationAttr.Locale, string.Empty); if (!string.IsNullOrEmpty(value)) { _locale = value; } value = data.GetAttribute(ConfigurationAttr.SelfBranded, string.Empty); if (!string.IsNullOrEmpty(value)) { _selfBranded = bool.Parse(value); } value = data.GetAttribute(ConfigurationAttr.TopicVersion, string.Empty); if (!string.IsNullOrEmpty(value)) { _topicVersion = value; } value = data.GetAttribute(ConfigurationAttr.TocParent, string.Empty); if (!string.IsNullOrEmpty(value)) { _tocParent = value; } value = data.GetAttribute(ConfigurationAttr.TocParentVersion, string.Empty); if (!string.IsNullOrEmpty(value)) { _tocParentVersion = value; } value = data.GetAttribute(ConfigurationAttr.TocFile, string.Empty); if (!string.IsNullOrEmpty(value)) { tocFile = value; } } LoadToc(Path.GetFullPath(Environment.ExpandEnvironmentVariables(tocFile))); }
public PlatformsComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { // get the filter files XPathNodeIterator filterNodes = configuration.Select("filter"); foreach (XPathNavigator filterNode in filterNodes) { string filterFiles = filterNode.GetAttribute("files", String.Empty); if ((filterFiles == null) || (filterFiles.Length == 0)) { throw new ConfigurationErrorsException("The filter/@files attribute must specify a path."); } ParseDocuments(filterFiles); } //WriteMessage(MessageLevel.Info, String.Format("Indexed {0} elements.", index.Count)); }
//===================================================================== /// <inheritdoc /> public override void Initialize(XPathNavigator configuration) { // set up the context XPathNodeIterator context_nodes = configuration.Select("context"); foreach (XPathNavigator context_node in context_nodes) { string prefix = context_node.GetAttribute("prefix", String.Empty); string name = context_node.GetAttribute("name", String.Empty); context.AddNamespace(prefix, name); } // load the expression format XPathNavigator variable_node = configuration.SelectSingleNode("variable"); if (variable_node == null) { throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " + "specify a variable using the <variable> element."); } string xpath_format = variable_node.GetAttribute("expression", String.Empty); if ((xpath_format == null) || (xpath_format.Length == 0)) { throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " + "specify a variable expression using the expression attribute"); } xpath = XPathExpression.Compile(xpath_format); // load the subcomponents WriteMessage(MessageLevel.Info, "Loading subcomponents."); XPathNavigator components_node = configuration.SelectSingleNode("components"); if (components_node == null) { throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " + "specify subcomponents using the <components> element."); } components = BuildAssembler.LoadComponents(components_node); WriteMessage(MessageLevel.Info, "Loaded {0} subcomponents.", components.Count()); }
protected BuildComponent(BuildAssembler assembler, XPathNavigator configuration) { if (assembler == null) { throw new ArgumentNullException("assembler", "The assembler is required and cannot be null (or Nothing)."); } if (configuration == null) { throw new ArgumentNullException("configuration", "The configuration is required and cannot be null (or Nothing)."); } _assembler = assembler; this.WriteMessage(MessageLevel.Info, "Instantiating component."); }
public IntellisenseComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNavigator output_node = configuration.SelectSingleNode("output"); if (output_node != null) { string directory_value = output_node.GetAttribute("directory", String.Empty); if (!String.IsNullOrEmpty(directory_value)) { directory = Environment.ExpandEnvironmentVariables(directory_value); if (!Directory.Exists(directory)) { WriteMessage(MessageLevel.Error, String.Format("The output directory '{0}' does not exist.", directory)); } } } // a way to get additional information into the intellisense file XPathNodeIterator input_nodes = configuration.Select("input"); foreach (XPathNavigator input_node in input_nodes) { string file_value = input_node.GetAttribute("file", String.Empty); if (!String.IsNullOrEmpty(file_value)) { string file = Environment.ExpandEnvironmentVariables(file_value); ReadInputFile(file); } } context.AddNamespace("ddue", "http://ddue.schemas.microsoft.com/authoring/2003/5"); summaryExpression.SetContext(context); memberSummaryExpression.SetContext(context); returnsExpression.SetContext(context); parametersExpression.SetContext(context); parameterNameExpression.SetContext(context); templatesExpression.SetContext(context); templateNameExpression.SetContext(context); exceptionExpression.SetContext(context); exceptionCrefExpression.SetContext(context); }
//===================================================================== /// <inheritdoc /> public override void Initialize(XPathNavigator configuration) { // Get the condition XPathNavigator if_node = configuration.SelectSingleNode("if"); if (if_node == null) { throw new ConfigurationErrorsException("You must specify a condition using the <if> element."); } string condition_xpath = if_node.GetAttribute("condition", String.Empty); if (String.IsNullOrEmpty(condition_xpath)) { throw new ConfigurationErrorsException("You must define a condition attribute on the <if> element"); } condition = XPathExpression.Compile(condition_xpath); // Construct the true branch XPathNavigator then_node = configuration.SelectSingleNode("then"); if (then_node != null) { true_branch = BuildAssembler.LoadComponents(then_node); } // Construct the false branch XPathNavigator else_node = configuration.SelectSingleNode("else"); if (else_node != null) { false_branch = BuildAssembler.LoadComponents(else_node); } // Keep a pointer to the context for future use context = this.BuildAssembler.Context; }
public IfThenComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { // get the condition XPathNavigator if_node = configuration.SelectSingleNode("if"); if (if_node == null) { throw new ConfigurationErrorsException("You must specify a condition using the <if> element."); } string condition_xpath = if_node.GetAttribute("condition", String.Empty); if (String.IsNullOrEmpty(condition_xpath)) { throw new ConfigurationErrorsException(); } condition = XPathExpression.Compile(condition_xpath); // construct the true branch XPathNavigator then_node = configuration.SelectSingleNode("then"); if (then_node != null) { true_branch = BuildAssembler.LoadComponents(then_node); } // construct the false branch XPathNavigator else_node = configuration.SelectSingleNode("else"); if (else_node != null) { false_branch = BuildAssembler.LoadComponents(else_node); } // keep a pointer to the context for future use context = assembler.Context; }
public LiveExampleComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNavigator parsnip_node = configuration.SelectSingleNode("parsnip"); string approvedFile = null; if (parsnip_node != null) { approvedFile = parsnip_node.GetAttribute("approved-file", String.Empty); string omitBadExamplesValue = parsnip_node.GetAttribute("omit-bad-examples", String.Empty); if (!string.IsNullOrEmpty(omitBadExamplesValue)) { omitBadExamples = Boolean.Parse(omitBadExamplesValue); } //string runBadExamplesValue = parsnip_node.GetAttribute("run-bad-examples", String.Empty); //if (!string.IsNullOrEmpty(runBadExamplesValue)) // runBadExamples = Boolean.Parse(runBadExamplesValue); } if (string.IsNullOrEmpty(approvedFile)) { WriteMessage(MessageLevel.Warn, "No approved samples file specified; all available samples will be included."); } else { LoadApprovedFile(approvedFile); } context = new CustomContext(); context.AddNamespace("ddue", "http://ddue.schemas.microsoft.com/authoring/2003/5"); selector = XPathExpression.Compile("//ddue:codeReference"); selector.SetContext(context); }
public CopyFromIndexComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { // set up the context XPathNodeIterator context_nodes = configuration.Select("context"); foreach (XPathNavigator context_node in context_nodes) { string prefix = context_node.GetAttribute("prefix", String.Empty); string name = context_node.GetAttribute("name", String.Empty); context.AddNamespace(prefix, name); } // set up the indices XPathNodeIterator index_nodes = configuration.Select("index"); foreach (XPathNavigator index_node in index_nodes) { // get the name of the index string name = index_node.GetAttribute("name", String.Empty); if (String.IsNullOrEmpty(name)) { throw new ConfigurationErrorsException("Each index must have a unique name."); } // get the xpath for value nodes string value_xpath = index_node.GetAttribute("value", String.Empty); if (String.IsNullOrEmpty(value_xpath)) { WriteMessage(MessageLevel.Error, "Each index element must have a value attribute containing an XPath that describes index entries."); } // get the xpath for keys (relative to value nodes) string key_xpath = index_node.GetAttribute("key", String.Empty); if (String.IsNullOrEmpty(key_xpath)) { WriteMessage(MessageLevel.Error, "Each index element must have a key attribute containing an XPath (relative to the value XPath) that evaluates to the entry key."); } // get the cache size int cache = 10; string cache_value = index_node.GetAttribute("cache", String.Empty); if (!String.IsNullOrEmpty(cache_value)) { cache = Convert.ToInt32(cache_value); } // create the index IndexedDocumentCache index = new IndexedDocumentCache(this, key_xpath, value_xpath, context, cache); // search the data directories for entries XPathNodeIterator data_nodes = index_node.Select("data"); foreach (XPathNavigator data_node in data_nodes) { string base_value = data_node.GetAttribute("base", String.Empty); if (!String.IsNullOrEmpty(base_value)) { base_value = Environment.ExpandEnvironmentVariables(base_value); } bool recurse = false; string recurse_value = data_node.GetAttribute("recurse", String.Empty); if (!String.IsNullOrEmpty(recurse_value)) { recurse = (bool)Convert.ToBoolean(recurse_value); } // get the files string files = data_node.GetAttribute("files", String.Empty); if (String.IsNullOrEmpty(files)) { WriteMessage(MessageLevel.Error, "Each data element must have a files attribute specifying which files to index."); } // if ((files == null) || (files.Length == 0)) throw new ConfigurationErrorsException("When instantiating a CopyFromDirectory component, you must specify a directory path using the files attribute."); files = Environment.ExpandEnvironmentVariables(files); WriteMessage(MessageLevel.Info, String.Format("Searching for files that match '{0}'.", files)); index.AddDocuments(base_value, files, recurse); } WriteMessage(MessageLevel.Info, String.Format("Indexed {0} elements in {1} files.", index.Count, index.DocumentCount)); Data.Add(name, index); } // get the copy commands XPathNodeIterator copy_nodes = configuration.Select("copy"); foreach (XPathNavigator copy_node in copy_nodes) { string source_name = copy_node.GetAttribute("name", String.Empty); if (String.IsNullOrEmpty(source_name)) { throw new ConfigurationErrorsException("Each copy command must specify an index to copy from."); } string key_xpath = copy_node.GetAttribute("key", String.Empty); string source_xpath = copy_node.GetAttribute("source", String.Empty); if (String.IsNullOrEmpty(source_xpath)) { throw new ConfigurationErrorsException("When instantiating a CopyFromDirectory component, you must specify a source xpath format using the source attribute."); } string target_xpath = copy_node.GetAttribute("target", String.Empty); if (String.IsNullOrEmpty(target_xpath)) { throw new ConfigurationErrorsException("When instantiating a CopyFromDirectory component, you must specify a target xpath format using the target attribute."); } string attribute_value = copy_node.GetAttribute("attribute", String.Empty); string ignoreCase_value = copy_node.GetAttribute("ignoreCase", String.Empty); string missingEntryValue = copy_node.GetAttribute("missing-entry", String.Empty); string missingSourceValue = copy_node.GetAttribute("missing-source", String.Empty); string missingTargetValue = copy_node.GetAttribute("missing-target", String.Empty); IndexedDocumentCache index = (IndexedDocumentCache)Data[source_name]; CopyCommand copyCommand = new CopyCommand(index, key_xpath, source_xpath, target_xpath, attribute_value, ignoreCase_value); if (!String.IsNullOrEmpty(missingEntryValue)) { try { copyCommand.MissingEntry = (MessageLevel)Enum.Parse(typeof(MessageLevel), missingEntryValue, true); } catch (ArgumentException) { WriteMessage(MessageLevel.Error, String.Format("'{0}' is not a message level.", missingEntryValue)); } } if (!String.IsNullOrEmpty(missingSourceValue)) { try { copyCommand.MissingSource = (MessageLevel)Enum.Parse(typeof(MessageLevel), missingSourceValue, true); } catch (ArgumentException) { WriteMessage(MessageLevel.Error, String.Format("'{0}' is not a message level.", missingSourceValue)); } } if (!String.IsNullOrEmpty(missingTargetValue)) { try { copyCommand.MissingTarget = (MessageLevel)Enum.Parse(typeof(MessageLevel), missingTargetValue, true); } catch (ArgumentException) { WriteMessage(MessageLevel.Error, String.Format("'{0}' is not a message level.", missingTargetValue)); } } copy_commands.Add(copyCommand); } XPathNodeIterator component_nodes = configuration.Select("components/component"); foreach (XPathNavigator component_node in component_nodes) { // get the data to load the component string assembly_path = component_node.GetAttribute("assembly", String.Empty); if (String.IsNullOrEmpty(assembly_path)) { WriteMessage(MessageLevel.Error, "Each component element must have an assembly attribute."); } string type_name = component_node.GetAttribute("type", String.Empty); if (String.IsNullOrEmpty(type_name)) { WriteMessage(MessageLevel.Error, "Each component element must have a type attribute."); } // expand environment variables in the path assembly_path = Environment.ExpandEnvironmentVariables(assembly_path); //Console.WriteLine("loading {0} from {1}", type_name, assembly_path); try { Assembly assembly = Assembly.LoadFrom(assembly_path); CopyComponent component = (CopyComponent)assembly.CreateInstance(type_name, false, BindingFlags.Public | BindingFlags.Instance, null, new Object[2] { component_node.Clone(), Data }, null, null); if (component == null) { WriteMessage(MessageLevel.Error, String.Format("The type '{0}' does not exist in the assembly '{1}'.", type_name, assembly_path)); } else { components.Add(component); } } catch (IOException e) { WriteMessage(MessageLevel.Error, String.Format("A file access error occured while attempting to load the build component '{0}'. The error message is: {1}", assembly_path, e.Message)); } catch (BadImageFormatException e) { WriteMessage(MessageLevel.Error, String.Format("A syntax generator assembly '{0}' is invalid. The error message is: {1}.", assembly_path, e.Message)); } catch (TypeLoadException e) { WriteMessage(MessageLevel.Error, String.Format("The type '{0}' does not exist in the assembly '{1}'. The error message is: {2}", type_name, assembly_path, e.Message)); } catch (MissingMethodException e) { WriteMessage(MessageLevel.Error, String.Format("The type '{0}' in the assembly '{1}' does not have an appropriate constructor. The error message is: {2}", type_name, assembly_path, e.Message)); } catch (TargetInvocationException e) { WriteMessage(MessageLevel.Error, String.Format("An error occured while attempting to instantiate the type '{0}' in the assembly '{1}'. The error message is: {2}", type_name, assembly_path, e.InnerException.Message)); } catch (InvalidCastException) { WriteMessage(MessageLevel.Error, String.Format("The type '{0}' in the assembly '{1}' is not a SyntaxGenerator.", type_name, assembly_path)); } } WriteMessage(MessageLevel.Info, String.Format("Loaded {0} copy components.", components.Count)); }
public static int Main(string[] args) { ConsoleApplication.WriteBanner(); #region read command line arguments, and setup config // specify options OptionCollection options = new OptionCollection(); options.Add(new SwitchOption("?", "Show this help page.")); options.Add(new StringOption("config", "Specify a configuration file.", "configFilePath")); // process options ParseArgumentsResult results = options.ParseArguments(args); // process help option if (results.Options["?"].IsPresent) { Console.WriteLine("TocBuilder [options] rootDirectory"); options.WriteOptionSummary(Console.Out); return(0); } // check for invalid options if (!results.Success) { results.WriteParseErrors(Console.Out); return(1); } // check for manifest if (results.UnusedArguments.Count != 1) { Console.WriteLine("You must supply exactly one manifest file."); return(1); } string manifest = results.UnusedArguments[0]; // Load the configuration file XPathDocument configuration; try { if (results.Options["config"].IsPresent) { configuration = ConsoleApplication.GetConfigurationFile((string)results.Options["config"].Value); } else { configuration = ConsoleApplication.GetConfigurationFile(); } } catch (IOException e) { ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("The specified configuration file could not be loaded. The error message is: {0}", e.Message)); return(1); } catch (XmlException e) { ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("The specified configuration file is not well-formed. The error message is: {0}", e.Message)); return(1); } #endregion // create a BuildAssembler to do the work BuildAssembler buildAssembler = new BuildAssembler(); try { // load the context XPathNavigator contextNode = configuration.CreateNavigator().SelectSingleNode("/configuration/dduetools/builder/context"); if (contextNode != null) { buildAssembler.Context.Load(contextNode); } // load the build components XPathNavigator componentsNode = configuration.CreateNavigator().SelectSingleNode("/configuration/dduetools/builder/components"); if (componentsNode != null) { buildAssembler.AddComponents(componentsNode); } // proceed thorugh the build manifest, processing all topics named there int count = buildAssembler.Apply(manifest); ConsoleApplication.WriteMessage(LogLevel.Info, String.Format("Processed {0} topics", count)); } finally { buildAssembler.Dispose(); } return(0); }
public IntellisenseComponent2(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNavigator output_node = configuration.SelectSingleNode("output"); if (output_node != null) { string directory_value = output_node.GetAttribute("directory", String.Empty); if (!String.IsNullOrEmpty(directory_value)) { directory = Environment.ExpandEnvironmentVariables(directory_value); if (!Directory.Exists(directory)) { WriteMessage(MessageLevel.Error, String.Format("The output directory '{0}' does not exist.", directory)); } } } XPathNavigator expression_node = configuration.SelectSingleNode("expressions"); if (expression_node != null) { string root = expression_node.GetAttribute("root", string.Empty); try { rootExpression = XPathExpression.Compile(root); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", root)); } string assembly = expression_node.GetAttribute("assembly", string.Empty); try { assemblyExpression = XPathExpression.Compile(assembly); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", assembly)); } string summary = expression_node.GetAttribute("summary", string.Empty); try { summaryExpression = XPathExpression.Compile(summary); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", summary)); } string parameters = expression_node.GetAttribute("parameters", string.Empty); try { parametersExpression = XPathExpression.Compile(parameters); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", parameters)); } string parameterContent = expression_node.GetAttribute("parameterContent", string.Empty); try { parameterContentExpression = XPathExpression.Compile(parameterContent); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", parameterContent)); } string templates = expression_node.GetAttribute("templates", string.Empty); try { templatesExpression = XPathExpression.Compile(templates); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", templates)); } string templateContent = expression_node.GetAttribute("templateContent", string.Empty); try { templateContentExpression = XPathExpression.Compile(templateContent); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", templateContent)); } string returns = expression_node.GetAttribute("returns", string.Empty); try { returnsExpression = XPathExpression.Compile(returns); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", returns)); } string exception = expression_node.GetAttribute("exception", string.Empty); try { exceptionExpression = XPathExpression.Compile(exception); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", exception)); } string exceptionCref = expression_node.GetAttribute("exceptionCref", string.Empty); try { exceptionCrefExpression = XPathExpression.Compile(exceptionCref); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", exceptionCref)); } string enumeration = expression_node.GetAttribute("enumeration", string.Empty); try { enumerationExpression = XPathExpression.Compile(enumeration); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", enumeration)); } string enumerationApi = expression_node.GetAttribute("enumerationApi", string.Empty); try { enumerationApiExpression = XPathExpression.Compile(enumerationApi); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", enumerationApi)); } string memberSummary = expression_node.GetAttribute("memberSummary", string.Empty); try { memberSummaryExpression = XPathExpression.Compile(memberSummary); } catch (XPathException) { WriteMessage(MessageLevel.Error, String.Format("The expression '{0}' is not a valid XPath expression.", memberSummary)); } } // a way to get additional information into the intellisense file XPathNodeIterator input_nodes = configuration.Select("input"); foreach (XPathNavigator input_node in input_nodes) { string file_value = input_node.GetAttribute("file", String.Empty); if (!String.IsNullOrEmpty(file_value)) { string file = Environment.ExpandEnvironmentVariables(file_value); ReadInputFile(file); } } }
// instantiation logic public ResolveReferenceLinksComponent2(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { // base-url is an xpath expression applied against the current document to pick up the save location of the // document. If specified, local links will be made relative to the base-url. string baseUrlValue = configuration.GetAttribute("base-url", String.Empty); if (!String.IsNullOrEmpty(baseUrlValue)) { baseUrl = XPathExpression.Compile(baseUrlValue); } // url-format is a string format that is used to format the value of local href attributes. The default is // "{0}.htm" for backwards compatibility. string hrefFormatValue = configuration.GetAttribute("href-format", String.Empty); if (!String.IsNullOrEmpty(hrefFormatValue)) { hrefFormat = hrefFormatValue; } // the container XPath can be replaced; this is useful string containerValue = configuration.GetAttribute("container", String.Empty); if (!String.IsNullOrEmpty(containerValue)) { XmlTargetCollectionUtilities.ContainerExpression = containerValue; } targets = new TargetCollection(); resolver = new LinkTextResolver(targets); XPathNodeIterator targets_nodes = configuration.Select("targets"); foreach (XPathNavigator targets_node in targets_nodes) { // get target type string typeValue = targets_node.GetAttribute("type", String.Empty); if (String.IsNullOrEmpty(typeValue)) { WriteMessage(MessageLevel.Error, "Each targets element must have a type attribute that specifies which type of links to create."); } LinkType2 type = LinkType2.None; try { type = (LinkType2)Enum.Parse(typeof(LinkType2), typeValue, true); if ((type == LinkType2.Msdn) && (msdn == null)) { WriteMessage(MessageLevel.Info, "Creating MSDN URL resolver."); msdn = new MsdnResolver(); } } catch (ArgumentException) { WriteMessage(MessageLevel.Error, String.Format("'{0}' is not a supported reference link type.", typeValue)); } // get base directory string baseValue = targets_node.GetAttribute("base", String.Empty); // get file pattern string filesValue = targets_node.GetAttribute("files", String.Empty); if (String.IsNullOrEmpty(filesValue)) { WriteMessage(MessageLevel.Error, "Each targets element must have a files attribute specifying which target files to load."); } // determine whether to search recursively bool recurse = false; string recurseValue = targets_node.GetAttribute("recurse", String.Empty); if (!String.IsNullOrEmpty(recurseValue)) { if (String.Compare(recurseValue, Boolean.TrueString, true) == 0) { recurse = true; } else if (String.Compare(recurseValue, Boolean.FalseString, true) == 0) { recurse = false; } else { WriteMessage(MessageLevel.Error, String.Format("On the targets element, recurse='{0}' is not an allowed value.", recurseValue)); } } // turn baseValue and filesValue into directoryPath and filePattern string fullPath; if (String.IsNullOrEmpty(baseValue)) { fullPath = filesValue; } else { fullPath = Path.Combine(baseValue, filesValue); } fullPath = Environment.ExpandEnvironmentVariables(fullPath); string directoryPath = Path.GetDirectoryName(fullPath); if (String.IsNullOrEmpty(directoryPath)) { directoryPath = Environment.CurrentDirectory; } string filePattern = Path.GetFileName(fullPath); // verify that directory exists if (!Directory.Exists(directoryPath)) { WriteMessage(MessageLevel.Error, String.Format("The targets directory '{0}' does not exist.", directoryPath)); } // add the specified targets from the directory WriteMessage(MessageLevel.Info, String.Format("Searching directory '{0}' for targets files of the form '{1}'.", directoryPath, filePattern)); AddTargets(directoryPath, filePattern, recurse, type); } WriteMessage(MessageLevel.Info, String.Format("Loaded {0} reference targets.", targets.Count)); string locale_value = configuration.GetAttribute("locale", String.Empty); if (!String.IsNullOrEmpty(locale_value) && msdn != null) { msdn.Locale = locale_value; } string target_value = configuration.GetAttribute("linkTarget", String.Empty); if (!String.IsNullOrEmpty(target_value)) { linkTarget = target_value; } }
public WdxResolveConceptualLinksComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { //System.Diagnostics.Debugger.Break(); string av; // temporary attribute values // base-url is an xpath expression that is used to lookup the url that relative links need to be // relative to. The lookup is done against the current document. This attribute is needed only if // one of the targets uses relative links that are not in the current directory. If not specified, // the target uses the url from the meta data unchanged. av = configuration.GetAttribute("base-url", String.Empty); if (!String.IsNullOrEmpty(av)) { baseUrl = CompileXPathExpression(av); } // invalid-link-format specifies a string format to be used for invalid (target is not a valid GUID) // links. The string formatter is called with parameter {0} set to the target attribute of the link, // and parameter {1} set to the tag content from the source document. A reasonable default is used // if the value is not specified. av = configuration.GetAttribute("invalid-link-format", String.Empty); if (!String.IsNullOrEmpty(av)) { invalidLinkFormat = av; } // broken-link-format specifies a string format to be used for broken links (target GUID lookup // failed in all targets). The string formatter is called with parameter {0} set to the target attribute // of the link, and parameter {1} set to the tag content from the source document. A reasonable // default is used if the value is not specified. av = configuration.GetAttribute("broken-link-format", String.Empty); if (!String.IsNullOrEmpty(av)) { brokenLinkFormat = av; } // <targets> specifies a lookup solution for each possible set of link targets. Each target must // specify either a lookup file or error condition (invalid-link, broken-link). XPathNodeIterator targetsNodes = configuration.Select("targets"); foreach (XPathNavigator targetsNode in targetsNodes) { // lookup-file specifies the meta data file used for looking up URLs and titles. The value will // go through environment variable expansion during setup and then through string formatting after // computing the url, with parameter {0} set to the link target GUID. This attribute is required. string lookupFile = targetsNode.GetAttribute("lookup-file", String.Empty); if (string.IsNullOrEmpty(lookupFile)) { WriteMessage(MessageLevel.Error, "Each target must have a lookup-file attribute."); } else { lookupFile = Environment.ExpandEnvironmentVariables(lookupFile); } // check-file-exists if specified ensures that the link target file exists; if it doesn't exist we // take the broken link action. string checkFileExists = targetsNode.GetAttribute("check-file-exists", String.Empty); if (!String.IsNullOrEmpty(checkFileExists)) { checkFileExists = Environment.ExpandEnvironmentVariables(checkFileExists); } // url is an xpath expression that is used to lookup the link url in the meta data file. The default // value can be used to lookup the url in .cmp.xml files. av = targetsNode.GetAttribute("url", String.Empty); XPathExpression url = String.IsNullOrEmpty(av) ? XPathExpression.Compile("concat(/metadata/topic/@id,'.htm')") : XPathExpression.Compile(av); // text is an xpath expression that is used to lookup the link text in the meta data file. The default // value can be used to lookup the link text in .cmp.xml files. av = targetsNode.GetAttribute("text", string.Empty); XPathExpression text = String.IsNullOrEmpty(av) ? XPathExpression.Compile("string(/metadata/topic/title)") : XPathExpression.Compile(av); // relative-url determines whether the links from this target set are relative to the current page // and need to be adjusted to the base directory. av = targetsNode.GetAttribute("relative-url", String.Empty); bool relativeUrl = String.IsNullOrEmpty(av) ? false : Convert.ToBoolean(av);; // format is a format string that is used to generate the link. Parameter {0} is the url; // parameter {1} is the text. The default creates a standard HTML link. string format = targetsNode.GetAttribute("format", String.Empty); if (String.IsNullOrEmpty(format)) { format = defaultFormat; } // target looks OK targetSets.Add(new TargetSet(lookupFile, checkFileExists, url, text, relativeUrl, format)); } WriteMessage(MessageLevel.Info, String.Format("Collected {0} targets directories.", targetSets.Count)); }
public ResolveReferenceLinksComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { }
public CopyFromFileComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } string data_name = null; // get information about the data file XPathNodeIterator data_nodes = configuration.Select("data"); foreach (XPathNavigator data_node in data_nodes) { string data_file = data_node.GetAttribute("file", String.Empty); if (String.IsNullOrEmpty(data_file)) { WriteMessage(MessageLevel.Error, "Data elements must have a file attribute specifying a file from which to load data."); } data_file = Environment.ExpandEnvironmentVariables(data_file); data_name = data_node.GetAttribute("name", String.Empty); if (String.IsNullOrEmpty(data_name)) { data_name = Guid.NewGuid().ToString(); } // load a schema, if one is specified string schema_file = data_node.GetAttribute("schema", String.Empty); XmlReaderSettings settings = new XmlReaderSettings(); if (!String.IsNullOrEmpty(schema_file)) { settings.Schemas.Add(null, schema_file); } // load the document WriteMessage(MessageLevel.Info, String.Format("Loading data file '{0}'.", data_file)); using (XmlReader reader = XmlReader.Create(data_file, settings)) { XPathDocument data_document = new XPathDocument(reader); Data.Add(data_name, data_document); } } // get the source and target expressions for each copy command XPathNodeIterator copy_nodes = configuration.Select("copy"); foreach (XPathNavigator copy_node in copy_nodes) { string source_name = copy_node.GetAttribute("name", String.Empty); if (String.IsNullOrEmpty(source_name)) { source_name = data_name; } XPathDocument source_document = (XPathDocument)Data[source_name]; string source_xpath = copy_node.GetAttribute("source", String.Empty); if (String.IsNullOrEmpty(source_xpath)) { throw new ConfigurationErrorsException("When instantiating a CopyFromFile component, you must specify a source xpath format using the source attribute."); } string target_xpath = copy_node.GetAttribute("target", String.Empty); if (String.IsNullOrEmpty(target_xpath)) { throw new ConfigurationErrorsException("When instantiating a CopyFromFile component, you must specify a target xpath format using the target attribute."); } copy_commands.Add(new CopyFromFileCommand(source_document, source_xpath, target_xpath)); } }
public TaskGrabberComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNavigator keywordsNode = configuration.SelectSingleNode("keywords"); if (keywordsNode == null) { return; } string filespec = keywordsNode.GetAttribute("files", String.Empty); filespec = Environment.ExpandEnvironmentVariables(filespec); string keywordXPath = keywordsNode.GetAttribute("keyword", String.Empty); string topicXPath = keywordsNode.GetAttribute("topic", String.Empty); if (String.IsNullOrEmpty(keywordXPath) || String.IsNullOrEmpty(topicXPath) || String.IsNullOrEmpty(filespec)) { return; } xpathFromConfig = keywordXPath; string[] keywordFiles = null; if (File.Exists(filespec)) { // we're loading a single file AddBKeywords(filespec, topicXPath, keywordXPath); } else { // must be loading a set of files if (Directory.Exists(filespec)) { // if they specified a directory, transform all the files in the directory keywordFiles = Directory.GetFiles(filespec); } else { // it's not a file or a directory, maybe it's a path with wildcards string directoryPath = Path.GetDirectoryName(filespec); string filePath = Path.GetFileName(filespec); keywordFiles = Directory.GetFiles(directoryPath, filePath); } foreach (string file in keywordFiles) { // load targets from each file AddBKeywords(file, topicXPath, keywordXPath); } } // set up the context // put in a default entry for ddue nsManager.AddNamespace("ddue", "http://ddue.schemas.microsoft.com/authoring/2003/6"); // look for context nodes, which could override the default XPathNodeIterator contextNodes = configuration.Select("context"); foreach (XPathNavigator contextNode in contextNodes) { string prefix = contextNode.GetAttribute("prefix", String.Empty); string uri = contextNode.GetAttribute("name", String.Empty); nsManager.AddNamespace(prefix, uri); } // set up the index of source files XPathNodeIterator sourceNodes = configuration.Select("source"); foreach (XPathNavigator sourceNode in sourceNodes) { string valueXPath = sourceNode.GetAttribute("value", String.Empty); string keyXPath = sourceNode.GetAttribute("key", String.Empty); if (String.IsNullOrEmpty(valueXPath) || String.IsNullOrEmpty(keyXPath)) { WriteMessage(MessageLevel.Error, "@key and @value must be set in the 'source' node."); return; } keyQuery = XPathExpression.Compile(keyXPath); valueQuery = XPathExpression.Compile(valueXPath); // search the data directories for entries XPathNodeIterator dataNodes = sourceNode.Select("data"); foreach (XPathNavigator dataNode in dataNodes) { string dataFiles = dataNode.GetAttribute("files", String.Empty); dataFiles = Environment.ExpandEnvironmentVariables(dataFiles); if ((dataFiles == null) || (dataFiles.Length == 0)) { throw new ConfigurationErrorsException("When instantiating a CopyFromDirectory component, you must specify a directory path using the files attribute."); } WriteMessage(MessageLevel.Info, String.Format("Searching for files that match '{0}'.", dataFiles)); int fileCount = ParseDocuments(dataFiles); WriteMessage(MessageLevel.Info, String.Format("Found {0} files.", fileCount)); } WriteMessage(MessageLevel.Info, String.Format("Indexed {0} elements.", index.Count)); } // get the copy commands XPathNodeIterator copyNodes = configuration.Select("copy"); foreach (XPathNavigator copyNode in copyNodes) { string sourceXPath = copyNode.GetAttribute("source", String.Empty); string targetXPath = copyNode.GetAttribute("target", String.Empty); if (String.IsNullOrEmpty(sourceXPath) || String.IsNullOrEmpty(targetXPath)) { WriteMessage(MessageLevel.Error, "@source and @target must be set in the 'copy' node."); return; } copySets.Add(new CopySet(sourceXPath, targetXPath, nsManager)); } }
// Instantiation logic public ResolveConceptualLinksComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { string showBrokenLinkTextValue = configuration.GetAttribute("showBrokenLinkText", String.Empty); if (!String.IsNullOrEmpty(showBrokenLinkTextValue)) { showBrokenLinkText = Convert.ToBoolean(showBrokenLinkTextValue); } 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)) { 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)) { 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 LinkType type = LinkType.None; try { type = (LinkType)Enum.Parse(typeof(LinkType), typeValue, true); } catch (ArgumentException) { 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 TargetDirectory targetDirectory = new TargetDirectory(baseValue, urlExpression, textExpression, type); targetDirectories.Add(targetDirectory); } WriteMessage(MessageLevel.Info, String.Format("Collected {0} targets directories.", targetDirectories.Count)); }
public SyntaxComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNavigator syntax_node = configuration.SelectSingleNode("syntax"); string syntax_input_xpath = syntax_node.GetAttribute("input", String.Empty); if (String.IsNullOrEmpty(syntax_input_xpath)) { throw new ConfigurationErrorsException("You must specify an XPath for input in the syntax element."); } syntax_input = XPathExpression.Compile(syntax_input_xpath); string syntax_output_xpath = syntax_node.GetAttribute("output", String.Empty); if (String.IsNullOrEmpty(syntax_output_xpath)) { throw new ConfigurationErrorsException("You must specify an XPath for output in the syntax element."); } syntax_output = XPathExpression.Compile(syntax_output_xpath); writerType = typeof(ManagedSyntaxWriter); //if (writerType == null) Console.WriteLine("null writer"); XPathNodeIterator generator_nodes = configuration.Select("generators/generator"); foreach (XPathNavigator generator_node in generator_nodes) { // get the data to load the generator string assembly_path = generator_node.GetAttribute("assembly", String.Empty); if (String.IsNullOrEmpty(assembly_path)) { WriteMessage(MessageLevel.Error, "Each generator element must have an assembly attribute."); } string type_name = generator_node.GetAttribute("type", String.Empty); if (String.IsNullOrEmpty(type_name)) { WriteMessage(MessageLevel.Error, "Each generator element must have a type attribute."); } // expand environment variables in the path assembly_path = Environment.ExpandEnvironmentVariables(assembly_path); //Console.WriteLine("loading {0} from {1}", type_name, assembly_path); try { Assembly assembly = Assembly.LoadFrom(assembly_path); SyntaxGenerator generator = (SyntaxGenerator)assembly.CreateInstance(type_name, false, BindingFlags.Public | BindingFlags.Instance, null, new Object[1] { generator_node.Clone() }, null, null); if (generator == null) { WriteMessage(MessageLevel.Error, String.Format("The type '{0}' does not exist in the assembly '{1}'.", type_name, assembly_path)); } else { generators.Add(generator); } } catch (IOException e) { WriteMessage(MessageLevel.Error, String.Format("A file access error occured while attempting to load the build component '{0}'. The error message is: {1}", assembly_path, e.Message)); } catch (BadImageFormatException e) { WriteMessage(MessageLevel.Error, String.Format("A syntax generator assembly '{0}' is invalid. The error message is: {1}.", assembly_path, e.Message)); } catch (TypeLoadException e) { WriteMessage(MessageLevel.Error, String.Format("The type '{0}' does not exist in the assembly '{1}'. The error message is: {2}", type_name, assembly_path, e.Message)); } catch (MissingMethodException e) { WriteMessage(MessageLevel.Error, String.Format("The type '{0}' in the assembly '{1}' does not have an appropriate constructor. The error message is: {2}", type_name, assembly_path, e.Message)); } catch (TargetInvocationException e) { WriteMessage(MessageLevel.Error, String.Format("An error occured while attempting to instantiate the type '{0}' in the assembly '{1}'. The error message is: {2}", type_name, assembly_path, e.InnerException.Message)); } catch (InvalidCastException) { WriteMessage(MessageLevel.Error, String.Format("The type '{0}' in the assembly '{1}' is not a SyntaxGenerator.", type_name, assembly_path)); } } WriteMessage(MessageLevel.Info, String.Format("Loaded {0} syntax generators.", generators.Count)); }