コード例 #1
0
        public IndexedDocument GetDocument(string key)
        {
            // look up the file corresponding to the key
            string file;

            if (index.TryGetValue(key, out file))
            {
                // now look for that file in the cache
                IndexedDocument document;
                if (!cache.TryGetValue(file, out document))
                {
                    // not in the cache, so load it
                    document = new IndexedDocument(this, file);

                    // if the cache is full, remove a document
                    if (cache.Count >= cacheSize)
                    {
                        string fileToUnload = queue.Dequeue();
                        cache.Remove(fileToUnload);
                    }

                    // add it to the cache
                    cache.Add(file, document);
                    queue.Enqueue(file);
                }

                // XPathNavigator content = document.GetContent(key);
                return(document);
            }
            else
            {
                // there is no such key
                return(null);
            }
        }
コード例 #2
0
        public XPathNavigator GetContent(string key)
        {
            IndexedDocument document = GetDocument(key);

            if (document == null)
            {
                return(null);
            }
            else
            {
                return(document.GetContent(key));
            }
        }
コード例 #3
0
        public void AddDocument(string file)
        {
            // load the document
            IndexedDocument document = new IndexedDocument(this, file);

            // record the keys
            string[] keys = document.GetKeys();
            foreach (string key in keys)
            {
                if (index.ContainsKey(key))
                {
                    component.WriteHelperMessage(MessageLevel.Warn, String.Format("Entries for the key '{0}' occur in both '{1}' and '{2}'. The last entry will be used.", key, index[key], file));
                }
                index[key] = file;
            }
        }
コード例 #4
0
        public IndexedDocument GetDocument(string key) {

            // look up the file corresponding to the key
            string file;
            if (index.TryGetValue(key, out file)) {

                // now look for that file in the cache
                IndexedDocument document;
                if (!cache.TryGetValue(file, out document)) {

                    // not in the cache, so load it
                    document = new IndexedDocument(this, file);

                    // if the cache is full, remove a document
                    if (cache.Count >= cacheSize) {
                        string fileToUnload = queue.Dequeue();
                        cache.Remove(fileToUnload);
                    }

                    // add it to the cache
                    cache.Add(file, document);
                    queue.Enqueue(file);

                }

                // XPathNavigator content = document.GetContent(key);
                return (document);

            } else {
                // there is no such key
                return (null);
            }

        }
コード例 #5
0
        public void AddDocument(string file) {

            // load the document
            IndexedDocument document = new IndexedDocument(this, file);

            // record the keys
            string[] keys = document.GetKeys();
            foreach (string key in keys) {
                if (index.ContainsKey(key)) {
                    component.WriteHelperMessage(MessageLevel.Warn, String.Format("Entries for the key '{0}' occur in both '{1}' and '{2}'. The last entry will be used.", key, index[key], file));
                }
                index[key] = file;

            }

        }