Ejemplo n.º 1
0
 [M(O.AggressiveInlining)] private static string GetDownloadTimeText(DownloadRow row)
 {
     if (row.Status == DownloadStatus.Created)
     {
         return(row.CreatedOrStartedDateTime.ToString(CREATED_DT));
     }
     return(row.GetElapsed().ToString(HH_MM_SS));
 }
Ejemplo n.º 2
0
        [M(O.AggressiveInlining)] public static string GetDownloadInfoText(DownloadRow row)
        {
            var st = row.Status;

            switch (st)
            {
            case DownloadStatus.Created: return($"[created]: {row.CreatedOrStartedDateTime.ToString( CREATED_DT )}");

            case DownloadStatus.Started: return($"{row.GetElapsed().ToString( HH_MM_SS )}");

            case DownloadStatus.Wait: return($"(wait), ({row.GetElapsed().ToString( HH_MM_SS )})");
            }

            var ts      = row.GetElapsed();
            var elapsed = ((1 < ts.TotalHours) ? ts.ToString(HH_MM_SS) : (':' + ts.ToString(MM_SS)));
            var percent = ((0 < row.TotalParts) ? Convert.ToByte((100.0 * row.SuccessDownloadParts) / row.TotalParts).ToString() : "-");
            //var failedParts  = ((row.FailedDownloadParts != 0) ? $" (failed: {row.FailedDownloadParts})" : null);
            var downloadInfo = $"{percent}%, ({elapsed})";

            #region [.speed.]
            if (!st.IsPaused())
            {
                var elapsedSeconds = ts.TotalSeconds;
                var downloadBytes  = row.GetDownloadBytesLengthAfterLastRun();
                if ((1_000 < downloadBytes) && (2.5 <= elapsedSeconds))
                {
                    string speedText;
                    if (downloadBytes < 100_000)
                    {
                        speedText = ((downloadBytes / elapsedSeconds) / 1_000).ToString("N2") + " Kbit/s";
                    }
                    else
                    {
                        speedText = ((downloadBytes / elapsedSeconds) / 1_000_000).ToString("N1") + " Mbit/s";
                    }

                    downloadInfo += $", [{speedText}]";
                }
            }
            #endregion

            return(downloadInfo);
        }
Ejemplo n.º 3
0
 [M(O.AggressiveInlining)] private static string GetApproxRemainedTimeText(DownloadRow row)
 {
     if (row.Status == DownloadStatus.Running)
     {
         var totalBytes = row.GetApproxTotalBytes();
         if (totalBytes.HasValue)
         {
             var elapsedSeconds = row.GetElapsed().TotalSeconds;
             var downloadBytes  = row.GetDownloadBytesLengthAfterLastRun();
             if ((1_000 < downloadBytes) && (2.5 <= elapsedSeconds))
             {
                 var remainedBytes = totalBytes.Value - (row.DownloadBytesLength - downloadBytes);
                 var remainedTime  = TimeSpan.FromSeconds((remainedBytes - downloadBytes) * (elapsedSeconds / downloadBytes));
                 return(remainedTime.ToString(HH_MM_SS));
             }
         }
     }
     return(string.Empty);
 }
Ejemplo n.º 4
0
 [M(O.AggressiveInlining)] private static string GetDownloadSpeedText(DownloadRow row)
 {
     if (!row.Status.IsPaused())
     {
         var elapsedSeconds = row.GetElapsed().TotalSeconds;
         var downloadBytes  = row.GetDownloadBytesLengthAfterLastRun();
         if ((1_000 < downloadBytes) && (2.5 <= elapsedSeconds))
         {
             var speedText = default(string);
             if (downloadBytes < 100_000)
             {
                 speedText = ((downloadBytes / elapsedSeconds) / 1_000).ToString("N2") + " Kbit/s";
             }
             else
             {
                 speedText = ((downloadBytes / elapsedSeconds) / 1_000_000).ToString("N1") + " Mbit/s";
             }
             return(speedText);
         }
     }
     return(string.Empty);
 }