Created
October 24, 2009 18:10
-
-
Save panesofglass/217648 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
public abstract class DetailLoader<T> : IDetailLoader<T> | |
{ | |
public virtual void Load(string importPath, ProgressItem progressItem, Action<T> addToBatch) | |
{ | |
var spreadsheet = SpreadsheetDocument.Load(importPath); | |
var rows = spreadsheet.Rows(); | |
progressItem.Start(rows.Count()); | |
var details = GetDetailItems(rows, progressItem); | |
foreach (var detail in details) | |
addToBatch(detail); | |
_progressItem.EndWithSuccess(); | |
} | |
public virtual IEnumerable<T> GetDetailItems(IEnumerable<Row> rows, ProgressItem progressItem) | |
{ | |
foreach (var row in rows) | |
{ | |
var detail = GetDetailItemFrom(row); | |
progressItem.IncrementProgress(): | |
yield return detail; | |
} | |
} | |
// Implement for each concrete loader without needing the progress item. | |
public abstract T GetDetailItemFrom(Row row); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment