Exemplo n.º 1
0
 private bool SelectDownloadRowInternal(DownloadRow row, bool callAfterSort = false)
 {
     if (row != null)
     {
         var visibleIndex = row.GetVisibleIndex();
         if ((0 <= visibleIndex) && (visibleIndex < DGV.RowCount))
         {
             var dtrow = DGV.Rows[visibleIndex];
             if (dtrow.Selected)
             {
                 SelectionChanged?.Invoke(row);
             }
             else
             {
                 dtrow.Selected = true;
             }
             if (!callAfterSort)
             {
                 _UserMade_DGV_SelectionChanged = false;
             }
             return(true);
         }
     }
     return(false);
 }
        internal ChangeOutputFileForm(DownloadRow row) : this()
        {
            (Row, this.OutputFileName) = (row, row.OutputFileName);

            set_outputFileNameTextBox_Selection_Position(this.OutputFileName);
            _FNCP.FileNameTextBox_TextChanged(outputFileName => set_outputFileNameTextBox_Selection_Position(outputFileName));
        }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
            private int Comparison(DownloadRow x, DownloadRow y)
            {
                var d = _Comparison(x, y);

                if (d == 0)
                {
                    d = x.CreatedOrStartedDateTime.CompareTo(y.CreatedOrStartedDateTime);
                }
                else
                {
                    d *= _Coeff;
                }
                return(d);
            }
Exemplo n.º 5
0
        private void Model_RowPropertiesChanged(DownloadRow row, string propertyName)
        {
            var visibleIndex = row.GetVisibleIndex();

            if ((0 <= visibleIndex) && (visibleIndex < DGV.RowCount))
            {
                DGV.InvalidateRow(visibleIndex);

                if (propertyName == nameof(DownloadRow.Status))
                {
                    RestoreSortIfNeed();
                }
            }
        }
Exemplo n.º 6
0
        internal void CreateDownloadRows(List <ChapterRow> items, OutputFormat[] formats)
        {
            foreach (var chapter in items.Where(item => downloadRows.All(r => r.Url != item.Url)))
            {
                var savePath = View.GetSavePath(chapter);
                var task     = new DownloadRow
                {
                    Name         = chapter.DisplayName,
                    Url          = chapter.Url,
                    SaveToFolder = savePath,
                    Formats      = formats
                };
                downloadRows.Add(task);
            }

            View.SetDownloadRows(downloadRows);
        }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
        [M(O.AggressiveInlining)] private static bool TryGetDownloadProgress(DownloadRow row, out double part, out string progressText)
        {
            var st = row.Status;

            switch (st)
            {
            case DownloadStatus.Created:
            case DownloadStatus.Started:
            case DownloadStatus.Wait:
                part         = default;
                progressText = null;
                return(false);

            default:
                string percentText;
                if (0 < row.TotalParts)
                {
                    part = (1.0 * row.SuccessDownloadParts) / row.TotalParts;
                    var percent = (row.TotalParts <= (row.SuccessDownloadParts + row.FailedDownloadParts)) ? 100 : Extensions.Min((byte)(100 * part), 99);
                    percentText = percent.ToString();
                }
                else if (st == DownloadStatus.Canceled)       //not-started
                {
                    part         = default;
                    progressText = null;
                    return(false);
                }
                else
                {
                    part        = 0;
                    percentText = "-";
                }

                var failedParts = ((row.FailedDownloadParts != 0) ? $" (failed: {row.FailedDownloadParts})" : null);
                progressText = $"{percentText}%  ({row.SuccessDownloadParts} of {row.TotalParts}{failedParts})";
                return(true);
            }
        }
Exemplo n.º 11
0
        [M(O.AggressiveInlining)] private static string GetApproxTotalBytesText(DownloadRow row)
        {
            var size = row.GetApproxTotalBytes();

            return(size.HasValue ? GetDisplaySizeText(size.Value) : string.Empty);
        }
Exemplo n.º 12
0
 public bool SelectDownloadRow(DownloadRow row) => SelectDownloadRowInternal(row);
Exemplo n.º 13
0
 internal void Remove(DownloadRow chapter)
 {
     downloadRows.Remove(chapter);
     View.SetDownloadRows(downloadRows);
 }