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;
}