Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OperationModel"/> class.
        /// </summary>
        /// <param name="operation">The operation<see cref="Operation"/>.</param>
        public OperationModel(Operation operation)
        {
            this.Operation  = operation;
            this.Title      = this.Operation.Title;
            this.Url        = this.Operation.Link;
            this.Duration   = FormatString.FormatVideoLength(this.Operation.Duration);
            this.FileSize   = FormatString.FormatFileSize(this.Operation.FileSize);
            this.OutputPath = this.Operation.Output;
            this.Thumbnail  = this.Operation.Thumbnail;

            this.CancelDownloadCommand = new RelayCommand((o) => this.CancelDownloadAction?.Invoke(this), nameof(this.CancelDownloadCommand), (o) => this.Operation.CanStop());
            this.PauseDownloadCommand  = new RelayCommand((o) => this.PauseDownloadAction?.Invoke(this), nameof(this.PauseDownloadCommand), (o) => this.Operation.CanPause() || this.Operation.CanResume());

            this.Operation.Completed              += OnOperation_Completed;
            this.Operation.ProgressChanged        += OnOperation_ProgressChanged;
            this.Operation.PropertyChanged        += OnOperation_PropertyChanged;
            this.Operation.ReportsProgressChanged += OnOperation_ReportsProgressChanged;
            this.Operation.Started       += OnOperation_Started;
            this.Operation.StatusChanged += OnOperation_StatusChanged;

            // Set Status text, so it's not empty until a StatusChanged event is fired
            this.OnOperation_StatusChanged(this, EventArgs.Empty);
        }