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