I created a BranchAndReturnOperation which allows me to do this:
new BranchAndReturnOperation(this)
.AddBranch(
new FilterRowsOnType(this, "type1")
new DoSomeStuff1AndReturnRows(this)
)
.AddBranch(
new FilterRowsOnType(this, "type2"),
new DoSomeStuff2AndReturnRows(this)
),
And then use the result rows from both of those branches. Just putting
the idea here in case anyone wants it, the code below will need a
little bit of cleanup before it could go in the etl trunk. But I'm
more curious if anyone sees a reason why this wasn't done in the first
place. I also changed the syntax a bit because I didn't like the
partial.register stuff. If you didn't want one of the branches to
return rows you could just make a null operation which ate the rows.
public class BranchAndReturnOperation : BaseOperation
{
private readonly List<IOperation> operations = new
List<IOperation>
();
public BranchAndReturnOperation(BaseProcess Process) : base
(Process) { }
/// <summary>
/// Adds the specified operation to this branching operation
/// </summary>
/// <param name="operation">The operation.</param>
/// <returns></returns>
public BranchAndReturnOperation Add(IOperation operation)
{
operations.Add(operation);
return this;
}
public BranchAndReturnOperation AddBranch(params IOperation[]
branchOperations)
{
PartialProcessOperation subProcess = new
PartialProcessOperation();
foreach (IOperation operation in branchOperations)
subProcess.Register(operation);
operations.Add(subProcess);
return this;
}
/// <summary>
/// Initializes this instance
/// </summary>
/// <param name="pipelineExecuter">The current pipeline
executer.</
param>
public override void PrepareForExecution(IPipelineExecuter
pipelineExecuter)
{
base.PrepareForExecution(pipelineExecuter);
foreach (IOperation operation in operations)
{
operation.PrepareForExecution(pipelineExecuter);
}
}
/// <summary>
/// Executes this operation, sending the input of this operation
/// to all its child operations
/// </summary>
/// <param name="rows">The rows.</param>
/// <returns></returns>
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
List<Row> copiedRows = new List<Row>(rows);
foreach (IOperation operation in operations)
{
List<Row> cloned =
copiedRows.ConvertAll<Row>(delegate(Row row)
{
return row.Clone();
});
IEnumerable<Row> enumerable = operation.Execute
(cloned);
foreach (Row row in enumerable)
yield return row;
}
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino Tools Dev" group.
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
-~----------~----~----~----~------~----~------~--~---