diff --git a/PdfScribeInstallCustomAction/CustomAction.cs b/PdfScribeInstallCustomAction/CustomAction.cs index 469ce29..2b73c22 100644 --- a/PdfScribeInstallCustomAction/CustomAction.cs +++ b/PdfScribeInstallCustomAction/CustomAction.cs @@ -17,19 +17,26 @@ namespace PdfScribeInstallCustomAction public class CustomActions { - static readonly String traceSourceName = "PdfScribeInstaller"; [CustomAction] public static ActionResult CheckIfPrinterNotInstalled(Session session) { ActionResult resultCode; - TextWriterTraceListener installTraceListener = new TextWriterTraceListener("C:\\testout.txt"); + SessionLogWriterTraceListener installTraceListener = new SessionLogWriterTraceListener(session); PdfScribeInstaller installer = new PdfScribeInstaller(); installer.AddTraceListener(installTraceListener); - if (installer.IsPdfScribePrinterInstalled()) - resultCode = ActionResult.Success; - else - resultCode = ActionResult.Failure; + try + { + if (installer.IsPdfScribePrinterInstalled()) + resultCode = ActionResult.Success; + else + resultCode = ActionResult.Failure; + } + finally + { + if (installTraceListener != null) + installTraceListener.Dispose(); + } return resultCode; } @@ -64,23 +71,37 @@ namespace PdfScribeInstallCustomAction } finally { - if (installTraceListener != null) installTraceListener.Dispose(); + if (installTraceListener != null) + installTraceListener.Dispose(); + } return printerInstalled; } [CustomAction] - public static ActionResult UninstallPdfScribePrinter() + public static ActionResult UninstallPdfScribePrinter(Session session) { ActionResult printerUninstalled; - PdfScribeInstaller installer = new PdfScribeInstaller(); - if (installer.UninstallPdfScribePrinter()) - printerUninstalled = ActionResult.Success; - else - printerUninstalled = ActionResult.Failure; + SessionLogWriterTraceListener installTraceListener = new SessionLogWriterTraceListener(session); + installTraceListener.TraceOutputOptions = TraceOptions.DateTime; + PdfScribeInstaller installer = new PdfScribeInstaller(); + installer.AddTraceListener(installTraceListener); + try + { + if (installer.UninstallPdfScribePrinter()) + printerUninstalled = ActionResult.Success; + else + printerUninstalled = ActionResult.Failure; + installTraceListener.CloseAndWriteLog(); + } + finally + { + if (installTraceListener != null) + installTraceListener.Dispose(); + } return printerUninstalled; } } diff --git a/PdfScribeInstallCustomAction/SessionWriterTraceListener.cs b/PdfScribeInstallCustomAction/SessionWriterTraceListener.cs index 5ae52f7..0b6848f 100644 --- a/PdfScribeInstallCustomAction/SessionWriterTraceListener.cs +++ b/PdfScribeInstallCustomAction/SessionWriterTraceListener.cs @@ -28,11 +28,12 @@ namespace PdfScribeInstallCustomAction /// /// Releases resources held by the listener - - /// Note will not automatically flush and write - /// trace data to the install session - + /// will not automatically flush and write + /// trace data to the install session log - /// call CloseAndWriteLog() before disposing + /// to ensure data is written /// - public void Dispose() + public new void Dispose() { Dispose(true); GC.SuppressFinalize(this); @@ -70,7 +71,7 @@ namespace PdfScribeInstallCustomAction /// /// Closes the listener and writes accumulated /// trace data to the install session's log (Session.Log) - /// The listener will no longer be usable after calling + /// The listener should not be used after calling /// this method, and should be disposed of. /// public void CloseAndWriteLog() @@ -79,7 +80,6 @@ namespace PdfScribeInstallCustomAction this.installSession != null) { this.Flush(); - this.Close(); if (this.listenerStream.Length > 0) { listenerStream.Position = 0; @@ -88,7 +88,9 @@ namespace PdfScribeInstallCustomAction this.installSession.Log(listenerStreamReader.ReadToEnd()); } } + this.Close(); this.Dispose(); + this.installSession = null; } } }