More refactoring and tracing added
This commit is contained in:
parent
e8d202746a
commit
bebd81eefa
@ -19,7 +19,9 @@ namespace PdfScribe
|
||||
private Application activityWindow = null;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Displays the floating frameless
|
||||
/// activity notification window on
|
||||
/// a separate thread
|
||||
/// </summary>
|
||||
public void ShowActivityNotificationWindow()
|
||||
{
|
||||
@ -39,8 +41,8 @@ namespace PdfScribe
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the thread showing
|
||||
/// the ActivityNotification WPF window
|
||||
/// Shuts down the WPF Application showing
|
||||
/// the ActivityNotification window
|
||||
/// </summary>
|
||||
public void CloseActivityNotificationWindow()
|
||||
{
|
||||
|
@ -21,9 +21,9 @@ namespace PdfScribe
|
||||
/// Ctor overload that shows the
|
||||
/// task dialog immediately
|
||||
/// </summary>
|
||||
/// <param name="captionText"></param>
|
||||
/// <param name="instructionText"></param>
|
||||
/// <param name="messageText"></param>
|
||||
/// <param name="captionText">Text that goes in the window caption</param>
|
||||
/// <param name="instructionText">Instructional text (Appears next to the icon)</param>
|
||||
/// <param name="messageText">Smaller message detail text at bottom</param>
|
||||
public ErrorDialogPresenter(String captionText,
|
||||
String instructionText,
|
||||
String messageText)
|
||||
@ -38,9 +38,9 @@ namespace PdfScribe
|
||||
/// with a standard error icon, and
|
||||
/// just a Close button
|
||||
/// </summary>
|
||||
/// <param name="captionText"></param>
|
||||
/// <param name="instructionText"></param>
|
||||
/// <param name="messageText"></param>
|
||||
/// <param name="captionText">Text that goes in the window caption</param>
|
||||
/// <param name="instructionText">Instructional text (Appears next to the icon)</param>
|
||||
/// <param name="messageText">Smaller message detail text at bottom</param>
|
||||
public void ShowSimple(String captionText,
|
||||
String instructionText,
|
||||
String messageText)
|
||||
|
@ -14,8 +14,10 @@ namespace PdfScribe
|
||||
{
|
||||
|
||||
|
||||
#region Error messages
|
||||
#region Message constants
|
||||
|
||||
const string errorDialogCaption = "PDF Scribe"; // Error taskdialog caption text
|
||||
|
||||
const string errorDialogInstructionPDFGeneration = "There was a PDF generation error.";
|
||||
const string errorDialogInstructionCouldNotWrite = "Could not create the output file.";
|
||||
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 errorDialogTextGhostScriptConversion = "Ghostscript error code {0}.";
|
||||
|
||||
const string warnFileNotDeleted = "{0} could not be deleted.";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Other constants
|
||||
@ -69,26 +73,41 @@ namespace PdfScribe
|
||||
{
|
||||
// We couldn't delete, or create a file
|
||||
// because it was in use
|
||||
logEventSource.TraceEvent(TraceEventType.Error,
|
||||
(int)TraceEventType.Error,
|
||||
errorDialogInstructionCouldNotWrite +
|
||||
Environment.NewLine +
|
||||
"Exception message: " + ioEx.Message);
|
||||
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
|
||||
errorDialogInstructionCouldNotWrite,
|
||||
String.Empty);
|
||||
errorDialogInstructionCouldNotWrite,
|
||||
String.Empty);
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
catch (UnauthorizedAccessException unauthorizedEx)
|
||||
{
|
||||
// Couldn't delete a file
|
||||
// because it was set to readonly
|
||||
// or couldn't create a file
|
||||
// because of permissions issues
|
||||
logEventSource.TraceEvent(TraceEventType.Error,
|
||||
(int)TraceEventType.Error,
|
||||
errorDialogInstructionCouldNotWrite +
|
||||
Environment.NewLine +
|
||||
"Exception message: " + unauthorizedEx.Message);
|
||||
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
|
||||
errorDialogInstructionCouldNotWrite,
|
||||
String.Empty);
|
||||
errorDialogInstructionCouldNotWrite,
|
||||
String.Empty);
|
||||
}
|
||||
catch (ExternalException ghostscriptEx)
|
||||
{
|
||||
// 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,
|
||||
errorDialogInstructionPDFGeneration,
|
||||
String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString()));
|
||||
errorDialogInstructionPDFGeneration,
|
||||
String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString()));
|
||||
|
||||
}
|
||||
finally
|
||||
@ -97,7 +116,12 @@ namespace PdfScribe
|
||||
{
|
||||
File.Delete(standardInputFilename);
|
||||
}
|
||||
catch {}
|
||||
catch
|
||||
{
|
||||
logEventSource.TraceEvent(TraceEventType.Warning,
|
||||
(int)TraceEventType.Warning,
|
||||
String.Format(warnFileNotDeleted, standardInputFilename));
|
||||
}
|
||||
userDisplay.CloseActivityNotificationWindow();
|
||||
}
|
||||
}
|
||||
@ -109,9 +133,12 @@ namespace PdfScribe
|
||||
/// <param name="e"></param>
|
||||
static void Application_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
logEventSource.TraceEvent(TraceEventType.Critical,
|
||||
(int)TraceEventType.Critical,
|
||||
((Exception)e.ExceptionObject).Message);
|
||||
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
|
||||
errorDialogInstructionUnexpectedError,
|
||||
String.Empty);
|
||||
errorDialogInstructionUnexpectedError,
|
||||
String.Empty);
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,6 +70,8 @@ namespace PdfScribeCore
|
||||
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 FILENOTCOPIED_PRINTERDRIVER = "Printer driver file was not copied. Exception message: {0}";
|
||||
|
||||
const string WIN32ERROR = "Win32 error code {0}.";
|
||||
|
||||
const string NATIVE_COULDNOTENABLE64REDIRECTION = "Could not enable 64-bit file system redirection.";
|
||||
@ -84,7 +86,11 @@ namespace PdfScribeCore
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(eventSourceName))
|
||||
@ -124,7 +130,8 @@ namespace PdfScribeCore
|
||||
/// <param name="portName"></param>
|
||||
/// <param name="xcvDataOperation"></param>
|
||||
/// <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)
|
||||
{
|
||||
|
||||
@ -205,10 +212,22 @@ namespace PdfScribeCore
|
||||
newMonitor.pEnvironment = ENVIRONMENT_64;
|
||||
newMonitor.pDLLName = MONITORDLL;
|
||||
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
|
||||
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
|
||||
@ -519,25 +538,51 @@ namespace PdfScribeCore
|
||||
{
|
||||
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)
|
||||
{
|
||||
// Just keep going - file was already
|
||||
// there, but we didn't overwrite
|
||||
// Just keep going - file was already there
|
||||
// Not really a problem
|
||||
continue;
|
||||
}
|
||||
}
|
||||
filesCopied = true;
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{ }
|
||||
catch (PathTooLongException)
|
||||
{ }
|
||||
catch (DirectoryNotFoundException)
|
||||
{ }
|
||||
catch (FileNotFoundException)
|
||||
{ }
|
||||
catch (NotSupportedException)
|
||||
{ }
|
||||
catch (IOException ioEx)
|
||||
{
|
||||
logEventSource.TraceEvent(TraceEventType.Error,
|
||||
(int)TraceEventType.Error,
|
||||
String.Format(FILENOTCOPIED_PRINTERDRIVER, ioEx.Message));
|
||||
}
|
||||
catch (UnauthorizedAccessException unauthorizedEx)
|
||||
{
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user