public DataTable TryGetPreview() { //there is already a data table in memory if (_workingTable != null) { return(_workingTable); } //we have not loaded anything yet if (Headers == null) { //get a chunk DataTable toReturn = GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); //clear these to close the file and reset state to 'I need to open the file again state' CloseReader(); Headers = null; EventHandlers = null; DataPusher = null; _workingTable = null; _reader = null; return(toReturn); } throw new NotSupportedException("Cannot generate preview because _headers has already been set which likely means it is already loading / didn't cleanup properly after last preview attempt?"); }
private void InitializeComponents() { Headers = new FlatFileColumnCollection(_fileToLoad, MakeHeaderNamesSane, ExplicitlyTypedColumns, ForceHeaders, ForceHeadersReplacesFirstLineInFile, IgnoreColumns); DataPusher = new FlatFileToDataTablePusher(_fileToLoad, Headers, HackValueReadFromFile, AttemptToResolveNewLinesInRecords, Culture); EventHandlers = new FlatFileEventHandlers(_fileToLoad, DataPusher, ThrowOnEmptyFiles, BadDataHandlingStrategy, _listener, MaximumErrorsToReport <= 0 ? int.MaxValue:MaximumErrorsToReport, IgnoreBadReads); }