Hi All,
I haven't seen any example code regarding the proper way to construct a Reader using the SDK and wondered if I am doing things the wrong way. In this example, I am determining in the OnInitialize method whether any records exist at all and returning the appropriate state. Then when OnProcess is called, I return the first record which was found in OnInitialize and try and look for another one. If there are no additional records, I return DoneProcessingData. If I don't do it this way, I end up gettting additional null records.
The concern I have is that I am potentially doing a lot of work in the OnIinitialize to get that first record (could be say a minute), does this cause any issues? It also makes things a little more complicated. It would be much easier if I could signal to the PP host on each call whether the current request yields a value. If I simply return a DoneProcessingData when there is no new value, I get a null row.
Thanks!
---Jonathan
public class SimpleSourceExample : IComponent
{
private IEnumerator
private int nextValue;
public State OnInitialize(IContext context)
{
//just gimme 10 steps and you won't see me no more!
source = Enumerable.Range(0, 10).GetEnumerator();
//first read could actually be very slow
if (source.MoveNext())
{
nextValue = source.Current;
return State.ReadyForNewData;
}
return State.DoneProcessingData;
}
public State OnProcess(IContext context, IDataRecord data)
{
data.GetProperties().Define("A Value", nextValue);
if (!source.MoveNext())
{
return State.DoneProcessingData;
}
nextValue = source.Current;
return State.ReadyForNewData;
}
public void OnFinalize(IContext context)
{
}
}