Exemplo n.º 1
0
        private string GetNewDownloadSize()
        {
            var downloadSizeUnit = (DownloadSize.Type)((ComboBoxItem)DownloadSizeUnit.SelectedItem).Tag;
            var downloadSize     = new DownloadSize(downloadSizeUnit, double.Parse(DownloadSize.Text));
            var downloadSpeed    = new DownloadSpeed(DownloadEstimator.DownloadSpeed.Type.Mbps, double.Parse(DownloadSpeed.Content.ToString()));

            downloadSize = new DownloadSize(DownloadEstimator.DownloadSize.Type.MegaBit, downloadSize.MegaBits - (downloadSpeed.Mbps * 0.5));

            return(downloadSize.Bits >= 0 ? $"{downloadSize.ConvertTo(downloadSizeUnit):F2}" : "0.00");
        }
Exemplo n.º 2
0
        private string GetTimeRemaining()
        {
            if (DownloadSpeed.Content == null || string.IsNullOrEmpty(DownloadSize.Text))
            {
                return("");
            }

            var downloadSize  = new DownloadSize(DownloadEstimator.DownloadSize.Type.GigaByte, double.Parse(DownloadSize.Text));
            var downloadSpeed = new DownloadSpeed(DownloadEstimator.DownloadSpeed.Type.Mbps, double.Parse((string)DownloadSpeed.Content));

            if (Math.Abs(downloadSpeed.BitsPerSecond) < .001)
            {
                return("00h:00m:00s");
            }

            var timeRemaining = TimeSpan.FromSeconds(DownloadCalculations.GetTimeRemaining(downloadSpeed, downloadSize));

            return
                ($"{timeRemaining.Hours:D2}h:{timeRemaining.Minutes:D2}m:{timeRemaining.Seconds:D2}s");
        }
 public static double GetTimeRemaining(DownloadSpeed downloadSpeed, DownloadSize downloadSize)
 {
     return(downloadSize.Bytes / downloadSpeed.BytesPerSecond);
 }