Пример #1
0
        private void UploadStreamOnProgressUpdate(object sender, EventArgs e)
        {
            ProgressUpdateEventArgs updateEventArgs = e as ProgressUpdateEventArgs;

            if (updateEventArgs != null)
            {
                if (progressLastLength == 0)
                {
                    progressLastLength = updateEventArgs.CurrentBytes;
                    progressLastUpdate = DateTime.Now;
                }
                else
                {
                    double secondsDiff  = (DateTime.Now - progressLastUpdate).TotalSeconds;
                    double currentSpeed = ((updateEventArgs.CurrentBytes - progressLastLength) / secondsDiff);
                    progressSpeedAverage.Enqueue(currentSpeed);
                    progressSpeedAverage.Dequeue();
                    progressLastLength = updateEventArgs.CurrentBytes;
                    progressLastUpdate = DateTime.Now;
                }

                double currentAvgSpeed = progressSpeedAverage.Average();
                string prefix          = "KB/s";
                if (currentAvgSpeed > (1024 * 1024))
                {
                    currentAvgSpeed = Math.Round(currentAvgSpeed / (1024 * 1024), 2);
                    prefix          = "MB/s";
                }
                else
                {
                    currentAvgSpeed = Math.Round(currentAvgSpeed / 1024, 2);
                }

                Console.Write("└─ Uploading {0}% | {4} / {3} | {1} {2}        \r", Math.Round(updateEventArgs.Percent, 2),
                              currentAvgSpeed, prefix,
                              Utils.FormatFileSize(updateEventArgs.TotalBytes),
                              Utils.FormatFileSize(updateEventArgs.CurrentBytes));
            }
        }
Пример #2
0
        protected virtual void _OnProgressUpdate(ProgressUpdateEventArgs e)
        {
            EventHandler handler = OnProgressUpdate;

            handler?.Invoke(this, e);
        }