{\r
return Process.GetProcessesByName("HandBrakeCLI");\r
}\r
-\r
- /// <summary>\r
- /// Show the Exception Window\r
- /// </summary>\r
- /// <param name="shortError">\r
- /// The short error.\r
- /// </param>\r
- /// <param name="longError">\r
- /// The long error.\r
- /// </param>\r
- public static void ShowExceptiowWindow(string shortError, string longError)\r
- {\r
- ExceptionWindow exceptionWindow = new ExceptionWindow();\r
- exceptionWindow.Setup(shortError, longError);\r
- exceptionWindow.Show();\r
- }\r
}\r
}
\ No newline at end of file
/// </summary>\r
public class Encode : IEncode\r
{\r
+\r
#region Private Variables\r
\r
/// <summary>\r
+ /// The Error Service\r
+ /// </summary>\r
+ protected IErrorService errorService;\r
+\r
+ /// <summary>\r
/// The Log Buffer\r
/// </summary>\r
private StringBuilder logBuffer;\r
{\r
this.EncodeStarted += Encode_EncodeStarted;\r
GrowlCommunicator.Register();\r
+\r
+ this.errorService = new ErrorService();\r
}\r
\r
#region Delegates and Event Handlers\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("It would appear that HandBrakeCLI has not started correctly." +\r
+ errorService.ShowError("It would appear that HandBrakeCLI has not started correctly." +\r
"You should take a look at the Activity log as it may indicate the reason why.\n\nDetailed Error Information: error occured in runCli()",\r
exc.ToString());\r
}\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("Unable to stop HandBrakeCLI. It may not be running.", exc.ToString());\r
+ errorService.ShowError("Unable to stop HandBrakeCLI. It may not be running.", exc.ToString());\r
}\r
\r
if (this.EncodeEnded != null)\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("Unable to make a copy of the log file", exc.ToString());\r
+ errorService.ShowError("Unable to make a copy of the log file", exc.ToString());\r
}\r
}\r
\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("Unable to close the log file wrtier", exc.ToString());\r
+ errorService.ShowError("Unable to close the log file wrtier", exc.ToString());\r
}\r
}\r
\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("Unable to read log file", exc.ToString());\r
+ errorService.ShowError("Unable to read log file", exc.ToString());\r
}\r
}\r
}\r
{\r
if (fileWriter != null)\r
fileWriter.Close();\r
- Main.ShowExceptiowWindow("Error", exc.ToString());\r
+ errorService.ShowError("Error", exc.ToString());\r
}\r
}\r
\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("Unable to write log data...", exc.ToString());\r
+ errorService.ShowError("Unable to write log data...", exc.ToString());\r
}\r
}\r
}\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("An Unknown Error has occured", exc.ToString());\r
+ errorService.ShowError("An Unknown Error has occured", exc.ToString());\r
}\r
}\r
\r
namespace HandBrake.ApplicationServices.Services\r
{\r
using System;\r
+ using System.IO;\r
+ using System.Threading;\r
+\r
using Interfaces;\r
using Views;\r
\r
/// </param>\r
public void ShowError(string shortError, string longError)\r
{\r
+ Thread newThread = new Thread(new ParameterizedThreadStart(WriteExceptionToFile));\r
+ newThread.Start(shortError + Environment.NewLine + longError);\r
+\r
ExceptionWindow window = new ExceptionWindow();\r
window.Setup(shortError, longError);\r
window.Show();\r
}\r
\r
/// <summary>\r
+ /// Write Exceptions out to log files\r
+ /// </summary>\r
+ /// <param name="state">\r
+ /// The state.\r
+ /// </param>\r
+ public void WriteExceptionToFile(object state)\r
+ {\r
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+ string file = Path.Combine(logDir, string.Format("Exception_{0}.txt", DateTime.Now.Ticks));\r
+\r
+ try\r
+ {\r
+ if (!File.Exists(file))\r
+ {\r
+ using (StreamWriter streamWriter = new StreamWriter(file))\r
+ {\r
+ streamWriter.WriteLine(state.ToString());\r
+ streamWriter.Close();\r
+ streamWriter.Dispose();\r
+ }\r
+ }\r
+ }\r
+ catch\r
+ {\r
+ return; // Game over. Stop digging.\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
/// Show a Notice or Warning Message.\r
/// </summary>\r
/// <param name="notice">\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", exc.ToString());\r
+ errorService.ShowError("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", exc.ToString());\r
}\r
}\r
return false;\r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("Unable to Start Queue", exc.ToString());\r
+ errorService.ShowError("Unable to Start Queue", exc.ToString());\r
}\r
}\r
}\r
/* Private Variables */\r
\r
/// <summary>\r
+ /// The Error Service\r
+ /// </summary>\r
+ private IErrorService errorService;\r
+\r
+ /// <summary>\r
/// A Lock object\r
/// </summary>\r
private static readonly object locker = new object();\r
/// </summary>\r
private Process hbProc;\r
\r
+ /// <summary>\r
+ /// Initializes a new instance of the <see cref="ScanService"/> class.\r
+ /// </summary>\r
+ public ScanService()\r
+ {\r
+ this.errorService = new ErrorService();\r
+ }\r
+\r
/* Event Handlers */\r
\r
/// <summary>\r
}\r
catch (Exception ex)\r
{\r
- Main.ShowExceptiowWindow("Unable to kill HandBrakeCLI.exe \n" +\r
+ errorService.ShowError("Unable to kill HandBrakeCLI.exe \n" +\r
"You may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically" + \r
" within the next few minutes. ", ex.ToString());\r
}\r
IsScanning = false;\r
\r
if (this.ScanCompleted != null)\r
- this.ScanCompleted(this, new EventArgs());\r
+ this.ScanCompleted(this, new EventArgs()); \r
}\r
catch (Exception exc)\r
{\r
- Main.ShowExceptiowWindow("frmMain.cs - scanProcess() Error", exc.ToString());\r
+ errorService.ShowError("frmMain.cs - scanProcess() Error", exc.ToString());\r
}\r
}\r
\r