forked from chucknorris/roundhouse
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor searchallinsteadoftraverse handling
Add the FileLocator interface to abstract the selection of files from the migration folders. This replaces the need for the Migration Runner to explicitly decide what method to call on the FileSystemAccess interface. - the Traverse class replaces the get_all_file_name_strings_in method. - the Recurse class replace the get_all_file_name_strings_recurevly_in method. The dependency injection container picks the appropiate implementation dependening on the prescene or lack of the /searchallinsteadoftraverse switch.
- Loading branch information
Showing
12 changed files
with
129 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
product/roundhouse/infrastructure/filesystem/filelocators/FileLocator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace roundhouse.infrastructure.filesystem.filelocators | ||
{ | ||
/// <summary> | ||
/// Interface which abstracts the method for retrieving files | ||
/// from a directory. | ||
/// </summary> | ||
public interface FileLocator | ||
{ | ||
/// <summary> | ||
/// Return all the files in the given directory. | ||
/// The files are returned in an implementation dependent order. | ||
/// </summary> | ||
/// <param name="directory">The full path to the directory</param> | ||
/// <param name="pattern">The file name pattern</param> | ||
/// <returns>All the files in the directory and all subdirectories, in an implementation defined order.</returns> | ||
string[] locate_all_files_in(string directory, string pattern); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
product/roundhouse/infrastructure/filesystem/filelocators/Recurse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace roundhouse.infrastructure.filesystem.filelocators | ||
{ | ||
/// <summary> | ||
/// The recurse files option. | ||
/// </summary> | ||
public class Recurse : FileLocator | ||
{ | ||
/// <summary> | ||
/// Returns all files in this directory and it's subdirectories, globally sorted using the | ||
/// filename. | ||
/// </summary> | ||
/// <example> | ||
/// It will return like this: | ||
/// subdir\a.txt | ||
/// b.txt | ||
/// subdir\c.txt | ||
/// d.txt | ||
/// | ||
/// </example> | ||
/// <param name="directory">The directory to search in</param> | ||
/// <param name="pattern">The filename pattern</param> | ||
/// <returns>A globally sorted list of files.</returns> | ||
public string[] locate_all_files_in(string directory, string pattern) | ||
{ | ||
string[] returnList = Directory.GetFiles(directory, pattern, SearchOption.AllDirectories); | ||
return returnList.OrderBy(Path.GetFileName).ToArray(); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
product/roundhouse/infrastructure/filesystem/filelocators/Traverse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace roundhouse.infrastructure.filesystem.filelocators | ||
{ | ||
/// <summary> | ||
/// The traverse files option. | ||
/// </summary> | ||
public class Traverse : FileLocator | ||
{ | ||
/// <summary> | ||
/// Returns the files in the provided directory first, in sorted order based on their FileName. | ||
/// Then each subdirectory, with the each subdirectory files, in sorted order based on their FileName. | ||
/// </summary> | ||
/// <example> | ||
/// It will return like this (files are only sorted local to their directory): | ||
/// b.txt | ||
/// d.txt | ||
/// subdir\a.txt | ||
/// subdir\c.txt | ||
/// </example> | ||
/// <param name="directory">The directory to find files in</param> | ||
/// <param name="pattern">The wildcard pattern for those files</param> | ||
/// <returns>An ordered list of files in this directory and it's subdirectories</returns> | ||
public string[] locate_all_files_in(string directory, string pattern) | ||
{ | ||
var files = new List<string>(); | ||
|
||
// find all the files, sort them add to our list. | ||
files.AddRange(Directory.GetFiles(directory, pattern).OrderBy(Path.GetFileName)); | ||
|
||
// find all the subdirectories. | ||
foreach (var subDir in Directory.GetDirectories(directory)) | ||
{ | ||
// find all the files in the subdirectories. | ||
files.AddRange(locate_all_files_in(subDir, pattern)); | ||
} | ||
|
||
return files.ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters