i18n.Domain.Concrete.FileNuggetFinder.ParseAll C# (CSharp) Method

ParseAll() public method

Goes through the Directories to scan recursively and starts a scan of each while that matches the whitelist. (both from settings)
public ParseAll ( ) : TemplateItem>.IDictionary
return TemplateItem>.IDictionary
        public IDictionary<string, TemplateItem> ParseAll()
        {
            IEnumerable<string> fileWhiteList = _settings.WhiteList;
            IEnumerable<string> directoriesToSearchRecursively = _settings.DirectoriesToScan;
            FileEnumerator fileEnumerator = new FileEnumerator(_settings.BlackList);

            string currentFullPath;
            bool blacklistFound = false;

            var templateItems = new ConcurrentDictionary<string, TemplateItem>();
                // Collection of template items keyed by their id.

            foreach (var directoryPath in directoriesToSearchRecursively)
            {
                foreach (string filePath in fileEnumerator.GetFiles(directoryPath))
                {
                    if (filePath.Length >= 260)
                    {
                        DebugHelpers.WriteLine("Path too long to process. Path: " + filePath);
                        continue;
                    }

                    blacklistFound = false;
                    currentFullPath = Path.GetDirectoryName(Path.GetFullPath(filePath));
                    foreach (var blackItem in _settings.BlackList)
                    {
                        if (currentFullPath == null || currentFullPath.StartsWith(blackItem, StringComparison.OrdinalIgnoreCase))
                        {
                            //this is a file that is under a blacklisted directory so we do not parse it.
                            blacklistFound = true;
                            break;
                        }
                    }
                    if (!blacklistFound)
                    {

                        //we check every filePath against our white list. if it's on there in at least one form we check it.
                        foreach (var whiteListItem in fileWhiteList)
                        {
                            //We have a catch all for a filetype
                            if (whiteListItem.StartsWith("*."))
                            {
                                if (Path.GetExtension(filePath) == whiteListItem.Substring(1))
                                {
                                    //we got a match
                                    ParseFile(_settings.ProjectDirectory, filePath, templateItems);
                                    break;
                                }
                            }
                            else //a file, like myfile.js
                            {
                                if (Path.GetFileName(filePath) == whiteListItem)
                                {
                                    //we got a match
                                    ParseFile(_settings.ProjectDirectory, filePath, templateItems);
                                    break;
                                }
                            }
                        }

                    }
                }
            }

            return templateItems;
        }

Usage Example

Exemplo n.º 1
0
        public void FileNuggetFinder_disable_references()
        {
            var settingService = new SettingService_Mock();
            settingService.SetSetting("i18n.WhiteList", "ReferencesTest.txt");
            {
                i18nSettings settings = new i18nSettings(settingService);
                FileNuggetFinder finder = new FileNuggetFinder(settings);
                var templates = finder.ParseAll();

                var item = templates.Values.First();

                Assert.AreEqual(5, item.References.Count());
            }
            {
                //Disabling references
                settingService.SetSetting("i18n.DisableReferences", "true");
                i18nSettings settings = new i18nSettings(settingService);
                FileNuggetFinder finder = new FileNuggetFinder(settings);
                var templates = finder.ParseAll();

                var item = templates.Values.First();

                Assert.AreEqual(1, item.References.Count());
            }
        }
All Usage Examples Of i18n.Domain.Concrete.FileNuggetFinder::ParseAll