Created
April 7, 2011 20:38
-
-
Save emiaj/908662 to your computer and use it in GitHub Desktop.
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
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using FubuCore; | |
namespace FubuMVC.Spark | |
{ | |
public interface ISparkScanner | |
{ | |
IEnumerable<string> Scan(); | |
} | |
public interface IScannerFilter | |
{ | |
void Include(string pattern); | |
void Exclude(string pattern); | |
FileSet ToFileSet(); | |
} | |
public interface IScanSources | |
{ | |
void RegisterSource(string path); | |
IEnumerable<string> Sources(); | |
} | |
public class SparkScanner : ISparkScanner | |
{ | |
private readonly IFileSystem _fileSystem; | |
private readonly IScannerFilter _scannerFilter; | |
private readonly IScanSources _sources; | |
public SparkScanner(IFileSystem fileSystem, IScannerFilter scannerFilter, IScanSources sources) | |
{ | |
_fileSystem = fileSystem; | |
_sources = sources; | |
_scannerFilter = scannerFilter; | |
} | |
public IEnumerable<string> Scan() | |
{ | |
var set = _scannerFilter.ToFileSet(); | |
var sources = _sources.Sources(); | |
var files = sources.SelectMany(root => _fileSystem.FindFiles(root, set)); | |
return files; | |
} | |
} | |
public interface ISparkItemLocator | |
{ | |
IEnumerable<SparkItem> FindAll(); | |
} | |
public interface ISparkItemBuilder | |
{ | |
SparkItem Build(string path); | |
} | |
public class SparkItem | |
{ | |
public string FilePath { get; set; } | |
public SparkItemCategory Category { get; set; } | |
public string Name { get { return Path.GetFileName(FilePath); } } | |
} | |
public enum SparkItemCategory | |
{ | |
} | |
public class SparkItemLocator : ISparkItemLocator | |
{ | |
private readonly ISparkScanner _scanner; | |
private readonly ISparkItemBuilder _builder; | |
public SparkItemLocator(ISparkScanner scanner, ISparkItemBuilder builder) | |
{ | |
_scanner = scanner; | |
_builder = builder; | |
} | |
public IEnumerable<SparkItem> FindAll() | |
{ | |
var files = _scanner.Scan(); | |
var items = files.Select(_builder.Build); | |
return items; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment