/// <summary> /// Import a CSV file based on a <see cref="StreamReader"/> /// </summary> /// <param name="_stream">The stream to import</param> public void ImportStream(TextReader _stream) { m_columnNames = null; m_data = null; if (ColumnNameSpaceReplacement == null) { ColumnNameSpaceReplacement = ""; } var header = _stream.ReadLine(); // Header must be the first line in the stream if (header != null) { var str = new StringBuilder(header); OnHeaderRead?.Invoke(str); ProcessHeader(str); string line; while ((line = _stream.ReadLine()) != null) { str.Length = 0; str.Append(line); OnLineRead?.Invoke(str); ProcessLine(str); } } }
public bool Read() { switch (_state) { case State.End: return(false); case State.Start: _header = new EnhancementDatabaseHeader(); // TODO: convert to reader _header.Prefix = _reader.ReadString(); _header.Version = _reader.ReadSingle(); _state = State.Enhancements; OnHeaderRead?.Invoke(_header); return(true); case State.Enhancements: if (!IndexIsInitialized(_enhancementIndex)) { _enhancementIndex = 0; _enhancementCount = _reader.ReadInt32(); } if (_enhancementCount < _enhancementIndex) { return(false); } if (_enhancementReader == null) { _enhancementReader = new EnhancementReader(_reader); } var enhancement = _enhancementReader.Read(); OnEnhancementRead?.Invoke(enhancement); _enhancementIndex++; if (_enhancementIndex > _enhancementCount) { _state = State.EnhancementSets; OnEnhancementsCompleted?.Invoke(); } return(true); case State.EnhancementSets: if (!IndexIsInitialized(_enhancementSetIndex)) { _enhancementSetIndex = 0; _enhancementSetCount = _reader.ReadInt32(); } if (_enhancementSetCount < _enhancementSetIndex) { return(false); } if (_enhancementSetReader == null) { _enhancementSetReader = new EnhancementSetReader(_reader); } var enhancementSet = _enhancementSetReader.Read(); OnEnhancementSetRead?.Invoke(enhancementSet); _enhancementSetIndex++; if (_enhancementSetIndex > _enhancementSetCount) { _state = State.End; OnEnhancementSetsCompleted?.Invoke(); return(false); } return(true); } return(false); }