public FileSourceCSV( FileSourceFactory factory, DataFlowOpInitializeContext context, AdapterInputSource adapterInputSource, bool hasHeaderLine, bool hasTitleLine, int?numLoops, string[] propertyNames, string dateFormat) { _factory = factory; _adapterInputSource = adapterInputSource; _hasHeaderLine = hasHeaderLine; _hasTitleLine = hasTitleLine; _numLoops = numLoops; _dateFormat = dateFormat; _statementContext = context.AgentInstanceContext.StatementContext; // use event type's full list of properties if (!hasTitleLine) { if (propertyNames != null) { _parseMake = SetupProperties(false, propertyNames, factory.OutputEventType, _statementContext, dateFormat); } else { _parseMake = SetupProperties(false, factory.OutputEventType.PropertyNames, factory.OutputEventType, _statementContext, dateFormat); } } }
public void Next() { try { string[] nextRecord = _reader.GetNextRecord(); if (_firstRow) { // determine the parsers from the title line if (_hasTitleLine && _parseMake == null) { _parseMake = SetupProperties(true, nextRecord, _factory.OutputEventType, _statementContext, _dateFormat); } if (_hasTitleLine || _hasHeaderLine) { nextRecord = _reader.GetNextRecord(); } } var propertyIndexes = _parseMake.Indexes; var tuple = new object[propertyIndexes.Length]; for (var i = 0; i < propertyIndexes.Length; i++) { tuple[i] = _parseMake.Parsers[i].Parse(nextRecord[propertyIndexes[i]]); } var underlying = _parseMake.EventBeanManufacturer.MakeUnderlying(tuple); if (underlying is object[]) { graphContext.Submit((object[])underlying); } else { graphContext.Submit(underlying); } _firstRow = false; } catch (EndOfStreamException) { if (_numLoops != null) { _loopCount++; if (_loopCount >= _numLoops) { graphContext.SubmitSignal(new EPDataFlowSignalFinalMarkerImpl()); } else { // reset graphContext.SubmitSignal(new EPDataFlowSignalWindowMarkerImpl()); _firstRow = true; if (_reader.IsResettable) { _reader.Reset(); } else { _reader = new CSVReader(_adapterInputSource); } } } else { graphContext.SubmitSignal(new EPDataFlowSignalFinalMarkerImpl()); } } }