/// <summary> /// Reads the giving directory and populates the node with folders/files structure /// </summary> /// <param name="hostNode"></param> /// <param name="folderPath"></param> public static void LoadModuleFilesFromLocalFolder(ModelNode hostNode, string folderPath) { var files = Directory.GetFiles(folderPath); var folders = Directory.GetDirectories(folderPath); foreach (var file in files) { hostNode.AddModuleFile(new ModuleFileDefinition { Content = File.ReadAllBytes(file), FileName = Path.GetFileName(file), Overwrite = true }); } foreach (var subFolder in folders) { var subFolderPath = subFolder; var folderDef = new FolderDefinition { Name = Path.GetFileName(subFolderPath) }; hostNode.AddFolder(folderDef, folderNode => LoadModuleFilesFromLocalFolder(folderNode, subFolderPath)); } }
protected virtual void ProcessDirectory(string path, ModelNode parent) { parent.AddModuleFiles( Directory.EnumerateFiles(path) .Select(fileName => new ModuleFileDefinition { FileName = Path.GetFileName(fileName), Content = File.ReadAllBytes(fileName) })); foreach (string name in Directory.EnumerateDirectories(path)) { string folderName = name; parent.AddFolder( new FolderDefinition { Name = name.Remove(0, name.LastIndexOf('\\') + 1) }, folder => ProcessDirectory(folderName, folder)); } }
protected override void ProcessDirectory(string path, ModelNode parent) { var files = Directory.EnumerateFiles(path); foreach (var fileName in files.Where(fileName => !ProvisionCache.HasSame(fileName))) { parent.AddModuleFile(new ModuleFileDefinition { FileName = Path.GetFileName(fileName), Content = File.ReadAllBytes(fileName) }); ProvisionCache.AddOrUpdate(fileName); } foreach (string name in Directory.EnumerateDirectories(path)) { string folderName = name; parent.AddFolder( new FolderDefinition { Name = name.Remove(0, name.LastIndexOf('\\') + 1) }, folder => ProcessDirectory(folderName, folder)); } }