Added SessionWriterTraceListener.cs class
This commit is contained in:
parent
041ff0d11d
commit
000216e993
@ -98,14 +98,16 @@ namespace PdfScribeCore
|
|||||||
this.logEventSource.Listeners.Add(additionalListener);
|
this.logEventSource.Listeners.Add(additionalListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public PdfScribeInstaller()
|
public PdfScribeInstaller()
|
||||||
{
|
{
|
||||||
this.logEventSource = new TraceSource(logEventSourceNameDefault);
|
this.logEventSource = new TraceSource(logEventSourceNameDefault);
|
||||||
this.logEventSource.Switch = new SourceSwitch("PdfScribeCoreSwitch");
|
this.logEventSource.Switch = new SourceSwitch("PdfScribeCoreAll");
|
||||||
this.logEventSource.Switch.Level = SourceLevels.All;
|
this.logEventSource.Switch.Level = SourceLevels.All;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This override sets the
|
/// This override sets the
|
||||||
/// trace source to a specific name
|
/// trace source to a specific name
|
||||||
@ -124,7 +126,7 @@ namespace PdfScribeCore
|
|||||||
this.logEventSource.Switch = new SourceSwitch("PdfScribeCoreSwitch");
|
this.logEventSource.Switch = new SourceSwitch("PdfScribeCoreSwitch");
|
||||||
this.logEventSource.Switch.Level = SourceLevels.All;
|
this.logEventSource.Switch.Level = SourceLevels.All;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Port operations
|
#region Port operations
|
||||||
|
@ -24,7 +24,7 @@ namespace PdfScribeInstallCustomAction
|
|||||||
{
|
{
|
||||||
ActionResult resultCode;
|
ActionResult resultCode;
|
||||||
TextWriterTraceListener installTraceListener = new TextWriterTraceListener("C:\\testout.txt");
|
TextWriterTraceListener installTraceListener = new TextWriterTraceListener("C:\\testout.txt");
|
||||||
PdfScribeInstaller installer = new PdfScribeInstaller(traceSourceName);
|
PdfScribeInstaller installer = new PdfScribeInstaller();
|
||||||
installer.AddTraceListener(installTraceListener);
|
installer.AddTraceListener(installTraceListener);
|
||||||
if (installer.IsPdfScribePrinterInstalled())
|
if (installer.IsPdfScribePrinterInstalled())
|
||||||
resultCode = ActionResult.Success;
|
resultCode = ActionResult.Success;
|
||||||
@ -44,12 +44,13 @@ namespace PdfScribeInstallCustomAction
|
|||||||
String outputCommand = session.CustomActionData["OutputCommand"];
|
String outputCommand = session.CustomActionData["OutputCommand"];
|
||||||
String outputCommandArguments = session.CustomActionData["OutputCommandArguments"];
|
String outputCommandArguments = session.CustomActionData["OutputCommandArguments"];
|
||||||
|
|
||||||
TextWriterTraceListener installTraceListener = new TextWriterTraceListener("C:\\testout.txt");
|
SessionLogWriterTraceListener installTraceListener = new SessionLogWriterTraceListener(session);
|
||||||
installTraceListener.TraceOutputOptions = TraceOptions.Timestamp;
|
installTraceListener.TraceOutputOptions = TraceOptions.DateTime;
|
||||||
|
|
||||||
PdfScribeInstaller installer = new PdfScribeInstaller(traceSourceName);
|
|
||||||
|
|
||||||
|
PdfScribeInstaller installer = new PdfScribeInstaller();
|
||||||
installer.AddTraceListener(installTraceListener);
|
installer.AddTraceListener(installTraceListener);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
if (installer.InstallPdfScribePrinter(driverSourceDirectory,
|
if (installer.InstallPdfScribePrinter(driverSourceDirectory,
|
||||||
@ -59,9 +60,12 @@ namespace PdfScribeInstallCustomAction
|
|||||||
else
|
else
|
||||||
printerInstalled = ActionResult.Failure;
|
printerInstalled = ActionResult.Failure;
|
||||||
|
|
||||||
installTraceListener.Flush();
|
installTraceListener.CloseAndWriteLog();
|
||||||
installTraceListener.Close();
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (installTraceListener != null) installTraceListener.Dispose();
|
||||||
|
}
|
||||||
return printerInstalled;
|
return printerInstalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +75,7 @@ namespace PdfScribeInstallCustomAction
|
|||||||
{
|
{
|
||||||
ActionResult printerUninstalled;
|
ActionResult printerUninstalled;
|
||||||
|
|
||||||
PdfScribeInstaller installer = new PdfScribeInstaller(traceSourceName);
|
PdfScribeInstaller installer = new PdfScribeInstaller();
|
||||||
if (installer.UninstallPdfScribePrinter())
|
if (installer.UninstallPdfScribePrinter())
|
||||||
printerUninstalled = ActionResult.Success;
|
printerUninstalled = ActionResult.Success;
|
||||||
else
|
else
|
||||||
|
@ -82,6 +82,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CustomAction.cs" />
|
<Compile Include="CustomAction.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="SessionWriterTraceListener.cs" />
|
||||||
<Content Include="CustomAction.config" />
|
<Content Include="CustomAction.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
95
PdfScribeInstallCustomAction/SessionWriterTraceListener.cs
Normal file
95
PdfScribeInstallCustomAction/SessionWriterTraceListener.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using Microsoft.Deployment.WindowsInstaller;
|
||||||
|
|
||||||
|
namespace PdfScribeInstallCustomAction
|
||||||
|
{
|
||||||
|
public class SessionLogWriterTraceListener : TextWriterTraceListener , IDisposable
|
||||||
|
{
|
||||||
|
|
||||||
|
protected MemoryStream listenerStream;
|
||||||
|
protected Session installSession;
|
||||||
|
private bool isDisposed;
|
||||||
|
|
||||||
|
public SessionLogWriterTraceListener(Session session)
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
this.listenerStream = new MemoryStream();
|
||||||
|
this.Writer = new StreamWriter(this.listenerStream);
|
||||||
|
this.installSession = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IDisposable impelementation
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases resources held by the listener -
|
||||||
|
/// Note will not automatically flush and write
|
||||||
|
/// trace data to the install session -
|
||||||
|
/// call CloseAndWriteLog() before disposing
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dipose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!this.isDisposed)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (this.Writer != null)
|
||||||
|
{
|
||||||
|
this.Writer.Close();
|
||||||
|
this.Writer.Dispose();
|
||||||
|
this.Writer = null;
|
||||||
|
}
|
||||||
|
if (this.listenerStream != null)
|
||||||
|
{
|
||||||
|
this.listenerStream.Close();
|
||||||
|
this.listenerStream.Dispose();
|
||||||
|
this.listenerStream = null;
|
||||||
|
}
|
||||||
|
if (this.installSession != null)
|
||||||
|
this.installSession = null;
|
||||||
|
}
|
||||||
|
this.isDisposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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
|
||||||
|
/// this method, and should be disposed of.
|
||||||
|
/// </summary>
|
||||||
|
public void CloseAndWriteLog()
|
||||||
|
{
|
||||||
|
if (this.listenerStream != null &&
|
||||||
|
this.installSession != null)
|
||||||
|
{
|
||||||
|
this.Flush();
|
||||||
|
this.Close();
|
||||||
|
if (this.listenerStream.Length > 0)
|
||||||
|
{
|
||||||
|
listenerStream.Position = 0;
|
||||||
|
using (StreamReader listenerStreamReader = new StreamReader(this.listenerStream))
|
||||||
|
{
|
||||||
|
this.installSession.Log(listenerStreamReader.ReadToEnd());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user