Exemplo n.º 1
0
        /// <summary>
        /// Unzip a zip file then use the inner reader to process it.
        /// </summary>
        /// <param name="zipStream">The zip file</param>
        /// <param name="settings">Settings for the inner provider.</param>
        /// <returns>Wrapped data file that can dispose both.</returns>
        public IDataFile OpenDataFile(Stream zipStream, DataFileReaderSettings settings)
        {
            if (zipStream == null)
            {
                throw new ArgumentNullException(nameof(zipStream));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (!zipStream.CanSeek)
            {
                throw new InvalidOperationException("Stream must be seekable");
            }

            ZipArchive archive = new ZipArchive(zipStream);

            if (archive.Entries.Count != 1)
            {
                throw new FileFormatException("Zip file must contain exactly one data.");
            }

            Stream    dataStream = archive.Entries[0].Open( );
            IDataFile dataFile   = InnerReaderService.OpenDataFile(dataStream, settings);

            // Wrap so both get disposed
            ZipDataFile zipDataFile = new ZipDataFile(dataFile, zipStream);

            return(zipDataFile);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="excelFile">The sheet to read.</param>
        /// <param name="settings">Processing settings.</param>
        internal ExcelFileReader(Stream excelFile, DataFileReaderSettings settings)
        {
            if (excelFile == null)
            {
                throw new ArgumentNullException("excelFile");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            _stream   = excelFile;
            _settings = settings;
            _document = SpreadsheetDocument.Open(_stream, false);
            _sheetId  = _settings.SheetId;

            if (_sheetId == null)
            {
                SheetInfo firstSheet = GetSheets( )?.FirstOrDefault( );
                if (firstSheet != null)
                {
                    _sheetId = firstSheet.SheetId;
                }
            }
        }
Exemplo n.º 3
0
        public IDataFile OpenDataFile(Stream sheetFile, DataFileReaderSettings settings)
        {
            if (sheetFile == null)
            {
                throw new ArgumentNullException("sheetFile");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            return(new CsvFileReader(sheetFile, settings));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="fields">The field data.</param>
 /// <param name="lineNumber">The line number, for reporting purposes.</param>
 /// <param name="settings">General settings</param>
 internal CsvObjectReader(string[] fields, long lineNumber, DataFileReaderSettings settings)
 {
     if (fields == null)
     {
         throw new ArgumentNullException(nameof(fields));
     }
     if (settings == null)
     {
         throw new ArgumentNullException(nameof(settings));
     }
     _fields     = fields;
     _lineNumber = lineNumber;
     _settings   = settings;
 }
Exemplo n.º 5
0
        public IDataFile OpenDataFile(Stream excelSpreadsheet, DataFileReaderSettings settings)
        {
            if (excelSpreadsheet == null)
            {
                throw new ArgumentNullException("excelSpreadsheet");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            try
            {
                return(new ExcelFileReader(excelSpreadsheet, settings));
            }
            catch (FileFormatException ex)
            {
                throw new RN.FileFormatException(ex.Message);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="csvStream">The sheet to read.</param>
        /// <param name="settings">Processing settings.</param>
        internal CsvFileReader(Stream csvStream, DataFileReaderSettings settings)
        {
            if (csvStream == null)
            {
                throw new ArgumentNullException("csvStream");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            // Strip zip flag (or others)
            _importFormat = settings.ImportFormat & (ImportFormat.CSV | ImportFormat.Tab);
            if (_importFormat != ImportFormat.CSV && settings.ImportFormat != ImportFormat.Tab)
            {
                throw new ArgumentException("settings");
            }

            _csvStream = csvStream;
            _settings  = settings;
            OpenCsvFile( );
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="excelRow">The OpenXml Excel row.</param>
        /// <param name="document"></param>
        /// <param name="settings">General settings.</param>
        internal ExcelObjectReader(Row excelRow, SpreadsheetDocument document, DataFileReaderSettings settings)
        {
            if (excelRow == null)
            {
                throw new ArgumentNullException(nameof(excelRow));
            }
            if (!excelRow.RowIndex.HasValue)
            {
                throw new ArgumentException("RowIndex is not set", nameof(excelRow));
            }
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _row      = excelRow;
            _rowIndex = excelRow.RowIndex.Value;
            _document = document;
            _settings = settings;
        }