示例#1
0
        private static void FillTemplateDirectoryRecursivelyInternal(
            DirectoryInfo directory,
            [CanBeNull] IReadOnlyCollection<string> definitions,
            [CanBeNull] IReadOnlyDictionary<string, string> replacements,
            [CanBeNull] Func<DirectoryInfo, bool> excludeDirectory,
            [CanBeNull] Func<FileInfo, bool> excludeFile = null)
        {
            if (excludeDirectory != null && excludeDirectory(directory))
                return;

            bool ShouldMove(FileSystemInfo info) => replacements?.Keys.Any(x => info.Name.Contains(x)) ?? false;

            foreach (var file in directory.GetFiles())
            {
                if (excludeFile != null && excludeFile(file))
                    continue;

                FillTemplateFile(file.FullName, definitions, replacements);

                if (ShouldMove(file))
                    FileSystemTasks.RenameFile(file.FullName, file.Name.Replace(replacements), FileExistsPolicy.OverwriteIfNewer);
            }

            directory.GetDirectories()
                .ForEach(x => FillTemplateDirectoryRecursivelyInternal(x, definitions, replacements, excludeDirectory, excludeFile));

            if (ShouldMove(directory))
            {
                FileSystemTasks.RenameDirectory(
                    directory.FullName,
                    directory.Name.Replace(replacements),
                    DirectoryExistsPolicy.Merge,
                    FileExistsPolicy.OverwriteIfNewer);
            }
        }