// --------------------------------------------------------------------------------------------------------------------
//
// 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 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.
///
public void ProcessLogs(string destination)
{
ThreadPool.QueueUserWorkItem(delegate { this.Service.ProcessEncodeLogs(destination); });
}
///
/// Start with a LibHb EncodeJob Object
///
///
/// The job.
///
///
/// The enable Logging.
///
public void Start(QueueTask job, bool enableLogging)
{
ThreadPool.QueueUserWorkItem(
delegate { this.Service.StartEncode(job, enableLogging); });
}
///
/// Kill the CLI process
///
public void Stop()
{
ThreadPool.QueueUserWorkItem(delegate { this.Service.StopEncode(); });
}
#endregion
#endregion
}
}