summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices
diff options
context:
space:
mode:
authorsr55 <[email protected]>2011-05-14 14:46:16 +0000
committersr55 <[email protected]>2011-05-14 14:46:16 +0000
commit407aa2324adb84d97a61ddefde22178dff5c6063 (patch)
tree40ab418a4016065d5fc829f2935a690f6d5b3bac /win/CS/HandBrake.ApplicationServices
parente710acff9681ba85b7bddf65d001bc0444d4a69d (diff)
WinGui:
- Removed the Question Alert box when adding an item to the queue where the destination folder does not exist. The folder is automatically created before encode anyway, so no point in asking the user pre-Encode.cs - Better error handling in the encode service. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3979 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Exceptions/GeneralApplicationException.cs49
-rw-r--r--win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj1
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode.cs52
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs12
-rw-r--r--win/CS/HandBrake.ApplicationServices/Settings.StyleCop19
5 files changed, 106 insertions, 27 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Exceptions/GeneralApplicationException.cs b/win/CS/HandBrake.ApplicationServices/Exceptions/GeneralApplicationException.cs
new file mode 100644
index 000000000..1ee6608ba
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Exceptions/GeneralApplicationException.cs
@@ -0,0 +1,49 @@
+/* GeneralApplicationException.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr/>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Exceptions
+{
+ using System;
+
+ /// <summary>
+ /// The Encode Failure Exception
+ /// </summary>
+ public class GeneralApplicationException : Exception
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="GeneralApplicationException"/> class.
+ /// </summary>
+ /// <param name="error">
+ /// The error.
+ /// </param>
+ /// <param name="solution">
+ /// The solution.
+ /// </param>
+ /// <param name="innerException">
+ /// The inner Exception.
+ /// </param>
+ public GeneralApplicationException(string error, string solution, Exception innerException)
+ {
+ this.Error = error;
+ this.Solution = solution;
+ this.ActualException = innerException;
+ }
+
+ /// <summary>
+ /// Gets or sets FailureReason.
+ /// </summary>
+ public string Error { get; set; }
+
+ /// <summary>
+ /// Gets or sets Solution.
+ /// </summary>
+ public string Solution { get; set; }
+
+ /// <summary>
+ /// Gets or sets InnerException.
+ /// </summary>
+ public Exception ActualException { get; set; }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
index dd44f6d9c..f6a0122d9 100644
--- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
+++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
@@ -84,6 +84,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\EnumToDescConverter.cs" />
+ <Compile Include="Exceptions\GeneralApplicationException.cs" />
<Compile Include="EventArgs\EncodeCompletedEventArgs.cs" />
<Compile Include="EventArgs\EncodeProgressEventArgs.cs" />
<Compile Include="EventArgs\QueueProgressEventArgs.cs" />
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
index 5787ab8a8..468f4597a 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
@@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Services
using System.Windows.Forms;
using HandBrake.ApplicationServices.EventArgs;
+ using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
@@ -95,6 +96,12 @@ namespace HandBrake.ApplicationServices.Services
/// Encode process has progressed
/// </summary>
public event EncodeProgessStatus EncodeStatusChanged;
+
+ /// <summary>
+ /// An event for a failed encode.
+ /// </summary>
+ public event EventHandler EncodeFailed;
+
#endregion
#region Properties
@@ -139,27 +146,22 @@ namespace HandBrake.ApplicationServices.Services
{
QueueTask queueTask = encodeQueueTask;
- if (queueTask == null)
- {
- throw new ArgumentNullException("QueueTask was null");
- }
-
- if (IsEncoding)
+ if (this.IsEncoding)
{
throw new Exception("HandBrake is already encodeing.");
}
- IsEncoding = true;
+ this.IsEncoding = true;
if (enableLogging)
{
try
{
- SetupLogging(queueTask);
+ this.SetupLogging(queueTask);
}
catch (Exception)
{
- IsEncoding = false;
+ this.IsEncoding = false;
throw;
}
}
@@ -173,8 +175,15 @@ namespace HandBrake.ApplicationServices.Services
string path = Directory.GetParent(queueTask.Destination).ToString();
if (!Directory.Exists(path))
{
- // TODO - Better handle a directoryNotFound exception.
- Directory.CreateDirectory(path);
+ try
+ {
+ Directory.CreateDirectory(path);
+ }
+ catch (Exception)
+ {
+ throw new Exception(
+ "Unable to create directory for the encoded output. Please verify the drive and path is correct.");
+ }
}
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
@@ -194,12 +203,12 @@ namespace HandBrake.ApplicationServices.Services
if (enableLogging)
{
- this.HbProcess.ErrorDataReceived += HbProcErrorDataReceived;
+ this.HbProcess.ErrorDataReceived += this.HbProcErrorDataReceived;
this.HbProcess.BeginErrorReadLine();
}
- this.processId = HbProcess.Id;
- this.processHandle = HbProcess.Handle;
+ this.processId = this.HbProcess.Id;
+ this.processHandle = this.HbProcess.Handle;
// Set the process Priority
if (this.processId != -1)
@@ -233,12 +242,16 @@ namespace HandBrake.ApplicationServices.Services
// Fire the Encode Started Event
if (this.EncodeStarted != null)
+ {
this.EncodeStarted(this, new EventArgs());
+ }
}
catch (Exception exc)
{
if (this.EncodeCompleted != null)
- this.EncodeCompleted(this, new EncodeCompletedEventArgs(false, exc, "An Error has occured in EncodeService.Run()"));
+ {
+ this.EncodeCompleted(this, new EncodeCompletedEventArgs(false, exc, "An Error occured when trying to encode this source. "));
+ }
}
}
@@ -275,12 +288,19 @@ namespace HandBrake.ApplicationServices.Services
if (exc == null)
{
if (this.EncodeCompleted != null)
+ {
this.EncodeCompleted(this, new EncodeCompletedEventArgs(true, null, string.Empty));
+ }
}
else
{
if (this.EncodeCompleted != null)
- this.EncodeCompleted(this, new EncodeCompletedEventArgs(false, exc, "An Error has occured."));
+ {
+ this.EncodeCompleted(
+ this,
+ new EncodeCompletedEventArgs(
+ false, exc, "An Unknown Error has occured when trying to Stop this encode."));
+ }
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
index f2ca04c6d..fe3eb8549 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
@@ -10,6 +10,7 @@ namespace HandBrake.ApplicationServices.Services
using System.Windows.Forms;
using HandBrake.ApplicationServices.EventArgs;
+ using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Services.Interfaces;
@@ -200,15 +201,18 @@ namespace HandBrake.ApplicationServices.Services
if (!e.Successful)
{
this.Pause();
- MessageBox.Show(e.Exception + e.ErrorInformation);
+ throw new GeneralApplicationException(e.ErrorInformation, e.Exception.Message, e.Exception);
}
- // Post-Processing
- SendToApplication(this.QueueManager.LastProcessedJob.Destination);
-
// Handling Log Data
this.EncodeService.ProcessLogs(this.QueueManager.LastProcessedJob.Destination);
+ // Post-Processing
+ if (e.Successful)
+ {
+ SendToApplication(this.QueueManager.LastProcessedJob.Destination);
+ }
+
// Move onto the next job.
this.ProcessNextJob();
}
diff --git a/win/CS/HandBrake.ApplicationServices/Settings.StyleCop b/win/CS/HandBrake.ApplicationServices/Settings.StyleCop
index c8383e569..5d3a523a0 100644
--- a/win/CS/HandBrake.ApplicationServices/Settings.StyleCop
+++ b/win/CS/HandBrake.ApplicationServices/Settings.StyleCop
@@ -1,9 +1,14 @@
<StyleCopSettings Version="105">
- <Parsers>
- <Parser ParserId="StyleCop.CSharp.CsParser">
- <ParserSettings>
- <BooleanProperty Name="AnalyzeDesignerFiles">False</BooleanProperty>
- </ParserSettings>
- </Parser>
- </Parsers>
+ <Analyzers>
+ <Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
+ <Rules>
+ <Rule Name="FileHeaderFileNameDocumentationMustMatchTypeName">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ </Analyzers>
</StyleCopSettings> \ No newline at end of file