summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Services
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrakeWPF/Services')
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs6
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeCompletedEventArgs.cs34
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs40
-rw-r--r--win/CS/HandBrakeWPF/Services/Queue/Model/QueueStats.cs100
-rw-r--r--win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs5
-rw-r--r--win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs33
6 files changed, 179 insertions, 39 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs b/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
index 8f7dee945..b822b976d 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
@@ -131,7 +131,7 @@ namespace HandBrakeWPF.Services.Encode
/// <param name="configuration">
/// The configuration.
/// </param>
- public void ProcessLogs(string destination, bool isPreview, HBConfiguration configuration)
+ public string ProcessLogs(string destination, bool isPreview, HBConfiguration configuration)
{
try
{
@@ -162,11 +162,15 @@ namespace HandBrakeWPF.Services.Encode
{
this.WriteFile(logContent, Path.Combine(configuration.SaveLogCopyDirectory, encodeLogFile));
}
+
+ return encodeLogFile;
}
catch (Exception exc)
{
Debug.WriteLine(exc); // This exception doesn't warrent user interaction, but it should be logged
}
+
+ return null;
}
/// <summary>
diff --git a/win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeCompletedEventArgs.cs b/win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeCompletedEventArgs.cs
index ea334705d..1f2fe3bb0 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeCompletedEventArgs.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeCompletedEventArgs.cs
@@ -10,12 +10,10 @@
namespace HandBrakeWPF.Services.Encode.EventArgs
{
using System;
- using System.Runtime.Serialization;
/// <summary>
/// Encode Progress Event Args
/// </summary>
- [DataContract]
public class EncodeCompletedEventArgs : EventArgs
{
/// <summary>
@@ -33,36 +31,50 @@ namespace HandBrakeWPF.Services.Encode.EventArgs
/// <param name="filename">
/// The filename.
/// </param>
- public EncodeCompletedEventArgs(bool sucessful, Exception exception, string errorInformation, string filename)
+ /// <param name="logPath">
+ /// The path and filename of the log for this encode.
+ /// </param>
+ /// <param name="finalSizeInBytes">
+ /// The final size of the file in bytes.
+ /// </param>
+ public EncodeCompletedEventArgs(bool sucessful, Exception exception, string errorInformation, string filename, string logPath, long finalSizeInBytes)
{
this.Successful = sucessful;
this.Exception = exception;
this.ErrorInformation = errorInformation;
this.FileName = filename;
+ this.ActivityLogPath = logPath;
+ this.FinalFilesizeInBytes = finalSizeInBytes;
}
/// <summary>
/// Gets or sets the file name.
/// </summary>
- [DataMember]
- public string FileName { get; set; }
+ public string FileName { get; private set; }
/// <summary>
/// Gets or sets a value indicating whether Successful.
/// </summary>
- [DataMember]
- public bool Successful { get; set; }
+ public bool Successful { get; private set; }
/// <summary>
/// Gets or sets Exception.
/// </summary>
- [DataMember]
- public Exception Exception { get; set; }
+ public Exception Exception { get; private set; }
/// <summary>
/// Gets or sets ErrorInformation.
/// </summary>
- [DataMember]
- public string ErrorInformation { get; set; }
+ public string ErrorInformation { get; private set; }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public string ActivityLogPath { get; private set; }
+
+ /// <summary>
+ /// Final filesize in bytes
+ /// </summary>
+ public long FinalFilesizeInBytes { get; private set; }
}
}
diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
index 2ad5f0688..f8bd78fb7 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
@@ -11,6 +11,7 @@ namespace HandBrakeWPF.Services.Encode
{
using System;
using System.Diagnostics;
+ using System.IO;
using HandBrake.ApplicationServices.Interop;
using HandBrake.ApplicationServices.Interop.EventArgs;
@@ -21,15 +22,16 @@ namespace HandBrakeWPF.Services.Encode
using HandBrake.ApplicationServices.Services.Logging.Model;
using HandBrakeWPF.Exceptions;
+ using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Encode.Factories;
- using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
- using IEncode = HandBrakeWPF.Services.Encode.Interfaces.IEncode;
+ using EncodeTask = Model.EncodeTask;
+ using IEncode = Interfaces.IEncode;
/// <summary>
/// LibHB Implementation of IEncode
/// </summary>
- public class LibEncode : HandBrakeWPF.Services.Encode.EncodeBase, IEncode
+ public class LibEncode : EncodeBase, IEncode
{
#region Private Variables
@@ -63,7 +65,7 @@ namespace HandBrakeWPF.Services.Encode
// Sanity Checking and Setup
if (this.IsEncoding)
{
- throw new GeneralApplicationException("HandBrake is already encoding a file.", "Please stop the current encode. If the problem persists, please restart HandBrake.", null);
+ throw new GeneralApplicationException(Resources.Queue_AlreadyEncoding, Resources.Queue_AlreadyEncodingSolution, null);
}
// Setup
@@ -99,7 +101,7 @@ namespace HandBrakeWPF.Services.Encode
this.IsEncoding = false;
this.ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc);
- this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", task.Source));
+ this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", task.Source, null, 0));
}
}
@@ -203,14 +205,36 @@ namespace HandBrakeWPF.Services.Encode
this.ServiceLogMessage("Encode Completed ...");
// Handling Log Data
- this.ProcessLogs(this.currentTask.Destination, this.isPreviewInstance, this.currentConfiguration);
+ string hbLog = this.ProcessLogs(this.currentTask.Destination, this.isPreviewInstance, this.currentConfiguration);
+ long filesize = this.GetFilesize(this.currentTask.Destination);
// Raise the Encode Completed EVent.
this.InvokeEncodeCompleted(
e.Error
- ? new EventArgs.EncodeCompletedEventArgs(false, null, string.Empty, this.currentTask.Destination)
- : new EventArgs.EncodeCompletedEventArgs(true, null, string.Empty, this.currentTask.Destination));
+ ? new EventArgs.EncodeCompletedEventArgs(false, null, string.Empty, this.currentTask.Destination, hbLog, filesize)
+ : new EventArgs.EncodeCompletedEventArgs(true, null, string.Empty, this.currentTask.Destination, hbLog, filesize));
}
+
+ private long GetFilesize(string destination)
+ {
+ try
+ {
+ if (!string.IsNullOrEmpty(destination) && File.Exists(destination))
+ {
+ return new FileInfo(destination).Length;
+ }
+
+ return 0;
+ }
+ catch (Exception e)
+ {
+ this.ServiceLogMessage("Unable to get final filesize ..." + Environment.NewLine + e);
+ Debug.WriteLine(e);
+ }
+
+ return 0;
+ }
+
#endregion
}
}
diff --git a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueStats.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueStats.cs
new file mode 100644
index 000000000..857feb924
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueStats.cs
@@ -0,0 +1,100 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="QueueStats.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>
+// A file to record stats about a queue task.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services.Queue.Model
+{
+ using System;
+
+ using Caliburn.Micro;
+
+ public class QueueStats : PropertyChangedBase
+ {
+ private DateTime startTime;
+
+ private DateTime endTime;
+
+ private long? finalFileSize;
+
+ public QueueStats()
+ {
+ }
+
+ public DateTime StartTime
+ {
+ get
+ {
+ return this.startTime;
+ }
+ set
+ {
+ if (value.Equals(this.startTime)) return;
+ this.startTime = value;
+ this.NotifyOfPropertyChange(() => this.StartTime);
+ this.NotifyOfPropertyChange(() => this.Duration);
+ }
+ }
+
+ public DateTime EndTime
+ {
+ get
+ {
+ return this.endTime;
+ }
+ set
+ {
+ if (value.Equals(this.endTime)) return;
+ this.endTime = value;
+ this.NotifyOfPropertyChange(() => this.EndTime);
+ this.NotifyOfPropertyChange(() => this.Duration);
+ }
+ }
+
+ public TimeSpan Duration
+ {
+ get
+ {
+ // TODO, take into account Paused Duration. Requires some refactoring first.
+ return this.EndTime - this.StartTime;
+ }
+ }
+
+ /// <summary>
+ /// Final filesize in Bytes
+ /// </summary>
+ public long? FinalFileSize
+ {
+ get
+ {
+ return this.finalFileSize;
+ }
+ set
+ {
+ if (value == this.finalFileSize) return;
+ this.finalFileSize = value;
+ this.NotifyOfPropertyChange(() => this.FinalFileSize);
+ this.NotifyOfPropertyChange(() => this.FinalFileSizeInMegaBytes);
+ }
+ }
+
+ public long? FinalFileSizeInMegaBytes
+ {
+ get
+ {
+ if (this.finalFileSize.HasValue)
+ {
+ return this.finalFileSize / 1024 / 1024;
+ }
+
+ return 0;
+ }
+ }
+
+ public string CompletedActivityLogPath { get; set; }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs
index be3a8a4b9..334842d31 100644
--- a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs
+++ b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs
@@ -35,6 +35,7 @@ namespace HandBrakeWPF.Services.Queue.Model
this.Status = QueueItemStatus.Waiting;
id = id + 1;
this.Id = string.Format("{0}.{1}", GeneralUtilities.ProcessId, id);
+ this.Statistics = new QueueStats();
}
/// <summary>
@@ -58,6 +59,8 @@ namespace HandBrakeWPF.Services.Queue.Model
id = id + 1;
this.Id = string.Format("{0}.{1}", GeneralUtilities.ProcessId, id);
+
+ this.Statistics = new QueueStats();
}
public string Id { get; }
@@ -94,6 +97,8 @@ namespace HandBrakeWPF.Services.Queue.Model
/// </summary>
public HBConfiguration Configuration { get; set; }
+ public QueueStats Statistics { get; set; }
+
#endregion
protected bool Equals(QueueTask other)
diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
index 2292d18a2..c7aee8131 100644
--- a/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
+++ b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
@@ -48,7 +48,6 @@ namespace HandBrakeWPF.Services.Queue
/// </summary>
private static readonly object QueueLock = new object();
private readonly IUserSettingService userSettingService;
- private readonly IErrorService errorService;
private readonly BindingList<QueueTask> queue = new BindingList<QueueTask>();
private readonly string queueFile;
private bool clearCompleted;
@@ -72,10 +71,9 @@ namespace HandBrakeWPF.Services.Queue
/// <exception cref="ArgumentNullException">
/// Services are not setup
/// </exception>
- public QueueProcessor(IEncode encodeService, IUserSettingService userSettingService, IErrorService errorService)
+ public QueueProcessor(IEncode encodeService, IUserSettingService userSettingService)
{
this.userSettingService = userSettingService;
- this.errorService = errorService;
this.EncodeService = encodeService;
// If this is the first instance, just use the main queue file, otherwise add the instance id to the filename.
@@ -318,19 +316,9 @@ namespace HandBrakeWPF.Services.Queue
{
if (this.queue.Count > 0)
{
- QueueTask job = this.queue.FirstOrDefault(q => q.Status == QueueItemStatus.Waiting);
- if (job != null)
- {
- job.Status = QueueItemStatus.InProgress;
- this.LastProcessedJob = job;
- this.InvokeQueueChanged(EventArgs.Empty);
- }
-
- this.BackupQueue(string.Empty);
- return job;
+ return this.queue.FirstOrDefault(q => q.Status == QueueItemStatus.Waiting);
}
- this.BackupQueue(string.Empty);
return null;
}
@@ -399,7 +387,7 @@ namespace HandBrakeWPF.Services.Queue
if (job.Status != QueueItemStatus.Error && job.Status != QueueItemStatus.Completed)
{
throw new GeneralApplicationException(
- "Job Error", "Unable to reset job status as it is not in an Error or Completed state", null);
+ Resources.Error, Resources.Queue_UnableToResetJob, null);
}
job.Status = QueueItemStatus.Waiting;
@@ -437,10 +425,7 @@ namespace HandBrakeWPF.Services.Queue
}
catch (Exception exc)
{
- throw new GeneralApplicationException(
- "Unable to restore queue file.",
- "The file may be corrupted or from an older incompatible version of HandBrake",
- exc);
+ throw new GeneralApplicationException(Resources.Queue_UnableToRestoreFile, Resources.Queue_UnableToRestoreFileExtended, exc);
}
if (list != null)
@@ -544,6 +529,9 @@ namespace HandBrakeWPF.Services.Queue
private void EncodeServiceEncodeCompleted(object sender, EncodeCompletedEventArgs e)
{
this.LastProcessedJob.Status = QueueItemStatus.Completed;
+ this.LastProcessedJob.Statistics.EndTime = DateTime.Now;
+ this.LastProcessedJob.Statistics.CompletedActivityLogPath = e.ActivityLogPath;
+ this.LastProcessedJob.Statistics.FinalFileSize = e.FinalFilesizeInBytes;
// Clear the completed item of the queue if the setting is set.
if (this.clearCompleted)
@@ -638,10 +626,15 @@ namespace HandBrakeWPF.Services.Queue
LogService.GetLogger().LogMessage(Resources.PauseOnLowDiskspace, LogMessageType.ScanOrEncode, LogLevel.Info);
job.Status = QueueItemStatus.Waiting;
this.Pause();
+ this.BackupQueue(string.Empty);
return; // Don't start the next job.
}
+ job.Status = QueueItemStatus.InProgress;
+ job.Statistics.StartTime = DateTime.Now;
+ this.LastProcessedJob = job;
this.IsProcessing = true;
+ this.InvokeQueueChanged(EventArgs.Empty);
this.InvokeJobProcessingStarted(new QueueProgressEventArgs(job));
this.EncodeService.Start(job.Task, job.Configuration);
}
@@ -653,6 +646,8 @@ namespace HandBrakeWPF.Services.Queue
// Fire the event to tell connected services.
this.OnQueueCompleted(new QueueCompletedEventArgs(false));
}
+
+ this.BackupQueue(string.Empty);
}
#endregion