Beispiel #1
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);
        }
        private static void SendResponse(Stream f, string FullPath, string ContentType, bool IsDynamic, string ETag, DateTime LastModified,
                                         HttpResponse Response)
        {
            ReadProgress Progress = new ReadProgress()
            {
                Response    = Response,
                f           = f ?? File.OpenRead(FullPath),
                Next        = null,
                Boundary    = null,
                ContentType = null
            };

            Progress.BytesLeft = Progress.TotalLength = Progress.f.Length;
            Progress.BlockSize = (int)Math.Min(BufferSize, Progress.BytesLeft);
            Progress.Buffer    = new byte[Progress.BlockSize];

            Response.ContentType   = ContentType;
            Response.ContentLength = Progress.TotalLength;

            if (!IsDynamic)
            {
                Response.SetHeader("ETag", ETag);
                Response.SetHeader("Last-Modified", CommonTypes.EncodeRfc822(LastModified));
            }

            if (Response.OnlyHeader || Progress.TotalLength == 0)
            {
                Response.SendResponse();
                Progress.Dispose();
            }
            else
            {
                Task T = Progress.BeginRead();
            }
        }
Beispiel #3
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 #4
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);
            }
        }
Beispiel #6
0
 //--------------------------------------------------------------------------
 int IRemoteFsOperation.ReadData(byte[] buff, int buffOffset, string path, long offset, ref int length)
 {
     try{
         ReadProgress   monitor = new ReadProgress(offset + length);
         ReadDataStream dst     = new ReadDataStream(buff, buffOffset);
         session.Message.Write(1, "$ get {0} {1:X}-{2:X}", path, offset, offset + length);
         session.Sftp.get(path, dst, monitor, jsch::ChannelSftp.RESUME, offset);
         length = dst.ReceivedBytes;
         return(0);
     }catch (System.Exception e1) {
         return(session.Message.ReportErr(e1));
     }
 }
        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);
        }
Beispiel #9
0
 public async ValueTask <bool> Upsert(ReadProgress readProgress)
 {
     using var context = Context;
     try
     {
         context.BeginTran();
         readProgress.ReadTime = DateTime.Now;
         var chapterService = new ChapterService(context);
         readProgress.MangaId = (await chapterService.GetSingleAsync(it => it.ObjectId == readProgress.ChapterId)).MangaId;
         var readProgressService = new ReadProgressService(context);
         var result = readProgressService.Upsert(readProgress);
         context.CommitTran();
         return(true);
     }
     catch (Exception e)
     {
         context.RollbackTran();
         throw;
     }
 }
        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);
            }
        }
Beispiel #12
0
 //更新读文件进度
 private void UpdateReadProgress(ReadProgress rProgress)
 {
     this.progressBar.Value = rProgress.ReadingPercent;
     this.statusLblMsg.Text = rProgress.Message;
 }
