Ejemplo n.º 1
0
 public void Reset()
 {
     _args             = null;
     TotalSize         = 0;
     _bytesTransferred = 0;
     _processedSize    = 0;
 }
Ejemplo n.º 2
0
        private void UpdateProgressCallback()
        {
            var now  = DateTimeOffset.UtcNow;
            var diff = now - _lastFastUpdate;

            if (diff > _fastUpdateInterval)
            {
                if (ProgressChanged != null)
                {
                    if (_args == null)
                    {
                        _args = new TransferProgressChangedEventArgs {
                            TotalSize = TotalSize
                        }
                    }
                    ;

                    var slowUpdateDiff = now - _lastSlowUpdate;
                    if (slowUpdateDiff > _slowUpdateInterval)
                    {
                        _args.Speed = (_bytesTransferred - _lastUpdateBytesTransferred) / slowUpdateDiff.TotalSeconds;

                        if (TotalSize > 0)
                        {
                            var estimatedBytesToTransfer =
                                _processedSize / (double)_bytesTransferred * (TotalSize - _processedSize);
                            _args.EstimatedTime = TimeSpan.FromSeconds(estimatedBytesToTransfer / _args.Speed);
                        }

                        _lastUpdateBytesTransferred = _bytesTransferred;
                        _lastSlowUpdate             = now;
                    }

                    if (TotalSize > 0)
                    {
                        _args.Progress = _processedSize / (double)TotalSize;
                    }
                    _args.ProcessedSize = _processedSize;
                    ProgressChanged?.Invoke(this, _args);

                    _lastFastUpdate = now;
                }
            }
        }
    }