示例#1
0
        /// <summary>
        /// Goes through the Directories to scan recursively and starts a scan of each while that matches the whitelist. (both from settings)
        /// </summary>
        /// <returns>All found nuggets.</returns>
        public IDictionary <string, TemplateItem> ParseAll()
        {
            var whiteListItems = _localizationOptions.WhiteList.ToList();
            var directoriesToSearchRecursively = _localizationOptions.DirectoriesToScan;
            var fileEnumerator = new FileEnumerator(_localizationOptions.BlackList.ToList());
            var templateItems  = new ConcurrentDictionary <string, TemplateItem>();

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

                    var currentFullPath = Path.GetDirectoryName(Path.GetFullPath(filePath));
                    var blacklistFound  = _localizationOptions.BlackList.Any(blackItem => currentFullPath == null || currentFullPath.StartsWith(blackItem, StringComparison.OrdinalIgnoreCase));
                    if (blacklistFound)
                    {
                        continue;
                    }

                    foreach (var whiteListItem in whiteListItems)
                    {
                        if (whiteListItem.StartsWith("*."))
                        {
                            var fileName      = Path.GetFileName(filePath);
                            var dotStartindex = fileName.IndexOf(".", StringComparison.Ordinal);
                            if (dotStartindex == -1)
                            {
                                continue;
                            }

                            var extension = fileName.Substring(dotStartindex);
                            if (!extension.Equals(whiteListItem.Substring(1), StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }

                            ParseFile(_localizationOptions.ProjectDirectory, filePath, templateItems);
                            break;
                        }

                        if (Path.GetFileName(filePath).Equals(whiteListItem, StringComparison.Ordinal))
                        {
                            continue;
                        }

                        ParseFile(_localizationOptions.ProjectDirectory, filePath, templateItems);
                        break;
                    }
                }
            }

            return(templateItems);
        }
示例#2
0
        /// <summary>
        /// Goes through the Directories to scan recursively and starts a scan of each while that matches the whitelist. (both from settings)
        /// </summary>
        /// <returns>All found nuggets.</returns>
        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)
                    {
                        Console.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);
        }