// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Isolated Scan Service // This is an implementation of the IScan implementation that runs scans on a seperate process // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.ApplicationServices.Isolation { using System; using System.Threading; using HandBrake.ApplicationServices.EventArgs; using HandBrake.ApplicationServices.Exceptions; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services.Interfaces; /// /// Isolated Scan Service. /// This is an implementation of the IScan implementation that runs scans on a seperate process /// public class IsolatedScanService : BackgroundServiceConnector, IScan { #region Constants and Fields /// /// The post action. /// private Action postScanAction; #endregion #region Events /// /// The scan completed. /// public event ScanCompletedStatus ScanCompleted; /// /// The scan stared. /// public event EventHandler ScanStared; /// /// The scan status changed. /// public event ScanProgessStatus ScanStatusChanged; #endregion /// /// Initializes a new instance of the class. /// /// /// The port. /// public IsolatedScanService(string port) { try { if (this.CanConnect()) { this.Connect(port); } } catch (Exception exception) { throw new GeneralApplicationException("Unable to connect to scan worker process.", "Try restarting HandBrake", exception); } } #region Properties /// /// Gets ActivityLog. /// public string ActivityLog { get { return this.Service.ScanActivityLog; } } /// /// Gets a value indicating whether IsScanning. /// public bool IsScanning { get { return this.Service.IsScanning; } } /// /// Gets the Souce Data. /// public Source SouceData { get { return this.Service.SouceData; } } #endregion #region Public Methods /// /// The scan completed callback. /// /// /// The event args. /// public override void ScanCompletedCallback(ScanCompletedEventArgs eventArgs) { if (this.postScanAction != null) { this.postScanAction(true); } if (this.ScanCompleted != null) { ThreadPool.QueueUserWorkItem(delegate { this.ScanCompleted(this, eventArgs); }); } base.ScanCompletedCallback(eventArgs); } /// /// The scan progress callback. /// /// /// The event args. /// public override void ScanProgressCallback(ScanProgressEventArgs eventArgs) { if (this.ScanStatusChanged != null) { ThreadPool.QueueUserWorkItem(delegate { this.ScanStatusChanged(this, eventArgs); }); } base.ScanProgressCallback(eventArgs); } /// /// The scan started callback. /// public override void ScanStartedCallback() { if (this.ScanStared != null) { ThreadPool.QueueUserWorkItem(delegate { this.ScanStared(this, EventArgs.Empty); }); } base.ScanStartedCallback(); } #endregion #region Implemented Interfaces #region IScan /// /// Take a Scan Log file, and process it as if it were from the CLI. /// /// /// The path to the log file. /// public void DebugScanLog(string path) { throw new NotImplementedException("Not available in process isolation mode!"); } /// /// Scan a Source Path. /// Title 0: scan all /// /// /// Path to the file to scan /// /// /// int title number. 0 for scan all /// /// /// The preview Count. /// /// /// The post Action. /// public void Scan(string sourcePath, int title, int previewCount, Action postAction) { this.postScanAction = postAction; this.Service.ScanSource(sourcePath, title, previewCount); } /// /// Kill the scan /// public void Stop() { this.Service.StopScan(); } #endregion #endregion } }