namespace VideoBrowser.Controls.CefSharpBrowser.Models
{
using CefSharp;
using VideoBrowser.Common;
using VideoBrowser.Helpers;
///
/// Defines the .
///
public class DownloadProcessModel : DownloadItemModel
{
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The item.
internal DownloadProcessModel(DownloadItem item)
{
this.Initialize(item);
this.IsApplicationThumbnail = true;
this.CancelDownloadCommand = new RelayCommand(this.OnCancelDownload, nameof(this.CancelDownloadCommand));
}
#endregion Constructors
#region Properties
///
/// Gets a value indicating whether IsCanceled.
///
internal bool IsCanceled { get; private set; }
#endregion Properties
#region Methods
///
/// The UpdateInfo.
///
internal void UpdateInfo(DownloadItem downloadItem)
{
this.OutputPath = downloadItem.FullPath;
this.Progress = downloadItem.PercentComplete;
var speed = $"{downloadItem.CurrentSpeed.FormatFileSize()}/s";
var percentComplete = $"{downloadItem.PercentComplete}%";
var completeStatus = "Completed";
this.Status = downloadItem.IsComplete ? completeStatus : $"{percentComplete} - {speed}";
if (this.Status == completeStatus)
{
this.IsQueuedControlsVisible = false;
}
this.Thumbnail = this.OutputPath;
}
///
/// The Initialize.
///
private void Initialize(DownloadItem downloadItem)
{
this.FileSize = FormatString.FormatFileSize(downloadItem.TotalBytes);
this.Title = downloadItem.SuggestedFileName;
this.Url = downloadItem.OriginalUrl;
this.UpdateInfo(downloadItem);
}
///
/// The OnCancelDownload.
///
/// The obj.
private void OnCancelDownload(object obj)
{
this.IsCanceled = true;
}
#endregion Methods
}
}