Example #1
0
        public bool MoveNext()
        {
            bool canMoveNext = false;

            try
            {
                ///Reduce new buffer times for background task
                if (Current.IsNullOrEmpty())
                {
                    Current = new byte[ChunkSize];
                }
                else
                {
                    Array.Clear(Current, 0, Current.Length);
                }

                CurrentLength = targetStreams.Read(Current, 0, ChunkSize);
                if (CurrentLength != 0)
                {
                    Offset     += CurrentLength;
                    canMoveNext = true;
                }
                else
                {
                    if (streamLength != -1)
                    {
                        if (Offset < streamLength)
                        {
                            LogHelper.OnlineLogger.Error(string.Format("Cannot read any data before EOF, id={0}. {1}", targetStreams.GetHashCode(), HttpLayer.LogRequetId(logId)));
                            throw new WebException("Cannot read any data before EOF", WebExceptionStatus.UnknownError);
                        }
                        else
                        {
                            LogHelper.OnlineLogger.Debug(string.Format("Reach EOF, id={0}. {1}", targetStreams.GetHashCode(), HttpLayer.LogRequetId(logId)));
                        }
                    }
                    else
                    {
                        LogHelper.OnlineLogger.Warn(string.Format("Cannot read any data, Stream Length = -1, id={0}. {1}", targetStreams.GetHashCode(), HttpLayer.LogRequetId(logId)));
                    }
                }
            }
            catch (EndOfStreamException ex)
            {
                LogHelper.OnlineLogger.Warn(string.Format("Reach end of stream {0}. {1}", ex.ToString(), HttpLayer.LogRequetId(logId)));
            }
            catch (ObjectDisposedException ex)
            {
                LogHelper.OnlineLogger.Warn(string.Format("Can not read disposed stream {0}. {1}" + ex.ToString(), HttpLayer.LogRequetId(logId)));
            }

            return(canMoveNext);
        }