Implement SavePdf, SaveImages, Print event logging

This commit is contained in:
Ben Olden-Cooligan 2018-09-28 21:18:28 -04:00
parent 6be9519ddd
commit d2b36814e3
6 changed files with 99 additions and 2 deletions

View File

@ -146,6 +146,18 @@ namespace NAPS2.ImportExport.Images
}
return false;
});
Success.ContinueWith(task =>
{
if (task.Result)
{
Log.Event(EventType.SaveImages, new EventParams
{
Name = MiscResources.SaveImages,
Pages = snapshots.Count,
FileFormat = Path.GetExtension(fileName)
});
}
}, TaskContinuationOptions.OnlyOnRanToCompletion);
return true;
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAPS2.ImportExport.Email;
using NAPS2.Lang.Resources;
@ -113,6 +114,30 @@ namespace NAPS2.ImportExport.Pdf
return result;
});
Success.ContinueWith(task =>
{
if (task.Result)
{
if (email)
{
Log.Event(EventType.Email, new EventParams
{
Name = MiscResources.EmailPdf,
Pages = snapshots.Count,
FileFormat = ".pdf"
});
}
else
{
Log.Event(EventType.SavePdf, new EventParams
{
Name = MiscResources.SavePdf,
Pages = snapshots.Count,
FileFormat = ".pdf"
});
}
}
}, TaskContinuationOptions.OnlyOnRanToCompletion);
return true;
}

View File

@ -5,6 +5,8 @@ using System.Drawing.Printing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAPS2.Lang.Resources;
using NAPS2.Logging;
using NAPS2.Scan.Images;
using NAPS2.Scan.Images.Transforms;
using NAPS2.Util;
@ -105,6 +107,14 @@ namespace NAPS2.ImportExport
};
printDocument.PrinterSettings = printerSettings;
printDocument.Print();
Log.Event(EventType.Print, new EventParams
{
Name = MiscResources.Print,
Pages = snapshots.Count,
DeviceName = printDocument.PrinterSettings.PrinterName
});
return true;
}
finally

View File

@ -474,6 +474,15 @@ namespace NAPS2.Lang.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Email PDF.
/// </summary>
internal static string EmailPdf {
get {
return ResourceManager.GetString("EmailPdf", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Email PDF Progress.
/// </summary>
@ -933,6 +942,15 @@ namespace NAPS2.Lang.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Print.
/// </summary>
internal static string Print {
get {
return ResourceManager.GetString("Print", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} / {1}.
/// </summary>
@ -987,6 +1005,15 @@ namespace NAPS2.Lang.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Save Images.
/// </summary>
internal static string SaveImages {
get {
return ResourceManager.GetString("SaveImages", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Save Images Progress.
/// </summary>
@ -996,6 +1023,15 @@ namespace NAPS2.Lang.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Save PDF.
/// </summary>
internal static string SavePdf {
get {
return ResourceManager.GetString("SavePdf", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Save PDF Progress.
/// </summary>

View File

@ -342,15 +342,24 @@
<data name="RecoveryProgress" xml:space="preserve">
<value>Recovery Progress</value>
</data>
<data name="SaveImages" xml:space="preserve">
<value>Save Images</value>
</data>
<data name="SaveImagesProgress" xml:space="preserve">
<value>Save Images Progress</value>
</data>
<data name="SavePdf" xml:space="preserve">
<value>Save PDF</value>
</data>
<data name="SavePdfProgress" xml:space="preserve">
<value>Save PDF Progress</value>
</data>
<data name="SavingFormat" xml:space="preserve">
<value>Saving {0}...</value>
</data>
<data name="Print" xml:space="preserve">
<value>Print</value>
</data>
<data name="Copying" xml:space="preserve">
<value>Copying...</value>
</data>
@ -360,6 +369,9 @@
<data name="Importing" xml:space="preserve">
<value>Importing...</value>
</data>
<data name="EmailPdf" xml:space="preserve">
<value>Email PDF</value>
</data>
<data name="EmailPdfProgress" xml:space="preserve">
<value>Email PDF Progress</value>
</data>

View File

@ -19,6 +19,7 @@ namespace NAPS2.Util
private readonly AppConfigManager appConfigManager;
private readonly WindowsEventLogger windowsEventLogger;
private bool shouldCreateEventSource;
private int returnCode;
public Lifecycle(StillImage sti, AppConfigManager appConfigManager, WindowsEventLogger windowsEventLogger)
@ -102,7 +103,8 @@ namespace NAPS2.Util
}
}
if (args.Any(x => x.Equals("/CreateEventSource", StringComparison.InvariantCultureIgnoreCase)))
shouldCreateEventSource = args.Any(x => x.Equals("/CreateEventSource", StringComparison.InvariantCultureIgnoreCase));
if (shouldCreateEventSource)
{
try
{
@ -149,7 +151,7 @@ namespace NAPS2.Util
/// </summary>
public void ExitIfRedundant()
{
if (sti.ShouldRegister || sti.ShouldUnregister)
if (sti.ShouldRegister || sti.ShouldUnregister || shouldCreateEventSource)
{
// Was just started by the user to (un)register STI
Environment.Exit(returnCode);