Example #1
0
        //=====================================================================

        /// <summary>
        /// Load the configuration file
        /// </summary>
        /// <param name="configFile">The configuration file to load</param>
        /// <exception cref="ArgumentException">This is thrown if the configuration file does not exist.</exception>
        /// <exception cref="ConfigurationErrorsException">This is thrown if the configuration file is not
        /// valid.</exception>
        private static void LoadConfiguration(string configFile)
        {
            XPathDocument  config;
            XPathNavigator navConfig, navComments, element;
            string         path, wildcard, attrValue;
            bool           recurse;
            int            cacheSize = 100;

            if (!File.Exists(configFile))
            {
                throw new ArgumentException("Configuration file not found: " + configFile, "configFile");
            }

            config    = new XPathDocument(configFile);
            navConfig = config.CreateNavigator();

            // Show duplicate key warnings?
            showDupWarning = (navConfig.SelectSingleNode("configuration/showDuplicateWarning") != null);

            // Get the reflection information files
            reflectionFiles = new ReflectionFiles();

            foreach (XPathNavigator refFile in navConfig.Select("configuration/reflectionInfo/@file"))
            {
                if (!File.Exists(refFile.Value))
                {
                    throw new ConfigurationErrorsException("The reflectionFile element's target file '" +
                                                           refFile.Value + "' does not exist");
                }

                Console.WriteLine("Reflection information will be retrieved from '{0}'", refFile.Value);
                reflectionFiles.AddReflectionFile(refFile.Value);
            }

            if (reflectionFiles.Count == 0)
            {
                throw new ConfigurationErrorsException("At least one reflectionFile element is required");
            }

            // Get the inherited documentation filename
            element = navConfig.SelectSingleNode("configuration/inheritedDocs/@file");

            if (element == null)
            {
                throw new ConfigurationErrorsException("The inheritedDocs element does not exist or is not valid");
            }

            inheritedDocsFilename = element.Value;
            Console.WriteLine("Inherited documentation will be written to '{0}'", inheritedDocsFilename);

            // Load the comments file information
            navComments = navConfig.SelectSingleNode("configuration/commentsFiles");

            attrValue = navComments.GetAttribute("cacheSize", String.Empty);

            if (attrValue.Length != 0)
            {
                cacheSize = Convert.ToInt32(attrValue, CultureInfo.InvariantCulture);
            }

            commentsCache = new IndexedCommentsCache(cacheSize)
            {
                ShowDuplicatesWarning = showDupWarning
            };
            commentsCache.ReportWarning += (s, e) => Console.WriteLine(e.Message);

            foreach (XPathNavigator nav in navComments.Select("*"))
            {
                path      = nav.GetAttribute("path", String.Empty);
                wildcard  = nav.GetAttribute("file", String.Empty);
                attrValue = nav.GetAttribute("recurse", String.Empty);

                if (path.Length == 0)
                {
                    path     = Path.GetDirectoryName(wildcard);
                    wildcard = Path.GetFileName(wildcard);
                }

                path = Environment.ExpandEnvironmentVariables(path);

                if (wildcard.Length != 0)
                {
                    wildcard = Environment.ExpandEnvironmentVariables(wildcard);
                }
                else
                {
                    wildcard = "*.xml";
                }

                if (attrValue.Length == 0)
                {
                    recurse = false;
                }
                else
                {
                    recurse = Convert.ToBoolean(attrValue, CultureInfo.InvariantCulture);
                }

                Console.WriteLine("Indexing {0}\\{1}", path, wildcard);
                commentsCache.IndexCommentsFiles(path, wildcard, recurse, (nav.Name == "scan") ? commentsFiles : null);
            }

            if (commentsCache.FilesIndexed == 0 || commentsCache.IndexCount == 0)
            {
                throw new ConfigurationErrorsException("No comments files were specified or they did not " +
                                                       "contain valid information to index");
            }

            if (commentsFiles.Count == 0)
            {
                throw new ConfigurationErrorsException("No comments files were specified to scan for " +
                                                       "<inheritdoc /> tags.");
            }

            Console.WriteLine("Indexed {0} members in {1} file(s).  {2} file(s) to scan for <inheritdoc /> tags.",
                              commentsCache.IndexCount, commentsCache.FilesIndexed, commentsFiles.Count);
        }
        //=====================================================================

        /// <summary>
        /// Load the configuration file
        /// </summary>
        /// <param name="configFile">The configuration file to load</param>
        /// <exception cref="ArgumentException">This is thrown if the configuration file does not exist.</exception>
        /// <exception cref="ConfigurationErrorsException">This is thrown if the configuration file is not
        /// valid.</exception>
        private static void LoadConfiguration(string configFile)
        {
            XPathDocument config;
            XPathNavigator navConfig, navComments, element;
            string path, wildcard, attrValue;
            bool recurse;
            int cacheSize = 100;

            if(!File.Exists(configFile))
                throw new ArgumentException("Configuration file not found: " + configFile, "configFile");

            config = new XPathDocument(configFile);
            navConfig = config.CreateNavigator();

            // Show duplicate key warnings?
            showDupWarning = (navConfig.SelectSingleNode("configuration/showDuplicateWarning") != null);

            // Get the reflection information files
            reflectionFiles = new ReflectionFiles();

            foreach(XPathNavigator refFile in navConfig.Select("configuration/reflectionInfo/@file"))
            {
                if(!File.Exists(refFile.Value))
                    throw new ConfigurationErrorsException("The reflectionFile element's target file '" +
                        refFile.Value + "' does not exist");

                Console.WriteLine("Reflection information will be retrieved from '{0}'", refFile.Value);
                reflectionFiles.AddReflectionFile(refFile.Value);
            }

            if(reflectionFiles.Count == 0)
                throw new ConfigurationErrorsException("At least one reflectionFile element is required");

            // Get the inherited documentation filename
            element = navConfig.SelectSingleNode("configuration/inheritedDocs/@file");

            if(element == null)
                throw new ConfigurationErrorsException("The inheritedDocs element does not exist or is not valid");

            inheritedDocsFilename = element.Value;
            Console.WriteLine("Inherited documentation will be written to '{0}'", inheritedDocsFilename);

            // Load the comments file information
            navComments = navConfig.SelectSingleNode("configuration/commentsFiles");

            attrValue = navComments.GetAttribute("cacheSize", String.Empty);

            if(attrValue.Length != 0)
                cacheSize = Convert.ToInt32(attrValue, CultureInfo.InvariantCulture);

            commentsCache = new IndexedCommentsCache(cacheSize) { ShowDuplicatesWarning = showDupWarning };
            commentsCache.ReportWarning += (s, e) => Console.WriteLine(e.Message);

            foreach(XPathNavigator nav in navComments.Select("*"))
            {
                path = nav.GetAttribute("path", String.Empty);
                wildcard = nav.GetAttribute("file", String.Empty);
                attrValue = nav.GetAttribute("recurse", String.Empty);

                if(path.Length == 0)
                {
                    path = Path.GetDirectoryName(wildcard);
                    wildcard = Path.GetFileName(wildcard);
                }

                path = Environment.ExpandEnvironmentVariables(path);

                if(wildcard.Length != 0)
                    wildcard = Environment.ExpandEnvironmentVariables(wildcard);
                else
                    wildcard = "*.xml";

                if(attrValue.Length == 0)
                    recurse = false;
                else
                    recurse = Convert.ToBoolean(attrValue, CultureInfo.InvariantCulture);

                Console.WriteLine("Indexing {0}\\{1}", path, wildcard);
                commentsCache.IndexCommentsFiles(path, wildcard, recurse, (nav.Name == "scan") ? commentsFiles : null);
            }

            if(commentsCache.FilesIndexed == 0 || commentsCache.IndexCount == 0)
                throw new ConfigurationErrorsException("No comments files were specified or they did not " +
                    "contain valid information to index");

            if(commentsFiles.Count == 0)
                throw new ConfigurationErrorsException("No comments files were specified to scan for " +
                    "<inheritdoc /> tags.");

            Console.WriteLine("Indexed {0} members in {1} file(s).  {2} file(s) to scan for <inheritdoc /> tags.",
                commentsCache.IndexCount, commentsCache.FilesIndexed, commentsFiles.Count);
        }