/// <summary>
        /// This read-only property returns the comments for the specified key
        /// </summary>
        /// <param name="key">The key for which to retrieve comments</param>
        /// <returns>An <see cref="XPathNavigator"/> for the comments or null if not found.</returns>
        public XPathNavigator this[string key]
        {
            get
            {
                IndexedCommentsFile document;
                string file;

                // Look up the file corresponding to the key
                if (index.TryGetValue(key, out file))
                {
                    // Now look for that file in the cache
                    if (!cache.TryGetValue(file, out document))
                    {
                        // Not in the cache, so load it
                        document = new IndexedCommentsFile(this, file);

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

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

                    return(document[key]);
                }

                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Get the comments file from the index cache that contains the given
        /// key.
        /// </summary>
        /// <param name="key">The key for which to retrieve the file</param>
        /// <returns>The indexed comments file or null if not found</returns>
        public IndexedCommentsFile GetCommentsFile(string key)
        {
            IndexedCommentsFile document;
            string filename;

            if (index.TryGetValue(key, out filename))
            {
                if (!cache.TryGetValue(filename, out document))
                {
                    document = new IndexedCommentsFile(filename);

                    if (cache.Count >= cacheSize)
                    {
                        cache.Remove(lruList[0]);
                        lruList.RemoveAt(0);
                    }

                    cache.Add(filename, document);
                    lruList.Add(filename);
                }
                else
                {
                    // Since it got used, move it to the end of the list
                    // so that it stays around longer.  This is a really
                    // basic Least Recently Used list.
                    lruList.Remove(filename);
                    lruList.Add(filename);
                }

                return(document);
            }

            return(null);
        }
Пример #3
0
        /// <summary>
        /// Get the comments for the specified key
        /// </summary>
        /// <param name="key">The key for which to retrieve comments</param>
        /// <returns>An <see cref="XPathNavigator"/> for the comments or null
        /// if not found.</returns>
        public XPathNavigator GetComments(string key)
        {
            IndexedCommentsFile document = this.GetCommentsFile(key);

            if (document == null)
            {
                return(null);
            }

            return(document.GetContent(key));
        }
Пример #4
0
        /// <summary>
        /// This read-only property returns the comments for the specified key
        /// </summary>
        /// <param name="key">The key for which to retrieve comments</param>
        /// <returns>An <see cref="XPathNavigator"/> for the comments or null if not found.</returns>
        public XPathNavigator this[string key]
        {
            get
            {
                IndexedCommentsFile document;
                string file;

                // Look up the file corresponding to the key
                if(index.TryGetValue(key, out file))
                {
                    // Now look for that file in the cache
                    if(!cache.TryGetValue(file, out document))
                    {
                        // Not in the cache, so load it
                        document = new IndexedCommentsFile(this, file);

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

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

                    return document[key];
                }

                return null;
            }
        }
        /// <summary>
        /// Index all comments files found in the specified folder.
        /// </summary>
        /// <param name="path">The path to search.  If null or empty, the
        /// current directory is assumed.</param>
        /// <param name="wildcard">The wildcard to use.  If null or empty,
        /// "*.xml" is assumed.</param>
        /// <param name="recurse">True to recurse subfolders or false to only
        /// use the given folder.</param>
        /// <param name="commentsFiles">Optional.  If not null, an
        /// <see cref="XPathDocument"/> is added to the collection for each
        /// file indexed.</param>
        public void IndexCommentsFiles(string path, string wildcard,
          bool recurse, Collection<XPathNavigator> commentsFiles)
        {
            XPathDocument xpathDoc;
            string[] files, folders, keys;

            if(String.IsNullOrEmpty(path))
                path = Environment.CurrentDirectory;
            else
                path = Path.GetFullPath(path);

            if(String.IsNullOrEmpty(wildcard))
                wildcard = "*.xml";

            files = Directory.GetFiles(path, wildcard);

            // Index the file
            foreach(string filename in files)
            {
                if(!filename.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                {
                    this.OnReportWarning(new CommentsCacheEventArgs(
                        "SHFB: Warning GID0007: Ignoring non-XML comments " +
                        "file: " + filename));
                    continue;
                }

                keys = new IndexedCommentsFile(filename).GetKeys();

                if(commentsFiles != null)
                {
                    xpathDoc = new XPathDocument(filename);
                    commentsFiles.Add(xpathDoc.CreateNavigator());
                }

                // Check for duplicates.  If found, the last one in wins.
                foreach(string key in keys)
                {
                    if(index.ContainsKey(key))
                        this.OnReportWarning(new CommentsCacheEventArgs(
                            String.Format(CultureInfo.InvariantCulture,
                            "SHFB: Warning GID0008: Entries for the key " +
                            "'{0}' occur in both '{1}' and '{2}'.  The " +
                            "entries in '{2}' will be used.", key, index[key],
                            filename)));

                    index[key] = filename;
                }
            }

            filesIndexed += files.Length;

            if(recurse)
            {
                folders = Directory.GetDirectories(path);

                foreach(string folder in folders)
                    this.IndexCommentsFiles(folder, wildcard, recurse,
                        commentsFiles);
            }
        }
        /// <summary>
        /// Get the comments file from the index cache that contains the given
        /// key.
        /// </summary>
        /// <param name="key">The key for which to retrieve the file</param>
        /// <returns>The indexed comments file or null if not found</returns>
        public IndexedCommentsFile GetCommentsFile(string key)
        {
            IndexedCommentsFile document;
            string filename;

            if(index.TryGetValue(key, out filename))
            {
                if(!cache.TryGetValue(filename, out document))
                {
                    document = new IndexedCommentsFile(filename);

                    if(cache.Count >= cacheSize)
                    {
                        cache.Remove(lruList[0]);
                        lruList.RemoveAt(0);
                    }

                    cache.Add(filename, document);
                    lruList.Add(filename);
                }
                else
                {
                    // Since it got used, move it to the end of the list
                    // so that it stays around longer.  This is a really
                    // basic Least Recently Used list.
                    lruList.Remove(filename);
                    lruList.Add(filename);
                }

                return document;
            }

            return null;
        }
Пример #7
0
        /// <summary>
        /// Index all comments files found in the specified folder.
        /// </summary>
        /// <param name="path">The path to search.  If null or empty, the
        /// current directory is assumed.</param>
        /// <param name="wildcard">The wildcard to use.  If null or empty,
        /// "*.xml" is assumed.</param>
        /// <param name="recurse">True to recurse subfolders or false to only
        /// use the given folder.</param>
        /// <param name="commentsFiles">Optional.  If not null, an
        /// <see cref="XPathDocument"/> is added to the collection for each
        /// file indexed.</param>
        public void IndexCommentsFiles(string path, string wildcard,
                                       bool recurse, Collection <XPathNavigator> commentsFiles)
        {
            XPathDocument xpathDoc;

            string[] files, folders, keys;

            if (String.IsNullOrEmpty(path))
            {
                path = Environment.CurrentDirectory;
            }
            else
            {
                path = Path.GetFullPath(path);
            }

            if (String.IsNullOrEmpty(wildcard))
            {
                wildcard = "*.xml";
            }

            files = Directory.GetFiles(path, wildcard);

            // Index the file
            foreach (string filename in files)
            {
                if (!filename.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                {
                    this.OnReportWarning(new CommentsCacheEventArgs(
                                             "SHFB: Warning GID0007: Ignoring non-XML comments " +
                                             "file: " + filename));
                    continue;
                }

                keys = new IndexedCommentsFile(filename).GetKeys();

                if (commentsFiles != null)
                {
                    xpathDoc = new XPathDocument(filename);
                    commentsFiles.Add(xpathDoc.CreateNavigator());
                }

                // Check for duplicates.  If found, the last one in wins.
                foreach (string key in keys)
                {
                    if (index.ContainsKey(key))
                    {
                        this.OnReportWarning(new CommentsCacheEventArgs(
                                                 String.Format(CultureInfo.InvariantCulture,
                                                               "SHFB: Warning GID0008: Entries for the key " +
                                                               "'{0}' occur in both '{1}' and '{2}'.  The " +
                                                               "entries in '{2}' will be used.", key, index[key],
                                                               filename)));
                    }

                    index[key] = filename;
                }
            }

            filesIndexed += files.Length;

            if (recurse)
            {
                folders = Directory.GetDirectories(path);

                foreach (string folder in folders)
                {
                    this.IndexCommentsFiles(folder, wildcard, recurse,
                                            commentsFiles);
                }
            }
        }