summaryrefslogtreecommitdiffstats
path: root/win/CS
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
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')
-rw-r--r--win/CS/HandBrake.ApplicationServices/EventArgs/EncodeCompletedEventArgs.cs5
-rw-r--r--win/CS/HandBrake.ApplicationServices/EventArgs/EncodeProgressEventArgs.cs9
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs28
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode.cs13
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs24
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs9
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs52
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs10
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs13
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/ServerService.cs267
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs29
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs1
-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
18 files changed, 698 insertions, 154 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/EventArgs/EncodeCompletedEventArgs.cs b/win/CS/HandBrake.ApplicationServices/EventArgs/EncodeCompletedEventArgs.cs
index 12f3af2e9..44a66cac7 100644
--- a/win/CS/HandBrake.ApplicationServices/EventArgs/EncodeCompletedEventArgs.cs
+++ b/win/CS/HandBrake.ApplicationServices/EventArgs/EncodeCompletedEventArgs.cs
@@ -10,10 +10,12 @@
namespace HandBrake.ApplicationServices.EventArgs
{
using System;
+ using System.Runtime.Serialization;
/// <summary>
/// Encode Progress Event Args
/// </summary>
+ [DataContractAttribute]
public class EncodeCompletedEventArgs : EventArgs
{
/// <summary>
@@ -38,16 +40,19 @@ namespace HandBrake.ApplicationServices.EventArgs
/// <summary>
/// Gets or sets a value indicating whether Successful.
/// </summary>
+ [DataMember]
public bool Successful { get; set; }
/// <summary>
/// Gets or sets Exception.
/// </summary>
+ [DataMember]
public Exception Exception { get; set; }
/// <summary>
/// Gets or sets ErrorInformation.
/// </summary>
+ [DataMember]
public string ErrorInformation { get; set; }
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/EventArgs/EncodeProgressEventArgs.cs b/win/CS/HandBrake.ApplicationServices/EventArgs/EncodeProgressEventArgs.cs
index f4c7e9446..37cb76f25 100644
--- a/win/CS/HandBrake.ApplicationServices/EventArgs/EncodeProgressEventArgs.cs
+++ b/win/CS/HandBrake.ApplicationServices/EventArgs/EncodeProgressEventArgs.cs
@@ -10,45 +10,54 @@
namespace HandBrake.ApplicationServices.EventArgs
{
using System;
+ using System.Runtime.Serialization;
/// <summary>
/// Encode Progress Event Args
/// </summary>
+ [DataContractAttribute]
public class EncodeProgressEventArgs : EventArgs
{
/// <summary>
/// Gets or sets PercentComplete.
/// </summary>
+ [DataMember]
public float PercentComplete { get; set; }
/// <summary>
/// Gets or sets CurrentFrameRate.
/// </summary>
+ [DataMember]
public float CurrentFrameRate { get; set; }
/// <summary>
/// Gets or sets AverageFrameRate.
/// </summary>
+ [DataMember]
public float AverageFrameRate { get; set; }
/// <summary>
/// Gets or sets EstimatedTimeLeft.
/// </summary>
+ [DataMember]
public TimeSpan EstimatedTimeLeft { get; set; }
/// <summary>
/// Gets or sets Task.
/// </summary>
+ [DataMember]
public int Task { get; set; }
/// <summary>
/// Gets or sets TaskCount.
/// </summary>
+ [DataMember]
public int TaskCount { get; set; }
/// <summary>
/// Gets or sets ElapsedTime.
/// </summary>
+ [DataMember]
public TimeSpan ElapsedTime { get; set; }
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
index e20215bcf..36b9002bc 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
@@ -13,8 +13,6 @@ namespace HandBrake.ApplicationServices.Services.Base
using System.IO;
using System.Text;
- using Caliburn.Micro;
-
using HandBrake.ApplicationServices.EventArgs;
using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Model;
@@ -31,17 +29,22 @@ namespace HandBrake.ApplicationServices.Services.Base
/// <summary>
/// A Lock for the filewriter
/// </summary>
- private static readonly object fileWriterLock = new object();
+ private static readonly object FileWriterLock = new object();
/// <summary>
/// The User Setting Service
/// </summary>
- private IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ private readonly IUserSettingService userSettingService;
/// <summary>
/// Windows 7 API Pack wrapper
/// </summary>
- private Win7 windowsSeven = new Win7();
+ private readonly Win7 windowsSeven = new Win7();
+
+ /// <summary>
+ /// The Log File Header
+ /// </summary>
+ private readonly StringBuilder header = GeneralUtilities.CreateCliLogHeader();
/// <summary>
/// The Log Buffer
@@ -53,18 +56,17 @@ namespace HandBrake.ApplicationServices.Services.Base
/// </summary>
private StreamWriter fileWriter;
- /// <summary>
- /// The Log File Header
- /// </summary>
- private StringBuilder header = GeneralUtilities.CreateCliLogHeader();
-
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="EncodeBase"/> class.
/// </summary>
- public EncodeBase()
+ /// <param name="userSettingService">
+ /// The user Setting Service.
+ /// </param>
+ public EncodeBase(IUserSettingService userSettingService)
{
+ this.userSettingService = userSettingService;
this.logBuffer = new StringBuilder();
}
@@ -310,7 +312,7 @@ namespace HandBrake.ApplicationServices.Services.Base
this.LogBuffer.AppendLine(message);
}
- lock (fileWriterLock)
+ lock (FileWriterLock)
{
if (this.fileWriter != null && this.fileWriter.BaseStream.CanWrite)
{
@@ -341,7 +343,7 @@ namespace HandBrake.ApplicationServices.Services.Base
{
try
{
- lock (fileWriterLock)
+ lock (FileWriterLock)
{
if (this.fileWriter != null)
{
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
index f0f1b656b..98827a6e3 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
@@ -15,8 +15,6 @@ namespace HandBrake.ApplicationServices.Services
using System.Threading;
using System.Windows.Forms;
- using Caliburn.Micro;
-
using HandBrake.ApplicationServices.EventArgs;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Services.Base;
@@ -35,7 +33,7 @@ namespace HandBrake.ApplicationServices.Services
/// <summary>
/// The User Setting Service
/// </summary>
- private IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ private readonly IUserSettingService userSettingService;
/// <summary>
/// Gets The Process Handle
@@ -62,8 +60,13 @@ namespace HandBrake.ApplicationServices.Services
/// <summary>
/// Initializes a new instance of the <see cref="Encode"/> class.
/// </summary>
- public Encode()
+ /// <param name="userSettingService">
+ /// The user Setting Service.
+ /// </param>
+ public Encode(IUserSettingService userSettingService)
+ : base(userSettingService)
{
+ this.userSettingService = userSettingService;
this.EncodeStarted += this.EncodeEncodeStarted;
GrowlCommunicator.Register();
}
@@ -116,7 +119,7 @@ namespace HandBrake.ApplicationServices.Services
if (this.userSettingService.GetUserSetting<bool>(ASUserSettingConstants.PreventSleep))
{
- Win32.PreventSleep();
+ // Win32.PreventSleep();
}
// Make sure the path exists, attempt to create it if it doesn't
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs
index afb7ca5c3..1d10e3062 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IHbServiceCallback.cs
@@ -42,5 +42,29 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
/// </summary>
[OperationContract(IsOneWay = true)]
void ScanStartedCallback();
+
+ /// <summary>
+ /// The encode progress callback.
+ /// </summary>
+ /// <param name="eventArgs">
+ /// The event Args.
+ /// </param>
+ [OperationContract(IsOneWay = true)]
+ void EncodeProgressCallback(EncodeProgressEventArgs eventArgs);
+
+ /// <summary>
+ /// The encode completed callback.
+ /// </summary>
+ /// <param name="eventArgs">
+ /// The event Args.
+ /// </param>
+ [OperationContract(IsOneWay = true)]
+ void EncodeCompletedCallback(EncodeCompletedEventArgs eventArgs);
+
+ /// <summary>
+ /// The encode started callback.
+ /// </summary>
+ [OperationContract(IsOneWay = true)]
+ void EncodeStartedCallback();
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs
index 22cf365b0..b695bab49 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs
@@ -56,5 +56,14 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
/// Requests a pause of the encode queue.
/// </summary>
void Pause();
+
+ /// <summary>
+ /// Swap encode service.
+ /// Temp method until Castle is hooked up.
+ /// </summary>
+ /// <param name="service">
+ /// The service.
+ /// </param>
+ void SwapEncodeService(IEncode service);
}
} \ No newline at end of file
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs
index 22156e6fc..49eedffa5 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IServerService.cs
@@ -12,6 +12,7 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
using System.Runtime.Serialization;
using System.ServiceModel;
+ using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
/// <summary>
@@ -24,7 +25,13 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
/// Gets the activity log.
/// </summary>
[DataMember]
- string ActivityLog { get; }
+ string ScanActivityLog { get; }
+
+ /// <summary>
+ /// Gets the activity log.
+ /// </summary>
+ [DataMember]
+ string EncodeActivityLog { get; }
/// <summary>
/// Gets the souce data.
@@ -38,8 +45,20 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
/// <summary>
/// Gets a value indicating whether is scanning.
/// </summary>
- [DataMember]
- bool IsScanning { get; }
+ bool IsScanning
+ {
+ [OperationContract]
+ get;
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether is encoding.
+ /// </summary>
+ bool IsEncoding
+ {
+ [OperationContract]
+ get;
+ }
/// <summary>
/// Start the WCF Service
@@ -67,6 +86,33 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
void ScanSource(string path, int title, int previewCount);
/// <summary>
+ /// Start and Encode
+ /// </summary>
+ /// <param name="job">
+ /// The job.
+ /// </param>
+ /// <param name="enableLogging">
+ /// The enable logging.
+ /// </param>
+ [OperationContract]
+ void StartEncode(QueueTask job, bool enableLogging);
+
+ /// <summary>
+ /// The process encode logs.
+ /// </summary>
+ /// <param name="destination">
+ /// The destination.
+ /// </param>
+ [OperationContract]
+ void ProcessEncodeLogs(string destination);
+
+ /// <summary>
+ /// Stop and Encode
+ /// </summary>
+ [OperationContract]
+ void StopEncode();
+
+ /// <summary>
/// Stop the scan.
/// </summary>
[OperationContract]
diff --git a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
index 086305f4e..3ae06bbfd 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
@@ -40,7 +40,7 @@ namespace HandBrake.ApplicationServices.Services
/// <summary>
/// The User Setting Service
/// </summary>
- private IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ private readonly IUserSettingService userSettingService;
/// <summary>
/// The Start time of the current Encode;
@@ -62,8 +62,14 @@ namespace HandBrake.ApplicationServices.Services
/// <summary>
/// Initializes a new instance of the <see cref="LibEncode"/> class.
/// </summary>
- public LibEncode()
+ /// <param name="userSettingService">
+ /// The user Setting Service.
+ /// </param>
+ public LibEncode(IUserSettingService userSettingService)
+ : base(userSettingService)
{
+ this.userSettingService = userSettingService;
+
// Setup the HandBrake Instance
this.instance = IoC.Get<IHandBrakeInstance>();
this.instance.EncodeCompleted += this.InstanceEncodeCompleted;
diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
index cd1ff226d..f90aa0ef4 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
@@ -11,7 +11,6 @@ namespace HandBrake.ApplicationServices.Services
{
using System;
using System.Diagnostics;
- using System.IO;
using System.Windows.Forms;
using Caliburn.Micro;
@@ -181,6 +180,18 @@ namespace HandBrake.ApplicationServices.Services
}
/// <summary>
+ /// Swap encode service.
+ /// Temp method until Castle is hooked up.
+ /// </summary>
+ /// <param name="service">
+ /// The service.
+ /// </param>
+ public void SwapEncodeService(IEncode service)
+ {
+ this.EncodeService = service;
+ }
+
+ /// <summary>
/// After an encode is complete, move onto the next job.
/// </summary>
/// <param name="sender">
diff --git a/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs b/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
index 025b7c432..9984ade21 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
@@ -16,13 +16,15 @@ namespace HandBrake.ApplicationServices.Services
using System.Windows;
using HandBrake.ApplicationServices.EventArgs;
+ using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Services.Interfaces;
/// <summary>
/// HandBrake WCF Service
/// </summary>
- [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true, ConcurrencyMode = ConcurrencyMode.Single)]
+ [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true,
+ ConcurrencyMode = ConcurrencyMode.Single)]
public class ServerService : IServerService
{
#region Constants and Fields
@@ -33,6 +35,11 @@ namespace HandBrake.ApplicationServices.Services
private static readonly List<IHbServiceCallback> Subscribers = new List<IHbServiceCallback>();
/// <summary>
+ /// The encode service.
+ /// </summary>
+ private static IEncode encodeService;
+
+ /// <summary>
/// The scan service.
/// </summary>
private static IScan scanService;
@@ -44,46 +51,48 @@ namespace HandBrake.ApplicationServices.Services
#endregion
- #region Implemented Interfaces
-
- #region IServerService
+ #region Properties
/// <summary>
- /// The scan source.
+ /// Gets the activity log.
/// </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)
+ [DataMember]
+ public string ActivityLog
{
- Console.WriteLine("Starting Source Scan for: " + path);
- scanService.ScanStared += this.ScanStaredHandler;
- scanService.ScanStatusChanged += this.ScanStatusChangedHandler;
- scanService.ScanCompleted += this.ScanCompletedHandler;
-
- scanService.Scan(path, title, previewCount, null);
+ get
+ {
+ return scanService.ActivityLog;
+ }
}
/// <summary>
/// Gets the activity log.
/// </summary>
+ public string EncodeActivityLog { get; private set; }
+
+ /// <summary>
+ /// Gets a value indicating whether is encoding.
+ /// </summary>
+ public bool IsEncoding { get; private set; }
+
+ /// <summary>
+ /// Gets a value indicating whether is scanning.
+ /// </summary>
[DataMember]
- public string ActivityLog
+ public bool IsScanning
{
get
{
- return scanService.ActivityLog;
-
+ return scanService.IsScanning;
}
}
/// <summary>
+ /// Gets the activity log.
+ /// </summary>
+ public string ScanActivityLog { get; private set; }
+
+ /// <summary>
/// Gets the souce data.
/// </summary>
[DataMember]
@@ -95,16 +104,43 @@ namespace HandBrake.ApplicationServices.Services
}
}
+ #endregion
+
+ #region Implemented Interfaces
+
+ #region IServerService
+
/// <summary>
- /// Gets a value indicating whether is scanning.
+ /// The process encode logs.
/// </summary>
- [DataMember]
- public bool IsScanning
+ /// <param name="destination">
+ /// The destination.
+ /// </param>
+ public void ProcessEncodeLogs(string destination)
{
- get
- {
- return scanService.IsScanning;
- }
+ encodeService.ProcessLogs(destination);
+ }
+
+ /// <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)
+ {
+ Console.WriteLine("Starting Source Scan for: " + path);
+ scanService.ScanStared += this.ScanStaredHandler;
+ scanService.ScanStatusChanged += this.ScanStatusChangedHandler;
+ scanService.ScanCompleted += this.ScanCompletedHandler;
+
+ scanService.Scan(path, title, previewCount, null);
}
/// <summary>
@@ -121,12 +157,31 @@ namespace HandBrake.ApplicationServices.Services
Console.WriteLine("Service Started");
// Setup the services we are going to use.
- scanService = new ScanService(new UserSettingService());
+ scanService = new ScanService(new UserSettingService()); // TODO this needs wired up with castle
+ encodeService = new Encode(new UserSettingService());
Console.ReadLine();
}
}
/// <summary>
+ /// Start and Encode
+ /// </summary>
+ /// <param name="job">
+ /// The job.
+ /// </param>
+ /// <param name="enableLogging">
+ /// The enable logging.
+ /// </param>
+ public void StartEncode(QueueTask job, bool enableLogging)
+ {
+ Console.WriteLine("Starting Source Encode for: " + job.Task.Source);
+ encodeService.EncodeCompleted += this.EncodeServiceEncodeCompleted;
+ encodeService.EncodeStarted += this.encodeService_EncodeStarted;
+ encodeService.EncodeStatusChanged += this.encodeService_EncodeStatusChanged;
+ encodeService.Start(job, enableLogging);
+ }
+
+ /// <summary>
/// Stop this service
/// </summary>
public void Stop()
@@ -139,6 +194,14 @@ namespace HandBrake.ApplicationServices.Services
}
/// <summary>
+ /// Stop and Encode
+ /// </summary>
+ public void StopEncode()
+ {
+ encodeService.Stop();
+ }
+
+ /// <summary>
/// Stop the scan.
/// </summary>
public void StopScan()
@@ -222,17 +285,17 @@ namespace HandBrake.ApplicationServices.Services
{
Subscribers.ForEach(
delegate(IHbServiceCallback callback)
- {
- if (((ICommunicationObject)callback).State == CommunicationState.Opened)
{
- Console.WriteLine("Scan Completed Callback");
- callback.ScanCompletedCallback(e);
- }
- else
- {
- Subscribers.Remove(callback);
- }
- });
+ if (((ICommunicationObject)callback).State == CommunicationState.Opened)
+ {
+ Console.WriteLine("Scan Completed Callback");
+ callback.ScanCompletedCallback(e);
+ }
+ else
+ {
+ Subscribers.Remove(callback);
+ }
+ });
scanService.ScanStared -= this.ScanStaredHandler;
scanService.ScanStatusChanged -= this.ScanStatusChangedHandler;
@@ -252,17 +315,17 @@ namespace HandBrake.ApplicationServices.Services
{
Subscribers.ForEach(
delegate(IHbServiceCallback callback)
- {
- if (((ICommunicationObject)callback).State == CommunicationState.Opened)
- {
- Console.WriteLine("Scan Started Callback");
- callback.ScanStartedCallback();
- }
- else
{
- Subscribers.Remove(callback);
- }
- });
+ if (((ICommunicationObject)callback).State == CommunicationState.Opened)
+ {
+ Console.WriteLine("Scan Started Callback");
+ callback.ScanStartedCallback();
+ }
+ else
+ {
+ Subscribers.Remove(callback);
+ }
+ });
}
/// <summary>
@@ -278,17 +341,99 @@ namespace HandBrake.ApplicationServices.Services
{
Subscribers.ForEach(
delegate(IHbServiceCallback callback)
- {
- if (((ICommunicationObject)callback).State == CommunicationState.Opened)
{
- Console.WriteLine("Scan Changed Callback");
- callback.ScanProgressCallback(e);
- }
- else
+ if (((ICommunicationObject)callback).State == CommunicationState.Opened)
+ {
+ Console.WriteLine("Scan Changed Callback");
+ callback.ScanProgressCallback(e);
+ }
+ else
+ {
+ Subscribers.Remove(callback);
+ }
+ });
+ }
+
+ /// <summary>
+ /// The encode service_ encode completed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void EncodeServiceEncodeCompleted(object sender, EncodeCompletedEventArgs e)
+ {
+ encodeService.EncodeCompleted -= this.EncodeServiceEncodeCompleted;
+ encodeService.EncodeStarted -= this.encodeService_EncodeStarted;
+ encodeService.EncodeStatusChanged -= this.encodeService_EncodeStatusChanged;
+
+ Subscribers.ForEach(
+ delegate(IHbServiceCallback callback)
{
- Subscribers.Remove(callback);
- }
- });
+ if (((ICommunicationObject)callback).State == CommunicationState.Opened)
+ {
+ Console.WriteLine("Encode Completed Callback");
+ callback.EncodeCompletedCallback(e);
+ }
+ else
+ {
+ Subscribers.Remove(callback);
+ }
+ });
+ }
+
+ /// <summary>
+ /// The encode service_ encode started.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void encodeService_EncodeStarted(object sender, EventArgs e)
+ {
+ Subscribers.ForEach(
+ delegate(IHbServiceCallback callback)
+ {
+ if (((ICommunicationObject)callback).State == CommunicationState.Opened)
+ {
+ Console.WriteLine("Encode Started Callback");
+ callback.EncodeStartedCallback();
+ }
+ else
+ {
+ Subscribers.Remove(callback);
+ }
+ });
+ }
+
+ /// <summary>
+ /// The encode service_ encode status changed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void encodeService_EncodeStatusChanged(object sender, EncodeProgressEventArgs e)
+ {
+ Subscribers.ForEach(
+ delegate(IHbServiceCallback callback)
+ {
+ if (((ICommunicationObject)callback).State == CommunicationState.Opened)
+ {
+ Console.WriteLine("Encode Status Callback");
+ callback.EncodeProgressCallback(e);
+ }
+ else
+ {
+ Subscribers.Remove(callback);
+ }
+ });
}
#endregion
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs
index 4b50eef1a..b28de2264 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs
@@ -19,6 +19,7 @@ namespace HandBrake.ApplicationServices.Utilities
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Model.Encoding;
+ using HandBrake.ApplicationServices.Services;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.Interop.Model.Encoding;
using HandBrake.Interop.Model.Encoding.x264;
@@ -31,7 +32,7 @@ namespace HandBrake.ApplicationServices.Utilities
/// <summary>
/// Backing field for the user settings service.
/// </summary>
- private static readonly IUserSettingService UserSettingService = IoC.Get<IUserSettingService>();
+ private static IUserSettingService UserSettingService;
/// <summary>
/// Generate a CLI Query for an EncodeTask Model object
@@ -44,6 +45,19 @@ namespace HandBrake.ApplicationServices.Utilities
/// </returns>
public static string GenerateQuery(EncodeTask task)
{
+ // TODO Remove this quick hack
+ if (UserSettingService == null)
+ {
+ try
+ {
+ UserSettingService = IoC.Get<IUserSettingService>();
+ }
+ catch (Exception exc)
+ {
+ UserSettingService = new UserSettingService();
+ }
+ }
+
string query = string.Empty;
query += SourceQuery(task, null, null);
query += DestinationQuery(task);
@@ -69,6 +83,19 @@ namespace HandBrake.ApplicationServices.Utilities
/// </returns>
public static string GeneratePreviewQuery(EncodeTask task, int duration, string startAtPreview)
{
+ // TODO Remove this quick hack
+ if (UserSettingService == null)
+ {
+ try
+ {
+ UserSettingService = IoC.Get<IUserSettingService>();
+ }
+ catch (Exception exc)
+ {
+ UserSettingService = new UserSettingService();
+ }
+ }
+
string query = string.Empty;
query += SourceQuery(task, duration, startAtPreview);
query += DestinationQuery(task);
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs
index e16274fe6..c13511580 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs
@@ -10,7 +10,6 @@
namespace HandBrake.ApplicationServices.Utilities
{
using System;
- using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
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