Skip to content

Instantly share code, notes, and snippets.

@panesofglass
Created October 24, 2009 18:10
Show Gist options
  • Save panesofglass/217648 to your computer and use it in GitHub Desktop.
Save panesofglass/217648 to your computer and use it in GitHub Desktop.
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