Beispiel #13
0
 public static extern int SimCard_Mount(ref IntPtr handle, string comstr, ReadProgress process);
        /// <summary>
        /// Executes the ranged GET method on the resource.
        /// </summary>
        /// <param name="Request">HTTP Request</param>
        /// <param name="Response">HTTP Response</param>
        /// <param name="FirstInterval">First byte range interval.</param>
        /// <exception cref="HttpException">If an error occurred when processing the method.</exception>
        public async Task GET(HttpRequest Request, HttpResponse Response, ByteRangeInterval FirstInterval)
        {
            string FullPath = this.GetFullPath(Request);

            if (File.Exists(FullPath))
            {
                HttpRequestHeader Header       = Request.Header;
                DateTime          LastModified = File.GetLastWriteTime(FullPath).ToUniversalTime();
                DateTimeOffset?   Limit;
                CacheRec          Rec;

                if (Header.IfRange != null && (Limit = Header.IfRange.Timestamp).HasValue &&
                    !LessOrEqual(LastModified, Limit.Value.ToUniversalTime()))
                {
                    Response.StatusCode = 200;
                    await this.GET(Request, Response);                        // No ranged request.

                    return;
                }

                Rec = this.CheckCacheHeaders(FullPath, LastModified, Request);

                string ContentType = InternetContent.GetContentType(Path.GetExtension(FullPath));
                Stream f           = CheckAcceptable(Request, Response, ref ContentType, out bool Dynamic, FullPath, Request.Header.Resource);
                Rec.IsDynamic = Dynamic;

                if (Response.ResponseSent)
                {
                    return;
                }

                ReadProgress Progress = new ReadProgress()
                {
                    Response = Response,
                    Request  = Request,
                    f        = f ?? File.Open(FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
                };

                ByteRangeInterval Interval = FirstInterval;
                Progress.TotalLength = Progress.f.Length;

                long i = 0;
                long j;
                long First;

                if (FirstInterval.First.HasValue)
                {
                    First = FirstInterval.First.Value;
                }
                else
                {
                    First = Progress.TotalLength - FirstInterval.Last.Value;
                }

                Progress.f.Position = First;
                Progress.BytesLeft  = Interval.GetIntervalLength(Progress.TotalLength);
                Progress.Next       = Interval.Next;

                while (Interval != null)
                {
                    j = Interval.GetIntervalLength(Progress.TotalLength);
                    if (j > i)
                    {
                        i = j;
                    }

                    Interval = Interval.Next;
                }

                Progress.BlockSize = (int)Math.Min(BufferSize, i);
                Progress.Buffer    = new byte[Progress.BlockSize];

                if (FirstInterval.Next is null)
                {
                    Progress.Boundary    = null;
                    Progress.ContentType = null;

                    Response.ContentType   = ContentType;
                    Response.ContentLength = FirstInterval.GetIntervalLength(Progress.f.Length);
                    Response.SetHeader("Content-Range", ContentByteRangeInterval.ContentRangeToString(First, First + Progress.BytesLeft - 1, Progress.TotalLength));
                }
                else
                {
                    Progress.Boundary    = Guid.NewGuid().ToString().Replace("-", string.Empty);
                    Progress.ContentType = ContentType;

                    Response.ContentType = "multipart/byteranges; boundary=" + Progress.Boundary;
                    // chunked transfer encoding will be used
                }

                if (!Rec.IsDynamic)
                {
                    Response.SetHeader("ETag", Rec.ETag);
                    Response.SetHeader("Last-Modified", CommonTypes.EncodeRfc822(LastModified));
                }

                if (Response.OnlyHeader || Progress.BytesLeft == 0)
                {
                    await Response.SendResponse();

                    await Progress.Dispose();
                }
                else
                {
                    if (FirstInterval.Next != null)
                    {
                        await Response.WriteLine();

                        await Response.WriteLine("--" + Progress.Boundary);

                        await Response.WriteLine("Content-Type: " + Progress.ContentType);

                        await Response.WriteLine("Content-Range: " + ContentByteRangeInterval.ContentRangeToString(First, First + Progress.BytesLeft - 1, Progress.TotalLength));

                        await Response.WriteLine();
                    }

                    Task _ = Progress.BeginRead();
                }
            }
            else
            {
                await this.RaiseFileNotFound(FullPath, Request, Response);
            }
        }
Beispiel #15
0
        public virtual async ValueTask <Tuple <ResponseStatus, object> > RecordReadProgress(ReadProgress readProgress, long userId)
        {
            readProgress.UserId = userId;
            await MangaManager.Upsert(readProgress);

            return(new Tuple <ResponseStatus, object>(
                       ResponseStatus.Success,
                       null));
        }
Beispiel #16
0
 //更新读文件进度
 private void UpdateReadProgress(ReadProgress rProgress)
 {
     this.Progress = rProgress.ReadingPercent;
     this.Msg      = rProgress.Message;
 }