private Stream ReadDataFile( FileInfo dataFile ) { Stream stream; if( dataFile.Extension == _CsvExt ) { stream = dataFile.OpenRead(); } else if( dataFile.Extension == _ZipExt ) { if( dataFile.Length == 0 ) throw new Exception( "DataFile size is 0 bytes." ); //раззиповать файл string csvFileName = Path.ChangeExtension( dataFile.FullName, ".csv" ); ZipFile zf = new ZipFile( dataFile.FullName ); try { string csvEntry = dataFile.GetNameOnly() + _CsvExt; ZipEntry ze = zf.getEntry( csvEntry ); if( ze == null ) throw new Exception( csvEntry + " entry not found in " + dataFile.Name ); var zipStream = zf.getInputStream( ze ); try { using( FileStream stm = new FileStream( csvFileName, FileMode.Create, FileAccess.Write ) ) { int len; byte[] buf = new byte[ _BufferSize ]; sbyte[] sbuf = new sbyte[ _BufferSize ]; while( ( len = zipStream.read( sbuf ) ) > 0 ) { Buffer.BlockCopy( sbuf, 0, buf, 0, len ); stm.Write( buf, 0, len ); } } } finally { zipStream.close(); } } finally { zf.close(); } //прочитать раззипованный файл stream = new FileStream( csvFileName, FileMode.Open, FileAccess.Read ); } else { throw new Exception( "Unknown data file extension: " + dataFile.Extension ); } return stream; }
public AlarmFile( FileInfo fileInfo, ImportEntity importEntity, AlarmFileType fileType ) { FileInfo = fileInfo; ImportEntity = importEntity; FileType = fileType; Index = int.Parse( fileInfo.GetNameOnly() ); }