Ejemplo n.º 1
0
        private void ParseBinary(byte[] buffer, int offset, int length)
        {
            if (_segmentInfo.Length < _segmentInfo.Position + length)
            {
                var writeLength = (int)(_segmentInfo.Length - _segmentInfo.Position);
                _tail = new byte[length - writeLength];
                Buffer.BlockCopy(buffer, offset + writeLength, _tail, 0, _tail.Length);
                var extra = length - writeLength;
                length = writeLength;
                Logger.Warn("Received extra data in parse binary len={0}", extra);
            }

            if (DownloadItem.StorageContainer.WriteData(_segmentInfo, _segmentInfo.Position, buffer, offset, length))
            {
                _segmentInfo.Position += length;

                // segment finished
                if (_segmentInfo.Position >= _segmentInfo.Length)
                {
                    _binaryMode = false;

                    FinishSegment();

                    if (SegmentCompleted != null)
                    {
                        var ea = new TransferSegmentCompletedEventArgs();
                        OnSegmentCompleted(ea);

                        if (ea.Pause)
                        {
                            return;
                        }
                    }

                    // request another segment
                    if (!TakeSegment())
                    {
                        //request another download item
                        if (!GetNewDownloadItem())
                        {
                            // nothing to download more
                            Dispose();
                            return;
                        }

                        if (!TakeSegment())
                        {
                            Dispose();
                            return;
                        }
                    }

                    RequestSegment();
                }
            }
            else
            {
                Dispose();
            }
        }
Ejemplo n.º 2
0
        private void OnSegmentCompleted(TransferSegmentCompletedEventArgs e)
        {
            var handler = SegmentCompleted;

            if (handler != null)
            {
                handler(this, e);
            }
        }