I Am Not Myself

Bills.Pay(Developer.Skills).ShouldBeTrue()

Somedays Writing Code is Enough

I wrote this today, it made me happy. Somedays, simply writing some code that you are proud of makes it all worth it.

public void ImportLiabilityCategoryInput(string[] categories)
{
    ImportCategory(categories, InputDataGroupName.Liability);
}

public void ImportAssetCategoryInput(string[] categories)
{
    ImportCategory(categories, InputDataGroupName.AssetExisting);      
}

private void ImportCategory(string[] categories, InputDataGroupName group)
{

    WithASourceAndDestination(
        (source, destination) =>
        {
            foreach(var category in categories)
            {
                var inputData = source.ReadInputData(group, category);
                destination.WriteInputData(group, category, inputData);
             }
        });
}

private void WithASourceAndDestination(Action<IFileAccess, IFileAccess> action)
{
    using(var source = SourceFile.OpenForReading(_FromModelFile))
    using(var destination = DestFile.OpenForReadWrite(_ToModelFile))
    {
        action(source, destination);
        destination.Defragment();
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: