From cbe5f09e69c95df3be3b38de06c2b7bd6b5bd949 Mon Sep 17 00:00:00 2001 From: sr55 Date: Wed, 22 Aug 2012 20:11:18 +0000 Subject: WinGui: Initial Work to wire up Encode Process Isolation. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4914 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Services/Base/EncodeBase.cs | 28 ++- .../Services/Encode.cs | 13 +- .../Services/Interfaces/IHbServiceCallback.cs | 24 ++ .../Services/Interfaces/IQueueProcessor.cs | 9 + .../Services/Interfaces/IServerService.cs | 52 +++- .../Services/LibEncode.cs | 10 +- .../Services/QueueProcessor.cs | 13 +- .../Services/ServerService.cs | 267 ++++++++++++++++----- 8 files changed, 331 insertions(+), 85 deletions(-) (limited to 'win/CS/HandBrake.ApplicationServices/Services') 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 /// /// A Lock for the filewriter /// - private static readonly object fileWriterLock = new object(); + private static readonly object FileWriterLock = new object(); /// /// The User Setting Service /// - private IUserSettingService userSettingService = IoC.Get(); + private readonly IUserSettingService userSettingService; /// /// Windows 7 API Pack wrapper /// - private Win7 windowsSeven = new Win7(); + private readonly Win7 windowsSeven = new Win7(); + + /// + /// The Log File Header + /// + private readonly StringBuilder header = GeneralUtilities.CreateCliLogHeader(); /// /// The Log Buffer @@ -53,18 +56,17 @@ namespace HandBrake.ApplicationServices.Services.Base /// private StreamWriter fileWriter; - /// - /// The Log File Header - /// - private StringBuilder header = GeneralUtilities.CreateCliLogHeader(); - #endregion /// /// Initializes a new instance of the class. /// - public EncodeBase() + /// + /// The user Setting Service. + /// + 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 /// /// The User Setting Service /// - private IUserSettingService userSettingService = IoC.Get(); + private readonly IUserSettingService userSettingService; /// /// Gets The Process Handle @@ -62,8 +60,13 @@ namespace HandBrake.ApplicationServices.Services /// /// Initializes a new instance of the class. /// - public Encode() + /// + /// The user Setting Service. + /// + 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(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 /// [OperationContract(IsOneWay = true)] void ScanStartedCallback(); + + /// + /// The encode progress callback. + /// + /// + /// The event Args. + /// + [OperationContract(IsOneWay = true)] + void EncodeProgressCallback(EncodeProgressEventArgs eventArgs); + + /// + /// The encode completed callback. + /// + /// + /// The event Args. + /// + [OperationContract(IsOneWay = true)] + void EncodeCompletedCallback(EncodeCompletedEventArgs eventArgs); + + /// + /// The encode started callback. + /// + [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. /// void Pause(); + + /// + /// Swap encode service. + /// Temp method until Castle is hooked up. + /// + /// + /// The service. + /// + 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; /// @@ -24,7 +25,13 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// Gets the activity log. /// [DataMember] - string ActivityLog { get; } + string ScanActivityLog { get; } + + /// + /// Gets the activity log. + /// + [DataMember] + string EncodeActivityLog { get; } /// /// Gets the souce data. @@ -38,8 +45,20 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// /// Gets a value indicating whether is scanning. /// - [DataMember] - bool IsScanning { get; } + bool IsScanning + { + [OperationContract] + get; + } + + /// + /// Gets a value indicating whether is encoding. + /// + bool IsEncoding + { + [OperationContract] + get; + } /// /// Start the WCF Service @@ -66,6 +85,33 @@ namespace HandBrake.ApplicationServices.Services.Interfaces [OperationContract] void ScanSource(string path, int title, int previewCount); + /// + /// Start and Encode + /// + /// + /// The job. + /// + /// + /// The enable logging. + /// + [OperationContract] + void StartEncode(QueueTask job, bool enableLogging); + + /// + /// The process encode logs. + /// + /// + /// The destination. + /// + [OperationContract] + void ProcessEncodeLogs(string destination); + + /// + /// Stop and Encode + /// + [OperationContract] + void StopEncode(); + /// /// Stop the scan. /// 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 /// /// The User Setting Service /// - private IUserSettingService userSettingService = IoC.Get(); + private readonly IUserSettingService userSettingService; /// /// The Start time of the current Encode; @@ -62,8 +62,14 @@ namespace HandBrake.ApplicationServices.Services /// /// Initializes a new instance of the class. /// - public LibEncode() + /// + /// The user Setting Service. + /// + public LibEncode(IUserSettingService userSettingService) + : base(userSettingService) { + this.userSettingService = userSettingService; + // Setup the HandBrake Instance this.instance = IoC.Get(); 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; @@ -180,6 +179,18 @@ namespace HandBrake.ApplicationServices.Services this.IsProcessing = false; } + /// + /// Swap encode service. + /// Temp method until Castle is hooked up. + /// + /// + /// The service. + /// + public void SwapEncodeService(IEncode service) + { + this.EncodeService = service; + } + /// /// After an encode is complete, move onto the next job. /// 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; /// /// HandBrake WCF Service /// - [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 @@ -32,6 +34,11 @@ namespace HandBrake.ApplicationServices.Services /// private static readonly List Subscribers = new List(); + /// + /// The encode service. + /// + private static IEncode encodeService; + /// /// The scan service. /// @@ -44,45 +51,47 @@ namespace HandBrake.ApplicationServices.Services #endregion - #region Implemented Interfaces - - #region IServerService + #region Properties /// - /// The scan source. + /// Gets the activity log. /// - /// - /// The path. - /// - /// - /// The title. - /// - /// - /// The preview Count. - /// - 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; + } } /// /// Gets the activity log. /// + public string EncodeActivityLog { get; private set; } + + /// + /// Gets a value indicating whether is encoding. + /// + public bool IsEncoding { get; private set; } + + /// + /// Gets a value indicating whether is scanning. + /// [DataMember] - public string ActivityLog + public bool IsScanning { get { - return scanService.ActivityLog; - + return scanService.IsScanning; } } + /// + /// Gets the activity log. + /// + public string ScanActivityLog { get; private set; } + /// /// Gets the souce data. /// @@ -95,16 +104,43 @@ namespace HandBrake.ApplicationServices.Services } } + #endregion + + #region Implemented Interfaces + + #region IServerService + /// - /// Gets a value indicating whether is scanning. + /// The process encode logs. /// - [DataMember] - public bool IsScanning + /// + /// The destination. + /// + public void ProcessEncodeLogs(string destination) { - get - { - return scanService.IsScanning; - } + encodeService.ProcessLogs(destination); + } + + /// + /// The scan source. + /// + /// + /// The path. + /// + /// + /// The title. + /// + /// + /// The preview Count. + /// + 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); } /// @@ -121,11 +157,30 @@ 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(); } } + /// + /// Start and Encode + /// + /// + /// The job. + /// + /// + /// The enable logging. + /// + 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); + } + /// /// Stop this service /// @@ -138,6 +193,14 @@ namespace HandBrake.ApplicationServices.Services } } + /// + /// Stop and Encode + /// + public void StopEncode() + { + encodeService.Stop(); + } + /// /// Stop the scan. /// @@ -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); + } + }); } /// @@ -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); + } + }); + } + + /// + /// The encode service_ encode completed. + /// + /// + /// The sender. + /// + /// + /// The e. + /// + 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); + } + }); + } + + /// + /// The encode service_ encode started. + /// + /// + /// The sender. + /// + /// + /// The e. + /// + 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); + } + }); + } + + /// + /// The encode service_ encode status changed. + /// + /// + /// The sender. + /// + /// + /// The e. + /// + 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 -- cgit v1.2.3