Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend termination criteria #28

Open
balintn22 opened this issue Feb 6, 2021 · 0 comments
Open

Extend termination criteria #28

balintn22 opened this issue Feb 6, 2021 · 0 comments

Comments

@balintn22
Copy link

balintn22 commented Feb 6, 2021

Hi,

I really like the simple approach, but imho DataExtractor.GetData() termination is lacking: it can either terminate based on the row number or on the value of a single property.
I propose to extend the termination test like this:

`
///


/// Obtains the entities for the columns previously configured.
/// The indicates the initial row that will be read,
/// the data extraction will only occur while the predicate returns true.
/// It'll get executed receiving the row index as parameter before extracting the data of each row.
///

/// The initial row to start the data extraction.
/// The condition that is evaulated for each row. The last fetched record is
/// passed as the argument to the predicate. The condition is evaluated before the row under test is
/// returned. Row fetching stops when the test returns false.
/// Returns an with the data of the columns.
public IEnumerable GetDataUntil(int fromRow, Func<int, TRow, bool> whileFunc)
{
if (whileFunc is null)
throw new ArgumentNullException(nameof(whileFunc));

        int row = fromRow;
        while(true)
        {
            var dataInstance = new TRow();

            bool continueExecution = true;
            for (int index = 0; continueExecution && index < this.propertySetters.Count; index++)
                continueExecution = this.propertySetters[index].SetPropertyValue(dataInstance, row, this.worksheet.Cells);

            if (!continueExecution)
            {
                yield return dataInstance;
                break;
            }

            foreach (var collectionPropertySetter in this.collectionColumnSetters)
                collectionPropertySetter.SetPropertyValue(dataInstance, row, this.worksheet.Cells);

            foreach (var simpleCollectionColumnSetter in this.simpleCollectionColumnSetters)
                simpleCollectionColumnSetter.SetPropertyValue(dataInstance, row, this.worksheet.Cells);

            if(!whileFunc(row, dataInstance))
                break;

            yield return dataInstance;

            row++;
        }
    }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant