예제 #1
0
        private static PatternConfig LoadPatternConfig(XmlNode patternNode, FilesingConfig filesingConfig)
        {
            Regex regex = null;
            List <IgnoreConfig>  ignoreConfigs  = new List <IgnoreConfig>();
            List <RequireConfig> requireConfigs = new List <RequireConfig>();

            foreach (XmlNode childNode in patternNode.ChildNodes)
            {
                if (childNode.Name.EqualsIgnoreCase(regexNode))
                {
                    // Patterns will always default to ignoring case.
                    regex = CreateRegexFromXmlNode(childNode, true);
                }
                else if (childNode.Name.EqualsIgnoreCase(ignoreListNode))
                {
                    IgnoreConfig ignoreConfig = LoadIgnoreConfig(childNode, filesingConfig);
                    ignoreConfigs.Add(ignoreConfig);
                }
                else if (childNode.Name.EqualsIgnoreCase(requirementsListNode))
                {
                    RequireConfig requireConfig = LoadRequireConfig(childNode, filesingConfig);
                    requireConfigs.Add(requireConfig);
                }
            }

            return(new PatternConfig(regex, ignoreConfigs, requireConfigs));
        }
예제 #2
0
        // ---------------- Constructor -----------------

        public FilesingRunner(FilesingConfig config, GenericLogger log)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            config.Validate();

            this.threads           = new List <Thread>(config.NumberOfThreads);
            this.keepRunning       = false;
            this.started           = false;
            this.keepRunningObject = new object();

            for (int i = 0; i < config.NumberOfThreads; ++i)
            {
                string threadName = i.ToString();
                Thread thread     = new Thread(() => this.ThreadEntry(threadName))
                {
                    Name = threadName
                };
                this.threads.Add(thread);
            }

            this.config = config;
            this.log    = log;
        }
예제 #3
0
        public static bool ShouldProcessFile(string filePath, FilesingConfig config, PatternConfig currentPattern)
        {
            bool globalIgnore = false;

            for (int i = 0; (i < config.GlobalIgnoreConfigs.Count) && (globalIgnore == false); ++i)
            {
                // If the path should be ignored, flag it as such, and break out of the loop.
                globalIgnore = config.GlobalIgnoreConfigs[i].ShouldIgnore(filePath);
            }

            bool globalRequire = false;

            for (int i = 0; (i < config.GlobalRequireConfigs.Count) && (globalRequire == false); ++i)
            {
                // If the path is required, flag it as such, and break out of the loop.
                globalRequire = config.GlobalRequireConfigs[i].IsRequired(filePath);
            }

            bool patternIgnore = false;

            for (int i = 0; (i < currentPattern.IgnoreConfigs.Count) && (patternIgnore == false); ++i)
            {
                patternIgnore = currentPattern.IgnoreConfigs[i].ShouldIgnore(filePath);
            }

            bool patternRequire = false;

            for (int i = 0; (i < currentPattern.RequireConfigs.Count) && (patternRequire == false); ++i)
            {
                patternRequire = currentPattern.RequireConfigs[i].IsRequired(filePath);
            }

            if (patternRequire)
            {
                // If our pattern says its required,
                // return true, as it overrides any global config.
                return(true);
            }
            else if (patternIgnore)
            {
                // If our pattern says to ignore the file,
                // ignore the file, as it overrides any global config.
                return(false);
            }
            else if (globalRequire)
            {
                // If the file falls into the categories that globally are required,
                // it should be processed.
                return(true);
            }
            else if (globalIgnore)
            {
                // If thf file falls into the categories that globally are ignored,
                // it should not be processed.
                return(false);
            }

            // By default, always process the file.
            return(true);
        }
예제 #4
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Gets all of the files to search for patterns based on the passed
        /// in configuration.  Any file that is marked to be ignored is NOT included
        /// in the returned list.
        /// </summary>
        public IList <string> FindAllFiles(FilesingConfig config)
        {
            config.Validate();

            List <string> files = new List <string>();

            SearchDir(config.SearchDirectoryLocation, files, config);

            return(files);
        }
예제 #5
0
        private static IgnoreConfig LoadIgnoreConfig(XmlNode ignoreNode, FilesingConfig filesingConfig)
        {
            IgnoreConfig ignoreConfig = new IgnoreConfig();

            foreach (XmlNode childNode in ignoreNode.ChildNodes)
            {
                // Parse specific files that are ignored.
                if (childNode.Name.EqualsIgnoreCase(ignoreFileNode))
                {
                    ignoreConfig.AddSpecificFileToIgnore(
                        Path.Combine(filesingConfig.SearchDirectoryLocation, childNode.InnerText)
                        );
                }
                // Parse specific dirs that are ignored.
                else if (childNode.Name.EqualsIgnoreCase(ignoreDirNode))
                {
                    ignoreConfig.AddSpecificDirToIgnore(
                        Path.Combine(filesingConfig.SearchDirectoryLocation, childNode.InnerText)
                        );
                }
                // Parse files ignored with a regex pattern.
                else if (childNode.Name.EqualsIgnoreCase(ignoreFileWithRegexNode))
                {
                    // Files and directories shall always be defaulted to false.
                    Regex regex = CreateRegexFromXmlNode(childNode, false);
                    ignoreConfig.AddFileRegexToIgnore(regex);
                }
                // Parse dirs ignored with a regex pattern.
                else if (childNode.Name.EqualsIgnoreCase(ignoreDirWithRegexNode))
                {
                    // Files and directories shall always be defaulted to false.
                    ignoreConfig.AddDirNameToIgnore(childNode.InnerText, LookForIgnoreCaseAttribute(childNode, false));
                }
                else if (childNode.Name.EqualsIgnoreCase(ignoreFileWithExtensionNode))
                {
                    string pattern = Regex.Escape(childNode.InnerText);

                    // Files and directories shall always be defaulted to false.
                    bool ignoreCase = LookForIgnoreCaseAttribute(childNode, false);

                    RegexOptions options = RegexOptions.Compiled;
                    if (ignoreCase)
                    {
                        options |= RegexOptions.IgnoreCase;
                    }

                    Regex regex = new Regex(pattern, options);
                    ignoreConfig.AddIgnoredFileExtension(regex);
                }
            }

            return(ignoreConfig);
        }
예제 #6
0
 private static void ParseGlobalSettings(XmlNode globalSettingsNode, FilesingConfig filesingConfig)
 {
     foreach (XmlNode childNode in globalSettingsNode.ChildNodes)
     {
         if (childNode.Name.EqualsIgnoreCase(ignoreListNode))
         {
             filesingConfig.GlobalIgnoreConfigs.Add(LoadIgnoreConfig(childNode, filesingConfig));
         }
         else if (childNode.Name.EqualsIgnoreCase(requirementsListNode))
         {
             filesingConfig.GlobalRequireConfigs.Add(LoadRequireConfig(childNode, filesingConfig));
         }
     }
 }
예제 #7
0
        private void SearchDir(string baseDir, IList <string> files, FilesingConfig config)
        {
            this.log.WriteLine(FilesingConstants.HeavyVerbosity, "Searching '{0}'", baseDir);

            foreach (string file in Directory.GetFiles(baseDir))
            {
                string fileName = Path.Combine(baseDir, file).NormalizePath();
                files.Add(fileName);
            }

            foreach (string dir in Directory.GetDirectories(baseDir))
            {
                SearchDir(Path.Combine(baseDir, dir), files, config);
            }
        }
예제 #8
0
 private static void ParsePatterns(XmlNode patternListNode, FilesingConfig filesingConfig)
 {
     foreach (XmlNode childNode in patternListNode.ChildNodes)
     {
         if (childNode.Name.EqualsIgnoreCase(regexNode))
         {
             // Patterns will always default to ignoring case.
             Regex         regex         = CreateRegexFromXmlNode(childNode, true);
             PatternConfig patternConfig = new PatternConfig(regex);
             filesingConfig.PatternConfigs.Add(patternConfig);
         }
         else if (childNode.Name.EqualsIgnoreCase(patternNode))
         {
             PatternConfig patternConfig = LoadPatternConfig(childNode, filesingConfig);
             filesingConfig.PatternConfigs.Add(patternConfig);
         }
     }
 }
예제 #9
0
        // ---------------- Functions ----------------

        public static FilesingConfig LoadConfigFromXml(string xmlFilePath, string searchDir)
        {
            if (File.Exists(xmlFilePath) == false)
            {
                throw new FileNotFoundException("Can not find Filesing config file '" + xmlFilePath + "'");
            }

            FilesingConfig config = new FilesingConfig
            {
                SearchDirectoryLocation = searchDir
            };

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFilePath);

            XmlNode rootNode = doc.DocumentElement;

            if (rootNode.Name.EqualsIgnoreCase(rootNodeName) == false)
            {
                throw new ArgumentException(
                          "Root node is not '" + rootNodeName + "', is this the correct XML file?  Got: " + rootNode.Name
                          );
            }

            foreach (XmlNode childNodes in rootNode.ChildNodes)
            {
                if (childNodes.Name.EqualsIgnoreCase(globalSettingsNode))
                {
                    ParseGlobalSettings(childNodes, config);
                }
                else if (childNodes.Name.EqualsIgnoreCase(patternsListNode))
                {
                    ParsePatterns(childNodes, config);
                }
            }

            return(config);
        }
예제 #10
0
        private static RequireConfig LoadRequireConfig(XmlNode requireNode, FilesingConfig filesingConfig)
        {
            RequireConfig config = new RequireConfig();

            foreach (XmlNode childNode in requireNode.ChildNodes)
            {
                // Parse specific file to require
                if (childNode.Name.EqualsIgnoreCase(requireFileNode))
                {
                    config.AddRequiredFile(
                        Path.Combine(filesingConfig.SearchDirectoryLocation, childNode.InnerText)
                        );
                }
                // Parse specific dir to require.
                else if (childNode.Name.EqualsIgnoreCase(requireDirNode))
                {
                    config.AddRequiredDir(
                        Path.Combine(filesingConfig.SearchDirectoryLocation, childNode.InnerText)
                        );
                }
            }

            return(config);
        }
예제 #11
0
        // ---------------- Constructor ----------------

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="config">Reference to the global filesing config.</param>
        /// <param name="log">The log to write to.</param>
        /// <param name="name">The name of this file processor (e.g. could be a thread name).</param>
        public FileProcessor(FilesingConfig config, GenericLogger log, string name)
        {
            this.config = config;
            this.log    = log;
            this.name   = name;
        }