public static IObjectTree<IFileSystemInfo> GetLocalDirectoryTree(IDirectoryInfo parent, IFilterAggregator filter) {
var children = new List<IObjectTree<IFileSystemInfo>>();
try {
foreach (var child in parent.GetDirectories()) {
string reason;
if (!filter.InvalidFolderNamesFilter.CheckFolderName(child.Name, out reason) && !filter.FolderNamesFilter.CheckFolderName(child.Name, out reason) && !filter.SymlinkFilter.IsSymlink(child, out reason)) {
children.Add(GetLocalDirectoryTree(child, filter));
} else {
Logger.Info(reason);
}
}
foreach (var file in parent.GetFiles()) {
string reason;
if (!filter.FileNamesFilter.CheckFile(file.Name, out reason) && !filter.SymlinkFilter.IsSymlink(file, out reason)) {
children.Add(new ObjectTree<IFileSystemInfo> {
Item = file,
Children = new List<IObjectTree<IFileSystemInfo>>()
});
} else {
Logger.Info(reason);
}
}
} catch (System.IO.PathTooLongException) {
Logger.Fatal(string.Format("One or more children paths of \"{0}\" are to long to be synchronized, synchronization is impossible since the problem is fixed", parent.FullName));
throw;
}
IObjectTree<IFileSystemInfo> tree = new ObjectTree<IFileSystemInfo> {
Item = parent,
Children = children
};
return tree;
}