summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-08-22 20:11:18 +0000
committersr55 <[email protected]>2012-08-22 20:11:18 +0000
commitcbe5f09e69c95df3be3b38de06c2b7bd6b5bd949 (patch)
tree298b9b143b38433e16854089f6afe9d5d59cbe7e /win/CS/HandBrakeWPF
parentd363a3f1c5f19df252ba1ac118c7bb3bf2bf4e7c (diff)
WinGui: Initial Work to wire up Encode Process Isolation.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4914 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj2
-rw-r--r--win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs134
-rw-r--r--win/CS/HandBrakeWPF/Isolation/Interfaces/IIsolatedEncodeService.cs24
-rw-r--r--win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs189
-rw-r--r--win/CS/HandBrakeWPF/Isolation/IsolatedScanService.cs13
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs30
6 files changed, 325 insertions, 67 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index d560cc961..d3682caeb 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -130,6 +130,8 @@
<Compile Include="Converters\Subtitles\SubtitlesQueueDisplayConverter.cs" />
<Compile Include="Converters\Video\VideoEncoderConverter.cs" />
<Compile Include="Isolation\BackgroundServiceConnector.cs" />
+ <Compile Include="Isolation\IsolatedEncodeService.cs" />
+ <Compile Include="Isolation\Interfaces\IIsolatedEncodeService.cs" />
<Compile Include="Isolation\Interfaces\IIsolatedScanService.cs" />
<Compile Include="Isolation\IsolatedScanService.cs" />
<Compile Include="Services\DriveDetectService.cs" />
diff --git a/win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs b/win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs
index b6198da46..0d08f2dca 100644
--- a/win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs
+++ b/win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs
@@ -28,23 +28,23 @@ namespace HandBrakeWPF.Isolation
/// </summary>
public class BackgroundServiceConnector : IHbServiceCallback, IDisposable
{
+ #region Constants and Fields
+
/// <summary>
/// The error service.
/// </summary>
private readonly IErrorService errorService;
- #region Constants and Fields
-
/// <summary>
/// Gets or sets the pipe factory.
/// DuplexChannelFactory is necessary for Callbacks.
/// </summary>
- private DuplexChannelFactory<IServerService> pipeFactory;
+ private static DuplexChannelFactory<IServerService> pipeFactory;
/// <summary>
/// The background process.
/// </summary>
- private Process backgroundProcess;
+ private static Process backgroundProcess;
#endregion
@@ -73,7 +73,7 @@ namespace HandBrakeWPF.Isolation
#endregion
- #region Public Methods
+ #region Public Server Management Methods
/// <summary>
/// The can connect.
@@ -91,19 +91,24 @@ namespace HandBrakeWPF.Isolation
/// </summary>
public void Connect()
{
+ if (backgroundProcess == null)
+ {
+ // backgroundProcess = Process.Start("HandBrake.Server.exe");
+ }
+
ThreadPool.QueueUserWorkItem(delegate
{
try
{
- this.pipeFactory = new DuplexChannelFactory<IServerService>(
+ pipeFactory = new DuplexChannelFactory<IServerService>(
new InstanceContext(this),
new NetTcpBinding(),
new EndpointAddress("net.tcp://127.0.0.1:8000/IHbService"));
// Connect and Subscribe to the Server
- this.Service = this.pipeFactory.CreateChannel();
- this.Service.Subscribe();
- this.IsConnected = true;
+ Service = pipeFactory.CreateChannel();
+ Service.Subscribe();
+ IsConnected = true;
}
catch (Exception exc)
{
@@ -121,7 +126,7 @@ namespace HandBrakeWPF.Isolation
{
try
{
- this.Service.Unsubscribe();
+ Service.Unsubscribe();
}
catch (Exception exc)
{
@@ -130,33 +135,56 @@ namespace HandBrakeWPF.Isolation
}
}
- /// <summary>
- /// The scan source.
- /// </summary>
- /// <param name="path">
- /// The path.
- /// </param>
- /// <param name="title">
- /// The title.
- /// </param>
- /// <param name="previewCount">
- /// The preview count.
- /// </param>
- public void ScanSource(string path, int title, int previewCount)
- {
- ThreadPool.QueueUserWorkItem(delegate { this.Service.ScanSource(path, title, previewCount); });
- }
+ #endregion
- /// <summary>
- /// The start server.
- /// </summary>
- public void StartServer()
- {
- if (this.backgroundProcess == null)
- {
- this.backgroundProcess = Process.Start("HandBrake.Server.exe");
- }
- }
+ #region Public Service Methods
+
+ ///// <summary>
+ ///// The scan source.
+ ///// </summary>
+ ///// <param name="path">
+ ///// The path.
+ ///// </param>
+ ///// <param name="title">
+ ///// The title.
+ ///// </param>
+ ///// <param name="previewCount">
+ ///// The preview count.
+ ///// </param>
+ //public void ScanSource(string path, int title, int previewCount)
+ //{
+ // ThreadPool.QueueUserWorkItem(delegate { this.Service.ScanSource(path, title, previewCount); });
+ //}
+
+ ///// <summary>
+ ///// The stop scan.
+ ///// </summary>
+ //public void StopScan()
+ //{
+ // ThreadPool.QueueUserWorkItem(delegate { this.Service.StopScan(); });
+ //}
+
+ ///// <summary>
+ ///// Start an Encode
+ ///// </summary>
+ ///// <param name="job">
+ ///// The job.
+ ///// </param>
+ ///// <param name="enableLogging">
+ ///// The enable logging.
+ ///// </param>
+ //public void StartEncode(QueueTask job, bool enableLogging)
+ //{
+ // ThreadPool.QueueUserWorkItem(delegate { this.Service.StartEncode(job, enableLogging); });
+ //}
+
+ ///// <summary>
+ ///// Stop an Encode
+ ///// </summary>
+ //public void StopEncode()
+ //{
+ // ThreadPool.QueueUserWorkItem(delegate { this.Service.StopEncode(); });
+ //}
#endregion
@@ -169,7 +197,7 @@ namespace HandBrakeWPF.Isolation
/// </summary>
public void Dispose()
{
- this.Service.Unsubscribe();
+ Service.Unsubscribe();
}
#endregion
@@ -203,23 +231,35 @@ namespace HandBrakeWPF.Isolation
{
}
- #endregion
-
- #endregion
-
- #region Implementation of IHbServiceCallback
+ /// <summary>
+ /// The encode progress callback.
+ /// </summary>
+ /// <param name="eventArgs">
+ /// The event Args.
+ /// </param>
+ public virtual void EncodeProgressCallback(EncodeProgressEventArgs eventArgs)
+ {
+ }
/// <summary>
- /// The test.
+ /// The encode completed callback.
/// </summary>
- /// <param name="message">
- /// The message.
+ /// <param name="eventArgs">
+ /// The event Args.
/// </param>
- public void Test(string message)
+ public virtual void EncodeCompletedCallback(EncodeCompletedEventArgs eventArgs)
{
- Console.WriteLine(message);
}
+ /// <summary>
+ /// The encode started callback.
+ /// </summary>
+ public virtual void EncodeStartedCallback()
+ {
+ }
+
+ #endregion
+
#endregion
}
} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Isolation/Interfaces/IIsolatedEncodeService.cs b/win/CS/HandBrakeWPF/Isolation/Interfaces/IIsolatedEncodeService.cs
new file mode 100644
index 000000000..fb9912ccf
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Isolation/Interfaces/IIsolatedEncodeService.cs
@@ -0,0 +1,24 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="IIsolatedEncodeService.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The Isolated Encode Service interface.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Isolation.Interfaces
+{
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
+ /// <summary>
+ /// The Isolated Encode Service interface.
+ /// </summary>
+ public interface IIsolatedEncodeService : IEncode
+ {
+ /// <summary>
+ /// The disconnect.
+ /// </summary>
+ void Disconnect();
+ }
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs b/win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs
new file mode 100644
index 000000000..3c5363c28
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs
@@ -0,0 +1,189 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="IsolatedEncodeService.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Isolated Scan Service
+// This is an implementation of the IEncode implementation that runs scans on a seperate process
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Isolation
+{
+ using System;
+ using System.Threading;
+
+ using HandBrake.ApplicationServices.EventArgs;
+ using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
+ using HandBrakeWPF.Isolation.Interfaces;
+ using HandBrakeWPF.Services.Interfaces;
+
+ /// <summary>
+ /// Isolated Scan Service.
+ /// This is an implementation of the IEncode implementation that runs scans on a seperate process
+ /// </summary>
+ public class IsolatedEncodeService : BackgroundServiceConnector, IIsolatedEncodeService
+ {
+ #region Constructors and Destructors
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="IsolatedEncodeService"/> class.
+ /// </summary>
+ /// <param name="errorService">
+ /// The error Service.
+ /// </param>
+ public IsolatedEncodeService(IErrorService errorService)
+ : base(errorService)
+ {
+ try
+ {
+ if (this.CanConnect())
+ {
+ this.Connect();
+ }
+ }
+ catch (Exception exception)
+ {
+ errorService.ShowError(
+ "Unable to connect to scan worker process.", "Try restarting HandBrake", exception);
+ }
+ }
+
+ #endregion
+
+ #region Events
+
+ /// <summary>
+ /// The encode completed.
+ /// </summary>
+ public event EncodeCompletedStatus EncodeCompleted;
+
+ /// <summary>
+ /// The encode started.
+ /// </summary>
+ public event EventHandler EncodeStarted;
+
+ /// <summary>
+ /// The encode status changed.
+ /// </summary>
+ public event EncodeProgessStatus EncodeStatusChanged;
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Gets ActivityLog.
+ /// </summary>
+ public string ActivityLog
+ {
+ get
+ {
+ return Service.EncodeActivityLog;
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether IsEncoding.
+ /// </summary>
+ public bool IsEncoding
+ {
+ get
+ {
+ return Service.IsEncoding;
+ }
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ /// <summary>
+ /// The encode completed callback.
+ /// </summary>
+ /// <param name="eventArgs">
+ /// The event args.
+ /// </param>
+ public override void EncodeCompletedCallback(EncodeCompletedEventArgs eventArgs)
+ {
+ if (this.EncodeCompleted != null)
+ {
+ ThreadPool.QueueUserWorkItem(delegate { this.EncodeCompleted(this, eventArgs); });
+ }
+
+ base.EncodeCompletedCallback(eventArgs);
+ }
+
+ /// <summary>
+ /// The encode progress callback.
+ /// </summary>
+ /// <param name="eventArgs">
+ /// The event args.
+ /// </param>
+ 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
+
+ /// <summary>
+ /// Copy the log file to the desired destinations
+ /// </summary>
+ /// <param name="destination">
+ /// The destination.
+ /// </param>
+ public void ProcessLogs(string destination)
+ {
+ ThreadPool.QueueUserWorkItem(delegate { Service.ProcessEncodeLogs(destination); });
+ }
+
+ /// <summary>
+ /// Attempt to Safely kill a DirectRun() CLI
+ /// NOTE: This will not work with a MinGW CLI
+ /// Note: http://www.cygwin.com/ml/cygwin/2006-03/msg00330.html
+ /// </summary>
+ public void SafelyStop()
+ {
+ ThreadPool.QueueUserWorkItem(delegate { Service.StopEncode(); });
+ }
+
+ /// <summary>
+ /// Start with a LibHb EncodeJob Object
+ /// </summary>
+ /// <param name="job">
+ /// The job.
+ /// </param>
+ /// <param name="enableLogging">
+ /// The enable Logging.
+ /// </param>
+ public void Start(QueueTask job, bool enableLogging)
+ {
+ ThreadPool.QueueUserWorkItem(
+ delegate { Service.StartEncode(job, enableLogging); });
+ }
+
+ /// <summary>
+ /// Kill the CLI process
+ /// </summary>
+ public void Stop()
+ {
+ ThreadPool.QueueUserWorkItem(delegate { Service.StopEncode(); });
+ }
+
+ #endregion
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Isolation/IsolatedScanService.cs b/win/CS/HandBrakeWPF/Isolation/IsolatedScanService.cs
index 01153d2c6..608b00c21 100644
--- a/win/CS/HandBrakeWPF/Isolation/IsolatedScanService.cs
+++ b/win/CS/HandBrakeWPF/Isolation/IsolatedScanService.cs
@@ -66,7 +66,6 @@ namespace HandBrakeWPF.Isolation
{
if (this.CanConnect())
{
- this.StartServer();
this.Connect();
}
}
@@ -86,7 +85,7 @@ namespace HandBrakeWPF.Isolation
{
get
{
- return this.Service.ActivityLog;
+ return Service.ScanActivityLog;
}
}
@@ -97,7 +96,7 @@ namespace HandBrakeWPF.Isolation
{
get
{
- return this.Service.IsScanning;
+ return Service.IsScanning;
}
}
@@ -108,7 +107,7 @@ namespace HandBrakeWPF.Isolation
{
get
{
- return this.Service.SouceData;
+ return Service.SouceData;
}
}
@@ -180,7 +179,7 @@ namespace HandBrakeWPF.Isolation
/// </param>
public void DebugScanLog(string path)
{
- throw new NotImplementedException();
+ throw new NotImplementedException("Not available in process isolation mode!");
}
/// <summary>
@@ -202,7 +201,7 @@ namespace HandBrakeWPF.Isolation
public void Scan(string sourcePath, int title, int previewCount, Action<bool> postAction)
{
this.postScanAction = postAction;
- this.Service.ScanSource(sourcePath, title, previewCount);
+ Service.ScanSource(sourcePath, title, previewCount);
}
/// <summary>
@@ -210,7 +209,7 @@ namespace HandBrakeWPF.Isolation
/// </summary>
public void Stop()
{
- throw new NotImplementedException();
+ Service.StopScan();
}
#endregion
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index 3fc83ddac..5f65b26ce 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -48,16 +48,6 @@ namespace HandBrakeWPF.ViewModels
#region Private Variables and Services
/// <summary>
- /// The Source Scan Service.
- /// </summary>
- private IScan scanService;
-
- /// <summary>
- /// The Encode Service
- /// </summary>
- private readonly IEncode encodeService;
-
- /// <summary>
/// The Encode Service
/// </summary>
private readonly IQueueProcessor queueProcessor;
@@ -93,6 +83,16 @@ namespace HandBrakeWPF.ViewModels
private readonly IUserSettingService userSettingService;
/// <summary>
+ /// The Source Scan Service.
+ /// </summary>
+ private IScan scanService;
+
+ /// <summary>
+ /// The Encode Service
+ /// </summary>
+ private IEncode encodeService;
+
+ /// <summary>
/// HandBrakes Main Window Title
/// </summary>
private string windowName;
@@ -1147,18 +1147,22 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public void TestIsolationServices()
{
- // Unhook the old service
+ // Unhook the old services
this.scanService.ScanStared -= this.ScanStared;
this.scanService.ScanCompleted -= this.ScanCompleted;
this.scanService.ScanStatusChanged -= this.ScanStatusChanged;
+ this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;
- // Replace the Service
+ // Replace the Services
this.scanService = new IsolatedScanService(this.errorService);
+ this.encodeService = new IsolatedEncodeService(this.errorService);
+ this.queueProcessor.SwapEncodeService(this.encodeService);
- // Add Event Hooks
+ // Add the new Event Hooks
this.scanService.ScanStared += this.ScanStared;
this.scanService.ScanCompleted += this.ScanCompleted;
this.scanService.ScanStatusChanged += this.ScanStatusChanged;
+ this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;
}
#endregion