validate the data before inserting the data. then filter out the invalid
data before inserting. dump the invalid rows somewhere else so you can
review, alter and process those specific rows again.
here is a simple example of validating the length of the string
foreach(var row in rows)
{
var length = row[key].ToString().Length;
if(length > max)
{
row["error"] = string.Format("The value is {0} characters, but the
column only allows {1}", length, max)
}
yield return row;
}
you could expand on the validation make it more generic. something like
Func<Row, bool> Guard Against {get;set;}
string Message {get;set;}
foreach(var row in rows)
{
Validate(row);
yield return row;
}
private void Validate(Row row)
{
if(GuardAgainst(row) == false) return;
row["error"] = Message;
}
then in another operation
foreach(var row in rows)
{
var haserrors = row.Contains("error");
if(haserrors)
{
set row aside to fix and process later
continue; //prevents the current row from continuing down the
pipeline
}
yield return row; //valid rows only
}
your process would then look like this
Initialize()
{
Regsiter(new InputCommand(...));
Register(new ValidateRow {
GuardAgainst = r => {
r["key"].ToString().Length},
Message = "The value of
'key' is too long"
});
Register(new ValidateRow {
GuardAgainst = r => {
r["other"] != null},
Message = "The value of
'other' is null"
});
Register(new FilterOutRowsWithErrors());
Register(new ConventionInputCommand(...));
}
--
You received this message because you are subscribed to the Google Groups
"Rhino Tools Dev" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rhino-tools-dev/-/U3wi1RdAxP8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhino-tools-dev?hl=en.