More refactoring and tracing added

This commit is contained in:
S T Chan 2013-12-19 21:40:17 -05:00
parent e8d202746a
commit bebd81eefa
4 changed files with 109 additions and 35 deletions

View File

@ -19,7 +19,9 @@ namespace PdfScribe
private Application activityWindow = null; private Application activityWindow = null;
/// <summary> /// <summary>
/// /// Displays the floating frameless
/// activity notification window on
/// a separate thread
/// </summary> /// </summary>
public void ShowActivityNotificationWindow() public void ShowActivityNotificationWindow()
{ {
@ -39,8 +41,8 @@ namespace PdfScribe
} }
/// <summary> /// <summary>
/// Shuts down the thread showing /// Shuts down the WPF Application showing
/// the ActivityNotification WPF window /// the ActivityNotification window
/// </summary> /// </summary>
public void CloseActivityNotificationWindow() public void CloseActivityNotificationWindow()
{ {

View File

@ -21,9 +21,9 @@ namespace PdfScribe
/// Ctor overload that shows the /// Ctor overload that shows the
/// task dialog immediately /// task dialog immediately
/// </summary> /// </summary>
/// <param name="captionText"></param> /// <param name="captionText">Text that goes in the window caption</param>
/// <param name="instructionText"></param> /// <param name="instructionText">Instructional text (Appears next to the icon)</param>
/// <param name="messageText"></param> /// <param name="messageText">Smaller message detail text at bottom</param>
public ErrorDialogPresenter(String captionText, public ErrorDialogPresenter(String captionText,
String instructionText, String instructionText,
String messageText) String messageText)
@ -38,9 +38,9 @@ namespace PdfScribe
/// with a standard error icon, and /// with a standard error icon, and
/// just a Close button /// just a Close button
/// </summary> /// </summary>
/// <param name="captionText"></param> /// <param name="captionText">Text that goes in the window caption</param>
/// <param name="instructionText"></param> /// <param name="instructionText">Instructional text (Appears next to the icon)</param>
/// <param name="messageText"></param> /// <param name="messageText">Smaller message detail text at bottom</param>
public void ShowSimple(String captionText, public void ShowSimple(String captionText,
String instructionText, String instructionText,
String messageText) String messageText)

View File

@ -14,8 +14,10 @@ namespace PdfScribe
{ {
#region Error messages #region Message constants
const string errorDialogCaption = "PDF Scribe"; // Error taskdialog caption text const string errorDialogCaption = "PDF Scribe"; // Error taskdialog caption text
const string errorDialogInstructionPDFGeneration = "There was a PDF generation error."; const string errorDialogInstructionPDFGeneration = "There was a PDF generation error.";
const string errorDialogInstructionCouldNotWrite = "Could not create the output file."; const string errorDialogInstructionCouldNotWrite = "Could not create the output file.";
const string errorDialogInstructionUnexpectedError = "There was an unexpected, and unhandled error in PDF Scribe."; const string errorDialogInstructionUnexpectedError = "There was an unexpected, and unhandled error in PDF Scribe.";
@ -23,6 +25,8 @@ namespace PdfScribe
const string errorDialogTextFileInUse = "{0} is being used by another process."; const string errorDialogTextFileInUse = "{0} is being used by another process.";
const string errorDialogTextGhostScriptConversion = "Ghostscript error code {0}."; const string errorDialogTextGhostScriptConversion = "Ghostscript error code {0}.";
const string warnFileNotDeleted = "{0} could not be deleted.";
#endregion #endregion
#region Other constants #region Other constants
@ -69,26 +73,41 @@ namespace PdfScribe
{ {
// We couldn't delete, or create a file // We couldn't delete, or create a file
// because it was in use // because it was in use
logEventSource.TraceEvent(TraceEventType.Error,
(int)TraceEventType.Error,
errorDialogInstructionCouldNotWrite +
Environment.NewLine +
"Exception message: " + ioEx.Message);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionCouldNotWrite, errorDialogInstructionCouldNotWrite,
String.Empty); String.Empty);
} }
catch (UnauthorizedAccessException) catch (UnauthorizedAccessException unauthorizedEx)
{ {
// Couldn't delete a file // Couldn't delete a file
// because it was set to readonly // because it was set to readonly
// or couldn't create a file // or couldn't create a file
// because of permissions issues // because of permissions issues
logEventSource.TraceEvent(TraceEventType.Error,
(int)TraceEventType.Error,
errorDialogInstructionCouldNotWrite +
Environment.NewLine +
"Exception message: " + unauthorizedEx.Message);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionCouldNotWrite, errorDialogInstructionCouldNotWrite,
String.Empty); String.Empty);
} }
catch (ExternalException ghostscriptEx) catch (ExternalException ghostscriptEx)
{ {
// Ghostscript error // Ghostscript error
logEventSource.TraceEvent(TraceEventType.Error,
(int)TraceEventType.Error,
String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString()) +
Environment.NewLine +
"Exception message: " + ghostscriptEx.Message);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionPDFGeneration, errorDialogInstructionPDFGeneration,
String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString())); String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString()));
} }
finally finally
@ -97,7 +116,12 @@ namespace PdfScribe
{ {
File.Delete(standardInputFilename); File.Delete(standardInputFilename);
} }
catch {} catch
{
logEventSource.TraceEvent(TraceEventType.Warning,
(int)TraceEventType.Warning,
String.Format(warnFileNotDeleted, standardInputFilename));
}
userDisplay.CloseActivityNotificationWindow(); userDisplay.CloseActivityNotificationWindow();
} }
} }
@ -109,9 +133,12 @@ namespace PdfScribe
/// <param name="e"></param> /// <param name="e"></param>
static void Application_UnhandledException(object sender, UnhandledExceptionEventArgs e) static void Application_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
logEventSource.TraceEvent(TraceEventType.Critical,
(int)TraceEventType.Critical,
((Exception)e.ExceptionObject).Message);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionUnexpectedError, errorDialogInstructionUnexpectedError,
String.Empty); String.Empty);
} }

View File

@ -70,6 +70,8 @@ namespace PdfScribeCore
const string FILENOTDELETED_INUSE = "{0} is being used by another process. File was not deleted."; const string FILENOTDELETED_INUSE = "{0} is being used by another process. File was not deleted.";
const string FILENOTDELETED_UNAUTHORIZED = "{0} is read-only, or its file permissions do not allow for deletion."; const string FILENOTDELETED_UNAUTHORIZED = "{0} is read-only, or its file permissions do not allow for deletion.";
const string FILENOTCOPIED_PRINTERDRIVER = "Printer driver file was not copied. Exception message: {0}";
const string WIN32ERROR = "Win32 error code {0}."; const string WIN32ERROR = "Win32 error code {0}.";
const string NATIVE_COULDNOTENABLE64REDIRECTION = "Could not enable 64-bit file system redirection."; const string NATIVE_COULDNOTENABLE64REDIRECTION = "Could not enable 64-bit file system redirection.";
@ -84,7 +86,11 @@ namespace PdfScribeCore
{ {
this.logEventSource = new TraceSource(logEventSourceNameDefault); this.logEventSource = new TraceSource(logEventSourceNameDefault);
} }
/// <summary>
/// This override sets the
/// trace source to a specific name
/// </summary>
/// <param name="eventSourceName">Trace source name</param>
public PdfScribeInstaller(String eventSourceName) public PdfScribeInstaller(String eventSourceName)
{ {
if (!String.IsNullOrEmpty(eventSourceName)) if (!String.IsNullOrEmpty(eventSourceName))
@ -124,7 +130,8 @@ namespace PdfScribeCore
/// <param name="portName"></param> /// <param name="portName"></param>
/// <param name="xcvDataOperation"></param> /// <param name="xcvDataOperation"></param>
/// <returns></returns> /// <returns></returns>
/// <remarks>I can't remember the name of the coder who wrote this code originally</remarks> /// <remarks>I can't remember the name of the developer who wrote this code originally,
/// so I can't provide a link or credit.</remarks>
private int DoXcvDataPortOperation(string portName, string portMonitor, string xcvDataOperation) private int DoXcvDataPortOperation(string portName, string portMonitor, string xcvDataOperation)
{ {
@ -205,10 +212,22 @@ namespace PdfScribeCore
newMonitor.pEnvironment = ENVIRONMENT_64; newMonitor.pEnvironment = ENVIRONMENT_64;
newMonitor.pDLLName = MONITORDLL; newMonitor.pDLLName = MONITORDLL;
if (!AddPortMonitor(newMonitor)) if (!AddPortMonitor(newMonitor))
throw new Win32Exception(Marshal.GetLastWin32Error(), String.Format("Could not add port monitor {0}", PORTMONITOR)); logEventSource.TraceEvent(TraceEventType.Error,
(int)TraceEventType.Error,
String.Format("Could not add port monitor {0}", PORTMONITOR) + Environment.NewLine +
String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString()));
else else
monitorAdded = true; monitorAdded = true;
} }
else
{
// Monitor already installed -
// log it, and keep going
logEventSource.TraceEvent(TraceEventType.Warning,
(int)TraceEventType.Warning,
String.Format("Port monitor {0} already installed.", PORTMONITOR));
monitorAdded = true;
}
} }
finally finally
@ -519,25 +538,51 @@ namespace PdfScribeCore
{ {
File.Copy(fileSourcePath, fileDestinationPath); File.Copy(fileSourcePath, fileDestinationPath);
} }
catch (PathTooLongException)
{
// Will be caught by outer
// IOException catch block
throw;
}
catch (DirectoryNotFoundException)
{
// Will be caught by outer
// IOException catch block
throw;
}
catch (FileNotFoundException)
{
// Will be caught by outer
// IOException catch block
throw;
}
catch (IOException) catch (IOException)
{ {
// Just keep going - file was already // Just keep going - file was already there
// there, but we didn't overwrite // Not really a problem
continue; continue;
} }
} }
filesCopied = true; filesCopied = true;
} }
catch (UnauthorizedAccessException) catch (IOException ioEx)
{ } {
catch (PathTooLongException) logEventSource.TraceEvent(TraceEventType.Error,
{ } (int)TraceEventType.Error,
catch (DirectoryNotFoundException) String.Format(FILENOTCOPIED_PRINTERDRIVER, ioEx.Message));
{ } }
catch (FileNotFoundException) catch (UnauthorizedAccessException unauthorizedEx)
{ } {
catch (NotSupportedException) logEventSource.TraceEvent(TraceEventType.Error,
{ } (int)TraceEventType.Error,
String.Format(FILENOTCOPIED_PRINTERDRIVER, unauthorizedEx.Message));
}
catch (NotSupportedException notSupportedEx)
{
logEventSource.TraceEvent(TraceEventType.Error,
(int)TraceEventType.Error,
String.Format(FILENOTCOPIED_PRINTERDRIVER, notSupportedEx.Message));
}
return filesCopied; return filesCopied;