namespace VideoBrowser.Controls.CefSharpBrowser.Models { using Newtonsoft.Json; using System; using System.Windows.Input; using VideoBrowser.Common; using VideoBrowser.Controls.CefSharpBrowser.Helpers; using VideoBrowser.Extensions; /// /// Defines the . /// public class DownloadItemModel : NotifyPropertyChanged, IEquatable, IDisposable { #region Fields private string _fileSize; private bool _isQueuedControlsVisible = true; private string _outputPath; private string _pauseText = "Pause"; private int _progress; private string _status; private string _thumbnail; private string _title; private string _url; private bool Disposed = false;// To detect redundant calls #endregion Fields #region Constructors /// /// Initializes a new instance of the class. /// public DownloadItemModel() { this.ExecuteDownloadedCommand = new RelayCommand(this.OnExecuteDownloaded, nameof(this.ExecuteDownloadedCommand)); this.ShowDownloadedFolderCommand = new RelayCommand(this.OnShowDownloadedFolderCommand, nameof(this.ShowDownloadedFolderCommand)); } /// /// Initializes a new instance of the class. /// /// The other. internal DownloadItemModel(DownloadItemModel other) { this.FileSize = other.FileSize; this.IsApplicationThumbnail = other.IsApplicationThumbnail; this.IsQueuedControlsVisible = other.IsQueuedControlsVisible; this.OutputPath = other.OutputPath; this.PauseText = other.PauseText; this.Progress = other.Progress; this.Status = other.Status; this.Thumbnail = other.Thumbnail; this.Title = other.Title; this.Url = other.Url; } #endregion Constructors #region Properties /// /// Gets or sets the CancelDownloadCommand. /// [JsonIgnore] public ICommand CancelDownloadCommand { get; protected set; } /// /// Gets or sets the ExecuteDownloadedCommand. /// [JsonIgnore] public ICommand ExecuteDownloadedCommand { get; protected set; } /// /// Gets or sets the FileSize. /// public string FileSize { get => this._fileSize; set => this.Set(this.PropertyChangedHandler, ref this._fileSize, value); } /// /// Gets or sets a value indicating whether IsApplicationThumbnail. /// public bool IsApplicationThumbnail { get; set; } /// /// Gets a value indicating whether IsCompletedControlsVisible. /// [JsonIgnore] public bool IsCompletedControlsVisible { get => !this.IsQueuedControlsVisible; } /// /// Gets or sets a value indicating whether IsQueuedControlsVisible. /// public bool IsQueuedControlsVisible { get => _isQueuedControlsVisible; set { if (!this.Set(this.PropertyChangedHandler, ref _isQueuedControlsVisible, value)) { return; } this.OnPropertyChanged(nameof(this.IsCompletedControlsVisible)); } } /// /// Gets or sets the OutputPath. /// public string OutputPath { get => _outputPath; set => this.Set(this.PropertyChangedHandler, ref _outputPath, value); } /// /// Gets or sets the PauseDownloadCommand. /// [JsonIgnore] public ICommand PauseDownloadCommand { get; protected set; } /// /// Gets or sets the PauseText. /// public string PauseText { get => _pauseText; set => this.Set(this.PropertyChangedHandler, ref _pauseText, value); } /// /// Gets or sets the Progress. /// public int Progress { get => this._progress; set => this.Set(this.PropertyChangedHandler, ref this._progress, value); } /// /// Gets or sets the ShowDownloadedFolderCommand. /// [JsonIgnore] public ICommand ShowDownloadedFolderCommand { get; protected set; } /// /// Gets or sets the Status. /// public string Status { get => this._status; set => this.Set(this.PropertyChangedHandler, ref this._status, value); } /// /// Gets or sets the Thumbnail. /// public string Thumbnail { get => _thumbnail; set => this.Set(this.PropertyChangedHandler, ref _thumbnail, value); } /// /// Gets or sets the Title. /// public string Title { get => this._title; set => this.Set(this.PropertyChangedHandler, ref this._title, value); } /// /// Gets or sets the Url. /// public string Url { get => this._url; set => this.Set(this.PropertyChangedHandler, ref this._url, value); } #endregion Properties #region Methods /// /// The Dispose. /// public void Dispose() { // Do not change this code. Put cleanup code in Dispose(bool disposing) above. Dispose(true); } /// /// The Equals. /// /// The other. /// The . public bool Equals(DownloadItemModel other) { var isEqual = other != null && this.OutputPath == other.OutputPath; return isEqual; } /// /// The Equals. /// /// The obj. /// The . public override bool Equals(object obj) { return Equals(obj as DownloadItemModel); } /// /// The GetHashCode. /// /// The . public override int GetHashCode() { var hash = this.OutputPath == null ? string.Empty.GetHashCode() : this.OutputPath.GetHashCode(); return hash; } /// /// The Dispose. /// /// The disposing. protected virtual void Dispose(bool disposing) { if (!this.Disposed) { if (disposing) { // TODO: dispose managed state (managed objects). } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. this.Disposed = true; } } /// /// The OnPlayMedia. /// /// The obj. private void OnExecuteDownloaded(object obj) { ProcessHelper.Start(this.OutputPath); } /// /// The OnShowMediaInFolder. /// /// The obj. private void OnShowDownloadedFolderCommand(object obj) { ProcessHelper.OpenContainedFolder(this.OutputPath); } #endregion Methods } }