// -------------------------------------------------------------------------------------------------------------------- // // 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 IEncode 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.Model; using HandBrake.ApplicationServices.Services.Interfaces; /// /// Isolated Scan Service. /// This is an implementation of the IEncode implementation that runs scans on a seperate process /// public class IsolatedEncodeService : BackgroundServiceConnector, IEncode { #region Constructors and Destructors /// /// Initializes a new instance of the class. /// /// /// The port. /// public IsolatedEncodeService(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); } } #endregion #region Events /// /// The encode completed. /// public event EncodeCompletedStatus EncodeCompleted; /// /// The encode started. /// public event EventHandler EncodeStarted; /// /// The encode status changed. /// public event EncodeProgessStatus EncodeStatusChanged; #endregion #region Properties /// /// Gets ActivityLog. /// public string ActivityLog { get { return this.IsConnected ? this.Service.EncodeActivityLog : "Unable to connect to background worker service ..."; } } /// /// Gets the log index. /// public int LogIndex { get { return -1; } } /// /// Gets a value indicating whether can pause. /// public bool CanPause { get { return false; // TODO make this work. } } /// /// Gets or sets IsPaused /// public bool IsPasued { get; private set; } /// /// Gets a value indicating whether IsEncoding. /// public bool IsEncoding { get { return this.IsConnected && this.Service.IsEncoding; } } #endregion #region Public Methods /// /// The encode completed callback. /// /// /// The event args. /// public override void EncodeCompletedCallback(EncodeCompletedEventArgs eventArgs) { if (this.EncodeCompleted != null) { ThreadPool.QueueUserWorkItem(delegate { this.EncodeCompleted(this, eventArgs); }); } base.EncodeCompletedCallback(eventArgs); } /// /// The encode progress callback. /// /// /// The event args. /// public override void EncodeProgressCallback(EncodeProgressEventArgs eventArgs) { if (this.EncodeStatusChanged != null) { ThreadPool.QueueUserWorkItem(delegate { this.EncodeStatusChanged(this, eventArgs); }); } base.EncodeProgressCallback(eventArgs); } #endregion #region Implemented Interfaces #region IEncode /// /// Copy the log file to the desired destinations /// /// /// The destination. /// /// /// The configuration. /// public void ProcessLogs(string destination, HBConfiguration configuration) { ThreadPool.QueueUserWorkItem(delegate { this.Service.ProcessEncodeLogs(destination, configuration); }); } /// /// Start with a LibHb EncodeJob Object /// /// /// The job. /// public void Start(QueueTask job) { ThreadPool.QueueUserWorkItem( delegate { this.Service.StartEncode(job); }); } /// /// The pause. /// public void Pause() { } /// /// The resume. /// public void Resume() { } /// /// Kill the CLI process /// public void Stop() { ThreadPool.QueueUserWorkItem(delegate { this.Service.StopEncode(); }); } #endregion #endregion } }