// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Command to cancel a scan that is in progress // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Commands { using System; using System.Windows.Input; using HandBrake.ApplicationServices.Services.Interfaces; /// /// Command to cancel a scan that is in progress /// public class CancelScanCommand : ICommand { /// /// The scan service wrapper. /// private readonly IScanServiceWrapper scanServiceWrapper; /// /// Initializes a new instance of the class. /// /// /// The scan service wrapper. /// public CancelScanCommand(IScanServiceWrapper ssw) { this.scanServiceWrapper = ssw; this.scanServiceWrapper.ScanStared += this.ScanServiceWrapperScanStared; this.scanServiceWrapper.ScanCompleted += this.ScanServiceWrapperScanCompleted; } /// /// The scan service Scan Completed Event Handler. /// Fires CanExecuteChanged /// /// /// The sender. /// /// /// The ScanCompletedEventArgs. /// private void ScanServiceWrapperScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e) { Caliburn.Micro.Execute.OnUIThread(() => this.CanExecuteChanged(sender, EventArgs.Empty)); } /// /// The scan service scan started event handler. /// Fires CanExecuteChanged /// /// /// The sender. /// /// /// The EventArgs. /// private void ScanServiceWrapperScanStared(object sender, EventArgs e) { Caliburn.Micro.Execute.OnUIThread(() => this.CanExecuteChanged(sender, EventArgs.Empty)); } #region Implementation of ICommand /// /// Defines the method to be called when the command is invoked. /// /// Data used by the command. If the command does not require data to be passed, this object can be set to null. public void Execute(object parameter) { this.scanServiceWrapper.Stop(); } /// /// Defines the method that determines whether the command can execute in its current state. /// /// /// true if this command can be executed; otherwise, false. /// /// Data used by the command. If the command does not require data to be passed, this object can be set to null. public bool CanExecute(object parameter) { if (this.scanServiceWrapper != null) { return this.scanServiceWrapper.IsScanning; } return false; } /// /// The can execute changed. /// public event EventHandler CanExecuteChanged; #endregion } }