From: sr55 Date: Sun, 12 Apr 2015 14:25:56 +0000 (+0000) Subject: WinGui: Some further refactoring of the services library. Moving all the queueing... X-Git-Tag: 1.0.0~1265 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca97a5f5239a29e87470509add1fd68099e35f2c;p=handbrake WinGui: Some further refactoring of the services library. Moving all the queueing functionality up to app layer for now. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7086 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index a8bb2a063..c3995689c 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -205,8 +205,6 @@ - - diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs index 3ba8a847f..227a73f5e 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs @@ -11,15 +11,14 @@ namespace HandBrake.ApplicationServices.Services.Encode { using System; using System.Diagnostics; - using System.Globalization; using System.IO; using System.Text; - using System.Text.RegularExpressions; using HandBrake.ApplicationServices.Exceptions; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.EventArgs; using HandBrake.ApplicationServices.Services.Encode.Interfaces; + using HandBrake.ApplicationServices.Services.Encode.Model; using HandBrake.ApplicationServices.Utilities; /// @@ -237,13 +236,7 @@ namespace HandBrake.ApplicationServices.Services.Encode /// /// Setup the logging. /// - /// - /// The encode QueueTask. - /// - /// - /// Indicates if this is libhb that is encoding or not. - /// - protected void SetupLogging(QueueTask encodeQueueTask, bool isLibhb) + protected void SetupLogging() { this.ShutdownFileWriter(); string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs"; @@ -369,12 +362,12 @@ namespace HandBrake.ApplicationServices.Services.Encode /// /// If the creation fails, an exception is thrown. /// - protected void VerifyEncodeDestinationPath(QueueTask task) + protected void VerifyEncodeDestinationPath(EncodeTask task) { // Make sure the path exists, attempt to create it if it doesn't try { - string path = Directory.GetParent(task.Task.Destination).ToString(); + string path = Directory.GetParent(task.Destination).ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs index e0685d4ad..60a5744ad 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs @@ -13,6 +13,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Interfaces using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.EventArgs; + using HandBrake.ApplicationServices.Services.Encode.Model; /// /// Encode Progess Status @@ -82,7 +83,10 @@ namespace HandBrake.ApplicationServices.Services.Encode.Interfaces /// /// The job. /// - void Start(QueueTask job); + /// + /// The configuration. + /// + void Start(EncodeTask job, HBConfiguration configuration); /// /// The pause. diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs index 0ae99b964..3c92f9a6f 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs @@ -15,10 +15,10 @@ namespace HandBrake.ApplicationServices.Services.Encode using HandBrake.ApplicationServices.Interop; using HandBrake.ApplicationServices.Interop.EventArgs; using HandBrake.ApplicationServices.Interop.Interfaces; - using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.Factories; using HandBrake.ApplicationServices.Services.Encode.Interfaces; + using HandBrake.ApplicationServices.Services.Encode.Model; /// /// LibHB Implementation of IEncode @@ -27,25 +27,11 @@ namespace HandBrake.ApplicationServices.Services.Encode { #region Private Variables - /// - /// Lock for the log file - /// private static readonly object LogLock = new object(); - - /// - /// The instance. - /// private IHandBrakeInstance instance; - - /// - /// The Start time of the current Encode; - /// private DateTime startTime; - - /// - /// The Current Task - /// - private QueueTask currentTask; + private EncodeTask currentTask; + private HBConfiguration currentConfiguration; #endregion @@ -57,22 +43,26 @@ namespace HandBrake.ApplicationServices.Services.Encode /// /// Start with a LibHb EncodeJob Object /// - /// - /// The job. + /// + /// The task. + /// + /// + /// The configuration. /// - public void Start(QueueTask job) + public void Start(EncodeTask task, HBConfiguration configuration) { try { // Setup this.startTime = DateTime.Now; - this.currentTask = job; + this.currentTask = task; + this.currentConfiguration = configuration; // Create a new HandBrake instance // Setup the HandBrake Instance HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged; HandBrakeUtils.ErrorLogged += this.HandBrakeInstanceErrorLogged; - this.instance = HandBrakeInstanceManager.GetEncodeInstance(job.Configuration.Verbosity); + this.instance = HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity); this.instance.EncodeCompleted += this.InstanceEncodeCompleted; this.instance.EncodeProgress += this.InstanceEncodeProgress; @@ -83,21 +73,21 @@ namespace HandBrake.ApplicationServices.Services.Encode } this.IsEncoding = true; - this.SetupLogging(job, true); + this.SetupLogging(); // Verify the Destination Path Exists, and if not, create it. - this.VerifyEncodeDestinationPath(job); + this.VerifyEncodeDestinationPath(task); ServiceLogMessage("Starting Encode ..."); // Get an EncodeJob object for the Interop Library - instance.StartEncode(EncodeFactory.Create(job.Task, job.Configuration)); + instance.StartEncode(EncodeFactory.Create(task, configuration)); // Fire the Encode Started Event this.InvokeEncodeStarted(System.EventArgs.Empty); // Set the Process Priority - switch (job.Configuration.ProcessPriority) + switch (configuration.ProcessPriority) { case "Realtime": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; @@ -124,7 +114,7 @@ namespace HandBrake.ApplicationServices.Services.Encode this.IsEncoding = false; ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc); - this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", job.Task.Source)); + this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", task.Source)); } } @@ -254,7 +244,7 @@ namespace HandBrake.ApplicationServices.Services.Encode HandBrakeUtils.ErrorLogged -= this.HandBrakeInstanceErrorLogged; // Handling Log Data - this.ProcessLogs(this.currentTask.Task.Destination, this.currentTask.Configuration); + this.ProcessLogs(this.currentTask.Destination, this.currentConfiguration); // Cleanup this.ShutdownFileWriter(); @@ -262,8 +252,8 @@ namespace HandBrake.ApplicationServices.Services.Encode // Raise the Encode Completed EVent. this.InvokeEncodeCompleted( e.Error - ? new EventArgs.EncodeCompletedEventArgs(false, null, string.Empty, this.currentTask.Task.Destination) - : new EventArgs.EncodeCompletedEventArgs(true, null, string.Empty, this.currentTask.Task.Destination)); + ? new EventArgs.EncodeCompletedEventArgs(false, null, string.Empty, this.currentTask.Destination) + : new EventArgs.EncodeCompletedEventArgs(true, null, string.Empty, this.currentTask.Destination)); } #endregion } diff --git a/win/CS/HandBrakeWPF/EventArgs/QueueProgressEventArgs.cs b/win/CS/HandBrakeWPF/EventArgs/QueueProgressEventArgs.cs index 3fa93fe7e..03155d0b5 100644 --- a/win/CS/HandBrakeWPF/EventArgs/QueueProgressEventArgs.cs +++ b/win/CS/HandBrakeWPF/EventArgs/QueueProgressEventArgs.cs @@ -13,6 +13,8 @@ namespace HandBrakeWPF.EventArgs using HandBrake.ApplicationServices.Model; + using HandBrakeWPF.Services.Queue.Model; + /// /// Queue Progress Event Args /// diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index f8e754663..e0d3979e2 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -154,7 +154,7 @@ - + @@ -164,7 +164,10 @@ - + + + + diff --git a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs index e73251b07..d2d9f1322 100644 --- a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs @@ -22,8 +22,9 @@ namespace HandBrakeWPF.Helpers using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Services.Queue.Model; - using IQueueProcessor = HandBrakeWPF.Services.Interfaces.IQueueProcessor; + using IQueueProcessor = HandBrakeWPF.Services.Queue.Interfaces.IQueueProcessor; /// /// Queue Recovery Helper diff --git a/win/CS/HandBrakeWPF/Services/NotificationService.cs b/win/CS/HandBrakeWPF/Services/NotificationService.cs index d85a63d42..33870fe14 100644 --- a/win/CS/HandBrakeWPF/Services/NotificationService.cs +++ b/win/CS/HandBrakeWPF/Services/NotificationService.cs @@ -14,7 +14,7 @@ namespace HandBrakeWPF.Services using HandBrakeWPF.Services.Interfaces; - using IQueueProcessor = HandBrakeWPF.Services.Interfaces.IQueueProcessor; + using IQueueProcessor = HandBrakeWPF.Services.Queue.Interfaces.IQueueProcessor; /// /// The Notification Service (Growl Connector) diff --git a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs index 5bb8ca0ad..45889207f 100644 --- a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs +++ b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs @@ -20,6 +20,7 @@ namespace HandBrakeWPF.Services using HandBrakeWPF.EventArgs; using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Services.Queue.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; using Execute = Caliburn.Micro.Execute; diff --git a/win/CS/HandBrakeWPF/Services/Interfaces/IQueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs similarity index 95% rename from win/CS/HandBrakeWPF/Services/Interfaces/IQueueProcessor.cs rename to win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs index b04c825d9..aaeb37708 100644 --- a/win/CS/HandBrakeWPF/Services/Interfaces/IQueueProcessor.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs @@ -7,14 +7,15 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace HandBrakeWPF.Services.Interfaces +namespace HandBrakeWPF.Services.Queue.Interfaces { using System; using System.ComponentModel; - using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.Interfaces; + using HandBrakeWPF.Services.Queue.Model; + /// /// The Queue Processor /// diff --git a/win/CS/HandBrake.ApplicationServices/Model/QueueItemStatus.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueItemStatus.cs similarity index 100% rename from win/CS/HandBrake.ApplicationServices/Model/QueueItemStatus.cs rename to win/CS/HandBrakeWPF/Services/Queue/Model/QueueItemStatus.cs diff --git a/win/CS/HandBrake.ApplicationServices/Model/QueueTask.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs similarity index 93% rename from win/CS/HandBrake.ApplicationServices/Model/QueueTask.cs rename to win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs index 42f55d02d..f11cb9b8d 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/QueueTask.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs @@ -7,9 +7,9 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace HandBrake.ApplicationServices.Model +namespace HandBrakeWPF.Services.Queue.Model { - + using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.Model; using HandBrake.ApplicationServices.Utilities; @@ -131,7 +131,7 @@ namespace HandBrake.ApplicationServices.Model return false; } - return Equals((QueueTask)obj); + return this.Equals((QueueTask)obj); } /// diff --git a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTaskContainer.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTaskContainer.cs new file mode 100644 index 000000000..0509cd088 --- /dev/null +++ b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTaskContainer.cs @@ -0,0 +1,42 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The queue task container. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Services.Queue.Model +{ + /// + /// The queue task container. + /// + public class QueueTaskContainer + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The version. + /// + /// + /// The queuetask. + /// + public QueueTaskContainer(int version, string queuetask) + { + Version = version; + QueueTask = queuetask; + } + + /// + /// Gets or sets the version of the presets stored in this container. + /// + public int Version { get; set; } + + /// + /// Gets or sets the presets. This is a serialised string. + /// + public string QueueTask { get; set; } + } +} diff --git a/win/CS/HandBrakeWPF/Services/QueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs similarity index 95% rename from win/CS/HandBrakeWPF/Services/QueueProcessor.cs rename to win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs index 0507f7307..797d74e08 100644 --- a/win/CS/HandBrakeWPF/Services/QueueProcessor.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs @@ -7,7 +7,7 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace HandBrakeWPF.Services +namespace HandBrakeWPF.Services.Queue { using System; using System.Collections.Generic; @@ -16,23 +16,23 @@ namespace HandBrakeWPF.Services using System.Linq; using System.Xml.Serialization; - using Caliburn.Micro; - using HandBrake.ApplicationServices.Exceptions; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.EventArgs; using HandBrake.ApplicationServices.Services.Encode.Interfaces; using HandBrake.ApplicationServices.Utilities; + using HandBrakeWPF.Services.Queue.Model; + using Execute = Caliburn.Micro.Execute; - using IQueueProcessor = HandBrakeWPF.Services.Interfaces.IQueueProcessor; + using IQueueProcessor = HandBrakeWPF.Services.Queue.Interfaces.IQueueProcessor; using QueueCompletedEventArgs = HandBrakeWPF.EventArgs.QueueCompletedEventArgs; using QueueProgressEventArgs = HandBrakeWPF.EventArgs.QueueProgressEventArgs; /// /// The HandBrake Queue /// - public class QueueProcessor : IQueueProcessor + public class QueueProcessor : Interfaces.IQueueProcessor { #region Constants and Fields @@ -588,7 +588,7 @@ namespace HandBrakeWPF.Services if (job != null) { this.InvokeJobProcessingStarted(new QueueProgressEventArgs(job)); - this.EncodeService.Start(job); + this.EncodeService.Start(job.Task, job.Configuration); } else { diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs index e51dc1707..0fd29950e 100644 --- a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs +++ b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs @@ -36,6 +36,8 @@ namespace HandBrakeWPF.Startup using HandBrakeWPF.Services; using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Services.Queue; + using HandBrakeWPF.Services.Queue.Interfaces; /// /// The Castle Bootstrapper diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 4c9921459..2ba9744f6 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -44,6 +44,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Services.Presets.Factories; using HandBrakeWPF.Services.Presets.Interfaces; using HandBrakeWPF.Services.Presets.Model; + using HandBrakeWPF.Services.Queue.Model; using HandBrakeWPF.Utilities; using HandBrakeWPF.ViewModels.Interfaces; using HandBrakeWPF.Views; @@ -53,7 +54,7 @@ namespace HandBrakeWPF.ViewModels using Ookii.Dialogs.Wpf; using Execute = Caliburn.Micro.Execute; - using IQueueProcessor = HandBrakeWPF.Services.Interfaces.IQueueProcessor; + using IQueueProcessor = HandBrakeWPF.Services.Queue.Interfaces.IQueueProcessor; /// /// HandBrakes Main Window diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs index 7191ad9b5..52c51419b 100644 --- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs @@ -22,6 +22,8 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.EventArgs; using HandBrakeWPF.Properties; using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Services.Queue.Interfaces; + using HandBrakeWPF.Services.Queue.Model; using HandBrakeWPF.ViewModels.Interfaces; using Microsoft.Win32; diff --git a/win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs index 4d505b83d..11a9d8715 100644 --- a/win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs @@ -18,7 +18,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; - using IQueueProcessor = HandBrakeWPF.Services.Interfaces.IQueueProcessor; + using IQueueProcessor = HandBrakeWPF.Services.Queue.Interfaces.IQueueProcessor; /// /// The Shell View Model diff --git a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs index 3a3b4e6eb..7e6cc2525 100644 --- a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs @@ -33,6 +33,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Properties; using HandBrakeWPF.Services; using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Services.Queue.Model; using HandBrakeWPF.ViewModels.Interfaces; /// @@ -638,7 +639,7 @@ namespace HandBrakeWPF.ViewModels this.encodeService.EncodeCompleted += this.encodeService_EncodeCompleted; this.encodeService.EncodeStatusChanged += this.encodeService_EncodeStatusChanged; - this.encodeService.Start((QueueTask)state); + this.encodeService.Start(((QueueTask)state).Task, ((QueueTask)state).Configuration); this.userSettingService.SetUserSetting(UserSettingConstants.LastPreviewDuration, this.Duration); } #endregion