Beispiel #1
0
        public override byte[] ReadNextBuff()
        {
            if (!this.start)
            {
                this.bytePacket = new byte[LengthHeader];
                this.fileStream.Read(this.bytePacket, 0, LengthHeader);
                this.start = true;
            }

            int length = this.GetLengthPacket();

            if (length == 0)
            {
                fileLengthReaded = 0;
                ReadProgress?.Invoke(fileLength, fileLength);
                return(null);
            }

            var packet = new byte[length];

            this.fileStream.Read(packet, 0, length);
            var data = new byte[length - 16];

            System.Buffer.BlockCopy(packet, 16, data, 0, data.Length);
            fileLengthReaded += packet.Length;
            ReadProgress?.Invoke(fileLengthReaded, fileLength);
            return(packet);
        }
Beispiel #2
0
        public bool Read()
        {
            var excelRowNumber = (_hasHeader ? 2 : 1) + _rowIndex;

            if (excelRowNumber <= _sheet.Dimension.End.Row)
            {
                var row = _sheet.Cells[excelRowNumber, 1, excelRowNumber, _sheet.Dimension.End.Column];
                _currentRow = new object[_columnNames.Length];
                foreach (var cell in row)
                {
                    int colIndex = cell.Start.Column - 1;
                    if (colIndex < _currentRow.Length)
                    {
                        _currentRow[cell.Start.Column - 1] = cell.Value;
                    }
                }

                _rowIndex++;

                // raise a progress event every 100 records
                if (_rowIndex % 100 == 0)
                {
                    ReadProgress?.Invoke(this, new ExcelDataReaderProgressEventArgs(_rowIndex, _numRows));
                }
                return(true);
            }

            ReadProgress?.Invoke(this, new ExcelDataReaderProgressEventArgs(_rowIndex, _numRows));
            return(false);
        }
Beispiel #3
0
 public override byte[] ReadNextBuff()
 {
     this.bytePacket = new byte[LengthHeader];
     this.fileStream.Read(this.bytePacket, 0, LengthHeader);
     byte[] packet = this.GetPacketData();
     fileLengthReaded += packet.Length;
     ReadProgress?.Invoke(fileLengthReaded, fileLength);
     return(packet);
 }
        public virtual async void  ReadNextBuffAsync()
        {
            var outData = new byte[fileStream.Length];

            if (this.fileStream.CanRead && !this.closeFile)
            {
                await this.fileStream.ReadAsync(outData, 0, this.bufferLength);

                fileLengthReaded += outData.Length;
                ReadProgress?.Invoke(fileLengthReaded, this.fileLength);
                ReadedDataAsync?.Invoke(outData);
            }
        }
        public virtual byte[] ReadNextBuff()
        {
            var outData      = new byte[bufferLength];
            int readedLength = 0;

            if (fileStream.CanRead && !closeFile)
            {
                readedLength = fileStream.Read(outData, 0, bufferLength);
                if (readedLength < bufferLength)
                {
                    fileLengthReaded = 0;
                    ReadProgress?.Invoke(fileLength, fileLength);
                    Array.Resize(ref outData, readedLength);
                    return((readedLength != 0) ? outData : null);
                }
                fileLengthReaded += outData.Length;
                ReadProgress?.Invoke(fileLengthReaded, this.fileLength);
            }
            return((readedLength != 0) ? outData : null);
        }
        public override byte[] ReadNextBuff()
        {
            int low   = this.fileStream.ReadByte();
            int high  = this.fileStream.ReadByte();
            int count = low + (high << 8);

            if (count < 0)
            {
                fileLengthReaded = 0;
                ReadProgress?.Invoke(fileLength, fileLength);
                return(null);
            }

            var outData = new byte[count];

            this.fileStream.Read(outData, 0, count);
            fileLengthReaded += outData.Length;
            ReadProgress?.Invoke(fileLengthReaded, fileLength);
            return(outData);
        }
        public override byte[] ReadNextBuff()
        {
            var low1    = (ushort)this.fileStream.ReadByte();
            var high1   = (ushort)this.fileStream.ReadByte();
            int count   = low1 + (high1 << 8);
            var outData = new byte[count];
            int i       = this.fileStream.Read(outData, 0, count);

            if (i <= 0)
            {
                fileLengthReaded = 0;
                ReadProgress?.Invoke(fileLength, fileLength);
                return(null);
            }

            var temp = new byte[outData.Length - 2];

            Buffer.BlockCopy(outData, 2, temp, 0, temp.Length);
            fileLengthReaded += outData.Length;
            ReadProgress?.Invoke(fileLengthReaded, fileLength);
            return(temp);
        }
        public override async void ReadNextBuffAsync()
        {
            int low   = this.fileStream.ReadByte();
            int high  = this.fileStream.ReadByte();
            int count = low + (high << 8);

            if (count < 0)
            {
                fileLengthReaded = 0;
                ReadProgress?.Invoke(fileLength, fileLength);
                ReadedDataAsync?.Invoke(null);
            }
            else
            {
                var outData = new byte[count];
                await this.fileStream.ReadAsync(outData, 0, count);

                fileLengthReaded += outData.Length;
                ReadProgress?.Invoke(fileLengthReaded, fileLength);
                ReadedDataAsync?.Invoke(outData);
            }
        }