Created
May 26, 2010 07:07
-
-
Save panesofglass/414165 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class DetailItemLoaderWithProgressItem<T> : IDetailItemLoader<T> | |
| { | |
| private readonly IDetailItemLoader<T> _itemLoader; | |
| private readonly ProgressItem _progressItem; | |
| public DetailItemLoaderWithProgressItem(IDetailItemLoader<T> itemLoader, ProgressItem progressItem) | |
| { | |
| _itemLoader = itemLoader; | |
| _progressItem = progressItem; | |
| } | |
| public T GetDetailItemFrom(Row row) | |
| { | |
| _progressItem.IncrementProgress(); | |
| return _itemLoader.GetDetailItemFrom(row); | |
| } | |
| } |
This file contains hidden or 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
| public class DetailLoader<T> : IDetailLoader<T> | |
| { | |
| public DetailLoader(IDetailItemLoader<T> itemLoader) | |
| { | |
| ItemLoader = itemLoader; | |
| } | |
| public IDetailItemLoader<T> ItemLoader { get; set; } | |
| public virtual void Load(SpreadsheetDocument spreadsheet, Action<T> addToBatch) | |
| { | |
| var rows = spreadsheet.Rows(); | |
| var details = GetDetailItems(rows); | |
| foreach (var detail in details) | |
| addToBatch(detail); | |
| } | |
| public virtual IEnumerable<T> GetDetailItems(IEnumerable<Row> rows) | |
| { | |
| foreach (var row in rows) | |
| { | |
| var detail = ItemLoader.GetDetailItemFrom(row); | |
| yield return detail; | |
| } | |
| } | |
| } |
This file contains hidden or 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
| public class DetailLoaderWithProgressItem<T> : IDetailLoader<T> | |
| { | |
| private IDetailLoader<T> _loader; | |
| private ProgressItem _progressItem; | |
| public DetailLoaderWithProgressItem(IDetailLoader<T> loader, ProgressItem progressItem) | |
| { | |
| _progressItem = progressItem; | |
| _loader = loader; | |
| ItemLoader = new DetailItemLoaderWithProgressItem<T>(_loader.ItemLoader, _progressItem); | |
| _loader.ItemLoader = ItemLoader; | |
| } | |
| public IDetailItemLoader<T> ItemLoader { get; set; } | |
| public void Load(SpreadsheetDocument spreadsheet, Action<T> addToBatch) | |
| { | |
| var rows = spreadsheet.Rows(); | |
| _progressItem.Start(rows.Count()); | |
| _loader.Load(spreadsheet, addToBatch); | |
| _progressItem.EndWithSuccess(); | |
| } | |
| public IEnumerable<T> GetDetailItems(IEnumerable<Row> rows) | |
| { | |
| // This should never actually be called. | |
| return _loader.GetDetailItems(rows); | |
| } | |
| } |
This file contains hidden or 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
| public class Fake { }; | |
| public class FakeDetailItemLoader : IDetailItemLoader<Fake> | |
| { | |
| public Fake GetDetailItemFrom(Row row) | |
| { | |
| return new Fake(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment