/// <summary> /// Creates a CompoundFileEnumerator from an XML configuration. /// </summary> /// <param name="root">XML root element of the compound file enumerator configuration.</param> /// <returns>Instance of CompoundFileEnumerator configured as specified in the XML data.</returns> public static CompoundFileEnumerator BuildFromXml(XElement root) { // Check root element of configuration. if (root.Name.LocalName == XML_ELEMENT_FILE_SOURCES) { var builder = CompoundFileEnumeratorBuilder.Begin(); // Iterate over all Directory elements and create directory file enumerators. foreach (var directory in root.Elements().Where(element => element.Name.LocalName == XML_ELEMENT_DIRECTORY)) { var pathAttribute = directory.Attribute(XML_ATTRIBUTE_PATH); var includeAttribute = directory.Attribute(XML_ATTRIBUTE_INCLUDE); var excludeAttribute = directory.Attribute(XML_ATTRIBUTE_EXCLUDE); var patternsAttribute = directory.Attribute(XML_ATTRIBUTE_PATTERNS); var recursiveAttribute = directory.Attribute(XML_ATTRIBUTE_RECURSIVE); if (pathAttribute != null && !string.IsNullOrEmpty(pathAttribute.Value)) { string path = pathAttribute.Value.Trim(); bool recursive; if (recursiveAttribute == null || bool.TryParse(recursiveAttribute.Value, out recursive)) { recursive = false; } HashSet <string> includePatterns = new HashSet <string>(); HashSet <string> excludePatterns = new HashSet <string>(); FillListFromAttribute(includeAttribute, includePatterns); FillListFromAttribute(patternsAttribute, includePatterns); FillListFromAttribute(excludeAttribute, excludePatterns); builder = builder.DirectoryEnumerator(path, recursive, includePatterns.ToArray(), excludePatterns.ToArray()); builder.AddFiltersFromXml(directory); } } // Iterate over all File elements and create direct file enumerators. foreach (var file in root.Elements().Where(element => element.Name.LocalName == XML_ELEMENT_FILE)) { var pathAttribute = file.Attribute(XML_ATTRIBUTE_PATH); if (pathAttribute != null && !string.IsNullOrEmpty(pathAttribute.Value)) { string path = pathAttribute.Value.Trim(); builder = builder.FileEnumerator(path); builder.AddFiltersFromXml(file); } } // Iterate over all Catalogue elements and create catalogue enumerators. foreach (var catalogue in root.Elements().Where(element => element.Name.LocalName == XML_ELEMENT_CATALOGUE)) { var pathAttribute = catalogue.Attribute(XML_ATTRIBUTE_PATH); var typeAttribute = catalogue.Attribute(XML_ATTRIBUTE_TYPE); var recursiveAttribute = catalogue.Attribute(XML_ATTRIBUTE_RECURSIVE); // Select by catalogue path if (pathAttribute != null && !string.IsNullOrEmpty(pathAttribute.Value) && typeAttribute == null) { string path = pathAttribute.Value.Trim(); var fileCatalogueEnumeratorType = FileCatalogueEnumerators.GetFileCatalogueEnumeratorTypeForPath(path); var fileCatalogueEnumerator = fileCatalogueEnumeratorType.CreateAndConfigure(catalogue.Element(XML_ELEMENT_CONFIGURATION)) as IFileCatalogueEnumerator; if (fileCatalogueEnumerator != null) { if (recursiveAttribute != null) { bool recursive = false; if (bool.TryParse(recursiveAttribute.Value, out recursive)) { fileCatalogueEnumerator.Recursive = recursive; } } fileCatalogueEnumerator.FileCataloguePath = path; builder = builder.FileCatalogueEnumerator(fileCatalogueEnumerator); builder.AddFiltersFromXml(catalogue); } } else // Create from type and configure if (typeAttribute != null && !string.IsNullOrEmpty(typeAttribute.Value)) { var fileCatalogueEnumerator = FileCatalogueEnumerators.CreateFileCatalogueEnumerator(catalogue); if (fileCatalogueEnumerator != null) { if (recursiveAttribute != null) { bool recursive = false; if (bool.TryParse(recursiveAttribute.Value, out recursive)) { fileCatalogueEnumerator.Recursive = recursive; } } if (pathAttribute != null && !string.IsNullOrEmpty(pathAttribute.Value)) { fileCatalogueEnumerator.FileCataloguePath = pathAttribute.Value.Trim(); } builder = builder.FileCatalogueEnumerator(fileCatalogueEnumerator); builder.AddFiltersFromXml(catalogue); } } } // Iterate over all Source elements and create catalogue enumerators. foreach (var source in root.Elements().Where(element => element.Name.LocalName == XML_ELEMENT_SOURCE)) { // Create from type and configure var fileEnumerator = FileEnumerators.CreateFileEnumerator(source); if (fileEnumerator != null) { builder = builder.FileEnumerator(fileEnumerator); builder.AddFiltersFromXml(source); } } return(builder.End()); } return(null); }
/// <summary> /// Adds a file catalogue enumerator to the compound file enumerator. /// </summary> /// <param name="fileCataloguePath">File catalogue path for which a file catalogue enumerator should be added.</param> /// <returns></returns> public CompoundFileEnumeratorBuilder FileCatalogueEnumerator(string fileCataloguePath) { return(FileCatalogueEnumerator(FileCatalogueEnumerators.GetFileCatalogueEnumeratorForPath(fileCataloguePath))); }