Esempio n. 1
0
        private void TmrRefresh_Tick(object stateInfo)
        {
            if (_downloader == null || _downloader.State != DownloaderState.Working)
            {
                return;
            }
            if (!_isDownloadSizeInit)
            {
                _isDownloadSizeInit = true;
                _minerUpdateIndicator.SetMaxProgressValue((int)(_downloader.FileSize / 1024));
            }

            if (_downloader.LastError != null)
            {
                Helpers.ConsolePrint("MinersDownloader", _downloader.LastError.Message);
            }

            var speedString     = $"{_downloader.Rate / 1024d:0.00} kb/s";
            var percString      = _downloader.Progress.ToString("0.00") + "%";
            var labelDownloaded =
                $"{_downloader.Transfered / 1024d / 1024d:0.00} MB / {_downloader.FileSize / 1024d / 1024d:0.00} MB";

            _minerUpdateIndicator.SetProgressValueAndMsg((int)(_downloader.Transfered / 1024d),
                                                         $"{speedString}   {percString}   {labelDownloaded}");

            // Diagnostic stuff
            if (_downloader.Transfered > _lastProgress)
            {
                _ticksSinceUpdate = 0;
                _lastProgress     = _downloader.Transfered;
            }
            else if (_ticksSinceUpdate > 20)
            {
                Helpers.ConsolePrint("MinersDownloader", "Maximum ticks reached, retrying");
                _ticksSinceUpdate = 0;
            }
            else
            {
                Helpers.ConsolePrint("MinersDownloader", "No progress in ticks " + _ticksSinceUpdate);
                _ticksSinceUpdate++;
            }
        }
        private void TmrRefresh_Tick(Object stateInfo)
        {
            if (downloader != null && downloader.State == DownloaderState.Working)
            {
                if (!isDownloadSizeInit)
                {
                    isDownloadSizeInit = true;
                    _minerUpdateIndicator.SetMaxProgressValue((int)(downloader.FileSize / 1024));
                }

                if (downloader.LastError != null)
                {
                    Helpers.ConsolePrint("MinersDownloader", downloader.LastError.Message);
                }

                var speedString     = string.Format("{0} kb/s", (downloader.Rate / 1024d).ToString("0.00"));
                var percString      = downloader.Progress.ToString("0.00") + "%";
                var labelDownloaded = string.Format("{0} MB / {1} MB",
                                                    (downloader.Transfered / 1024d / 1024d).ToString("0.00"),
                                                    (downloader.FileSize / 1024d / 1024d).ToString("0.00"));
                _minerUpdateIndicator.SetProgressValueAndMsg((int)(downloader.Transfered / 1024d),
                                                             String.Format("{0}   {1}   {2}", speedString, percString, labelDownloaded));

                // Diagnostic stuff
                if (downloader.Transfered > lastProgress)
                {
                    ticksSinceUpdate = 0;
                    lastProgress     = downloader.Transfered;
                }
                else if (ticksSinceUpdate > 20)
                {
                    Helpers.ConsolePrint("MinersDownloader", "Maximum ticks reached, retrying");
                    ticksSinceUpdate = 0;
                }
                else
                {
                    Helpers.ConsolePrint("MinersDownloader", "No progress in ticks " + ticksSinceUpdate.ToString());
                    ticksSinceUpdate++;
                }
            }
        }
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            if (!isDownloadSizeInit)
            {
                isDownloadSizeInit = true;
                _minerUpdateIndicator.SetMaxProgressValue((int)(e.TotalBytesToReceive / 1024));
            }

            // Calculate download speed and output it to labelSpeed.
            var speedString = string.Format("{0} kb/s", (e.BytesReceived / 1024d / _stopwatch.Elapsed.TotalSeconds).ToString("0.00"));

            // Show the percentage on our label.
            var percString = e.ProgressPercentage.ToString() + "%";

            // Update the label with how much data have been downloaded so far and the total size of the file we are currently downloading
            var labelDownloaded = string.Format("{0} MB / {1} MB",
                                                (e.BytesReceived / 1024d / 1024d).ToString("0.00"),
                                                (e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00"));

            _minerUpdateIndicator.SetProgressValueAndMsg(
                (int)(e.BytesReceived / 1024d),
                String.Format("{0}   {1}   {2}", speedString, percString, labelDownloaded));
        }