public override XPathNavigator GetContent(string key) { XPathNavigator navigator = _cache[key]; if (navigator != null) { return(navigator); } if (_document != null) { navigator = _document.GetContent(key); if (navigator != null) { _cache.Add(key, navigator); return(navigator); } } if (_documents != null && _documents.Count != 0) { for (int i = 0; i < _documents.Count; i++) { DatabaseIndexedDocument document = _documents[i]; navigator = document.GetContent(key); if (navigator != null) { _cache.Add(key, navigator); break; } } } return(navigator); }
protected override void Dispose(bool disposing) { if (_document != null) { _document.Dispose(); _document = null; } }
public DatabaseIndexedDocumentSource(CopyFromIndexComponent component, string keyXPath, string valueXPath, XmlNamespaceManager context, int cacheSize, bool isSystem) : base(component, keyXPath, valueXPath, context, cacheSize) { _document = new DatabaseIndexedDocument(isSystem); _cache = new DatabaseIndexedDocumentCache(100); }
private void Dispose(bool disposing) { if (_document != null) { _document.Dispose(); _document = null; } }
public void AddDocument(DatabaseIndexedDocument document) { if (document == null) { return; } if (_documents == null) { _documents = new List <DatabaseIndexedDocument>(); } _documents.Add(document); }
public DatabaseIndexedBuilder(string workingDir) { _document = new DatabaseIndexedDocument(true, true, workingDir); // The following are the usual key/value in the configuration file... string keyXPath = "@id"; string valueXPath = "/reflection/apis/api"; CustomContext context = new CustomContext(); _keyExpression = XPathExpression.Compile(keyXPath); _keyExpression.SetContext(context); _valueExpression = XPathExpression.Compile(valueXPath); _valueExpression.SetContext(context); }
private void ProcessCommentsIndex(XPathNavigator indexNode, CustomContext context, IDictionary <string, object> globalData) { MemoryIndexedDocumentSource memorySource = null; DatabaseIndexedDocumentSource databaseSource = null; // get the name of the index string name = indexNode.GetAttribute("name", String.Empty); if (String.IsNullOrEmpty(name)) { throw new BuildComponentException("Each index must have a unique name."); } // get the xpath for value nodes string valueXPath = indexNode.GetAttribute("value", String.Empty); if (String.IsNullOrEmpty(valueXPath)) { 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 keyXPath = indexNode.GetAttribute("key", String.Empty); if (String.IsNullOrEmpty(keyXPath)) { 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 cacheValue = indexNode.GetAttribute("cache", String.Empty); if (!String.IsNullOrEmpty(cacheValue)) { cache = Convert.ToInt32(cacheValue); } HashSet <string> sourceDirs = new HashSet <string>( StringComparer.OrdinalIgnoreCase); // create the index memorySource = new MemoryIndexedDocumentSource(_component, keyXPath, valueXPath, context, cache); // Search for the persistent data sources for entries... XPathNodeIterator sourcesNodes = indexNode.Select("sources"); foreach (XPathNavigator sourcesNode in sourcesNodes) { DataSources dataSources = new DataSources(false, sourcesNode); if (dataSources.IsValid) { // Currently, database is supported for systems only... if (!dataSources.IsSystem && !dataSources.IsDatabase) { dataSources = null; } } else { dataSources = null; } if (dataSources != null && dataSources.Exists) { if (databaseSource == null) { databaseSource = new DatabaseIndexedDocumentSource( _component, keyXPath, valueXPath, context, cache, true); } if (!databaseSource.IsInitialized) { sourceDirs.UnionWith(dataSources.Sources); databaseSource.Initialize(dataSources.OutputDir, false); } else { DatabaseIndexedDocument document = new DatabaseIndexedDocument(true, false, dataSources.OutputDir); if (document.Exists) { sourceDirs.UnionWith(dataSources.Sources); databaseSource.AddDocument(document); } } } } // search the data directories for entries XPathNodeIterator dataNodes = indexNode.Select("data"); foreach (XPathNavigator dataNode in dataNodes) { string baseValue = dataNode.GetAttribute("base", String.Empty); if (!String.IsNullOrEmpty(baseValue)) { baseValue = Environment.ExpandEnvironmentVariables(baseValue); } bool isSystem = false; string systemValue = dataNode.GetAttribute("system", String.Empty); if (!String.IsNullOrEmpty(systemValue)) { isSystem = Convert.ToBoolean(systemValue); } bool recurse = false; string recurseValue = dataNode.GetAttribute("recurse", String.Empty); if (!String.IsNullOrEmpty(recurseValue)) { recurse = Convert.ToBoolean(recurseValue); } bool warnOverride = true; string warningValue = dataNode.GetAttribute("warnOverride", String.Empty); if (!String.IsNullOrEmpty(warningValue)) { warnOverride = Convert.ToBoolean(warningValue); } // get the files string files = dataNode.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 BuildComponentException("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)); if (isSystem && sourceDirs.Count != 0 && Directory.Exists(baseValue)) { // For consistent, we make sure all directory paths // end with backslash... string sourceDir = String.Copy(baseValue); if (!sourceDir.EndsWith("\\")) { sourceDir += "\\"; } // If included already in the persistent sources, we // will not load it into memory... if (sourceDirs.Contains(sourceDir)) { continue; } } memorySource.AddDocuments(baseValue, files, recurse, true, warnOverride); } WriteMessage(MessageLevel.Info, String.Format( "Indexed {0} elements in {1} files.", memorySource.Count, memorySource.DocumentCount)); globalData.Add(name, this); _documentSources[name] = new IndexedDocumentSources(_component, databaseSource, memorySource); }
private void ProcessReflectionIndex(XPathNavigator indexNode, CustomContext context, IDictionary <string, object> globalData) { MemoryIndexedDocumentSource memorySource = null; DatabaseIndexedDocumentSource databaseSource = null; // get the name of the index string name = indexNode.GetAttribute("name", String.Empty); if (String.IsNullOrEmpty(name)) { throw new BuildComponentException("Each index must have a unique name."); } // get the xpath for value nodes string valueXPath = indexNode.GetAttribute("value", String.Empty); if (String.IsNullOrEmpty(valueXPath)) { 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 keyXPath = indexNode.GetAttribute("key", String.Empty); if (String.IsNullOrEmpty(keyXPath)) { 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 cacheValue = indexNode.GetAttribute("cache", String.Empty); if (!String.IsNullOrEmpty(cacheValue)) { cache = Convert.ToInt32(cacheValue); } // create the index memorySource = new MemoryIndexedDocumentSource(_component, keyXPath, valueXPath, context, cache); // search the data directories for entries XPathNodeIterator dataNodes = indexNode.Select("data"); foreach (XPathNavigator dataNode in dataNodes) { string baseValue = dataNode.GetAttribute("base", String.Empty); if (!String.IsNullOrEmpty(baseValue)) { baseValue = Environment.ExpandEnvironmentVariables(baseValue); } bool recurse = false; string recurseValue = dataNode.GetAttribute("recurse", String.Empty); if (!String.IsNullOrEmpty(recurseValue)) { recurse = Convert.ToBoolean(recurseValue); } bool warnOverride = true; string warningValue = dataNode.GetAttribute("warnOverride", String.Empty); if (!String.IsNullOrEmpty(warningValue)) { warnOverride = Convert.ToBoolean(warningValue); } // get the files string files = dataNode.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 BuildComponentException("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)); DataSource dataSource = null; XPathNavigator nodeDataSource = dataNode.SelectSingleNode("source"); if (nodeDataSource != null) { dataSource = new DataSource(false, nodeDataSource); if (dataSource.IsValid) { // Currently, database is supported for systems only... if (!dataSource.IsSystem && !dataSource.IsDatabase) { dataSource = null; } } else { dataSource = null; } } if (dataSource != null && dataSource.Exists) { if (databaseSource == null) { databaseSource = new DatabaseIndexedDocumentSource( _component, keyXPath, valueXPath, context, cache, true); } if (!databaseSource.IsInitialized) { databaseSource.Initialize(dataSource.OutputDir, false); } else { DatabaseIndexedDocument document = new DatabaseIndexedDocument(true, false, dataSource.OutputDir); if (document.Exists) { databaseSource.AddDocument(document); } else { memorySource.AddDocuments(baseValue, files, recurse, false, warnOverride); } } } else { memorySource.AddDocuments(baseValue, files, recurse, true, warnOverride); } } WriteMessage(MessageLevel.Info, String.Format( "Indexed {0} elements in {1} files.", memorySource.Count, memorySource.DocumentCount)); globalData.Add(name, this); _documentSources[name] = new IndexedDocumentSources(_component, databaseSource, memorySource); }