Exemplo n.º 1
0
        protected void ProcessInput()
        {
            try
            {
                // Initial file. ProcessInput could be called again with another reader without
                // reaching the rollover limit. In which case we'd keep writing to same file.
                if (_writer == null)
                {
                    _writer = _target.GetNextStreamWriter();
                    OnBeginWriting();
                    OnBeginFile();
                }

                // For each data row
                while (_reader.Read())
                {
                    // If we've reached the maximum number of rows for the current file.
                    if (_fileWriteCount >= _fileRowLimit && _fileRowLimit > 0)
                    {
                        OnEndFile();
                        _fileWriteCount = 0;
                        _writer.Dispose();
                        _writer = _target.GetNextStreamWriter();
                        OnBeginFile();
                    }

                    OnWriteLine();
                    _totalWriteCount++;
                    _fileWriteCount++;
                }

                OnEndFile();
                _writer.Dispose();
                OnEndWriting();
            }
            catch (Exception ex)
            {
                throw new Exception($"Error writing line {_fileWriteCount}.", ex);
            }
        }