periodic commit

This commit is contained in:
S T Chan 2014-01-09 21:43:58 -05:00
parent 55c5e9aeec
commit e130b5f07f
3 changed files with 44 additions and 48 deletions

View File

@ -2,7 +2,7 @@
x:ClassModifier="internal" x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ActivityNotification" Height="300" Width="300" Title="PDF Scribe" Height="300" Width="300"
AllowsTransparency="True" AllowsTransparency="True"
WindowStyle="None" WindowStyle="None"
Background="Transparent" Background="Transparent"

View File

@ -12,29 +12,6 @@ namespace PdfScribe
{ {
public class ActivityNotificationPresenter public class ActivityNotificationPresenter
{ {
public ActivityNotificationPresenter(Application guiApplication)
{
this.activityWindowApp = guiApplication;
this.activityWindow = new ActivityNotification();
this.progressTimer = new SysTimers.Timer();
this.progressTimer.Enabled = false;
this.progressTimer.Interval = 250; // Quarter second is default
this.progressTimer.Elapsed += new SysTimers.ElapsedEventHandler(progressTimer_Elapsed);
/*
if (guiApplication.Dispatcher.CheckAccess())
{
this.activityWindow = new ActivityNotification();
}
else
{
guiApplication.Dispatcher.Invoke((Action)delegate()
{
this.activityWindow = new ActivityNotification();
}
);
}
*/
}
public ActivityNotificationPresenter() public ActivityNotificationPresenter()
{ {
@ -42,7 +19,7 @@ namespace PdfScribe
this.progressTimer.Enabled = false; this.progressTimer.Enabled = false;
this.progressTimer.Interval = 250; // Quarter second is default this.progressTimer.Interval = 250; // Quarter second is default
this.progressTimer.Elapsed += new SysTimers.ElapsedEventHandler(progressTimer_Elapsed); this.progressTimer.Elapsed += new SysTimers.ElapsedEventHandler(progressTimer_Elapsed);
this.activityWindow = new ActivityNotification(); //this.activityWindow = new ActivityNotification();
} }
@ -58,11 +35,12 @@ namespace PdfScribe
/// </summary> /// </summary>
public void ShowActivityNotificationWindow() public void ShowActivityNotificationWindow()
{ {
if (this.activityWindow != null) if (this.activityWindow == null)
{ {
if (this.activityWindow.Dispatcher.CheckAccess()) if (this.activityWindow.Dispatcher.CheckAccess())
{ {
this.activityWindow = new ActivityNotification();
this.activityWindow.Show(); this.activityWindow.Show();
this.progressTimer.Start(); this.progressTimer.Start();
} }
@ -70,6 +48,7 @@ namespace PdfScribe
{ {
this.activityWindow.Dispatcher.Invoke((Action)delegate() this.activityWindow.Dispatcher.Invoke((Action)delegate()
{ {
this.activityWindow = new ActivityNotification();
this.activityWindow.Show(); this.activityWindow.Show();
this.progressTimer.Start(); this.progressTimer.Start();
} }
@ -157,18 +136,18 @@ namespace PdfScribe
if (activityWindow.labelProgress.Dispatcher.CheckAccess()) if (activityWindow.labelProgress.Dispatcher.CheckAccess())
{ {
EventLog.WriteEntry("PdfScribe", "Timer_No_Invoke"); //EventLog.WriteEntry("PdfScribe", "Timer_No_Invoke");
this.activityWindow.labelProgress.Content = this.progressString.Substring(0, progressCounter + 1); this.activityWindow.labelProgress.Content = this.progressString.Substring(0, progressCounter + 1);
} }
else else
{ {
EventLog.WriteEntry("PdfScribe", "Timer_Invoke"); //EventLog.WriteEntry("PdfScribe", "Timer_Invoke");
this.activityWindow.labelProgress.Dispatcher.BeginInvoke((Action)delegate() this.activityWindow.labelProgress.Dispatcher.Invoke((Action)delegate()
{ {
this.activityWindow.labelProgress.Content = this.progressString.Substring(0, progressCounter + 1); this.activityWindow.labelProgress.Content = this.progressString.Substring(0, progressCounter + 1);
} }
); );
EventLog.WriteEntry("PdfScribe", "Timer_Invoked"); //EventLog.WriteEntry("PdfScribe", "Timer_Invoked");
} }
progressCounter++; progressCounter++;
} }

View File

@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Threading;
using PdfScribeCore; using PdfScribeCore;
namespace PdfScribe namespace PdfScribe
@ -23,7 +23,7 @@ namespace PdfScribe
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 unhandled error in PDF Scribe. Enable tracing for details.";
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}.";
@ -49,14 +49,12 @@ namespace PdfScribe
// Install the global exception handler // Install the global exception handler
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Application_UnhandledException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Application_UnhandledException);
// Setup and start the WPF application that will //Dispatcher.Run();
// handle Windows and other displayables
LaunchApplication(); LaunchApplication();
userDisplay = new ActivityNotificationPresenter(guiApplication);
userDisplay.ShowActivityNotificationWindow();
Thread.Sleep(10000);
//LaunchActivityNotification(); //LaunchActivityNotification();
//Thread.Sleep(10000);
String standardInputFilename = Path.GetTempFileName(); String standardInputFilename = Path.GetTempFileName();
String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename); String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename);
@ -88,9 +86,17 @@ namespace PdfScribe
errorDialogInstructionCouldNotWrite + errorDialogInstructionCouldNotWrite +
Environment.NewLine + Environment.NewLine +
"Exception message: " + ioEx.Message); "Exception message: " + ioEx.Message);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, /*ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionCouldNotWrite, errorDialogInstructionCouldNotWrite,
String.Empty); String.Format("{0} is in use.", outputFilename));*/
DispatchToGUIApp((Action)delegate()
{
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionCouldNotWrite,
String.Format("{0} is in use.", outputFilename));
}
);
} }
catch (UnauthorizedAccessException unauthorizedEx) catch (UnauthorizedAccessException unauthorizedEx)
{ {
@ -105,7 +111,7 @@ namespace PdfScribe
"Exception message: " + unauthorizedEx.Message); "Exception message: " + unauthorizedEx.Message);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionCouldNotWrite, errorDialogInstructionCouldNotWrite,
String.Empty); String.Format("Insufficient privileges to either create or delete {0}", outputFilename));
} }
catch (ExternalException ghostscriptEx) catch (ExternalException ghostscriptEx)
{ {
@ -132,7 +138,6 @@ namespace PdfScribe
(int)TraceEventType.Warning, (int)TraceEventType.Warning,
String.Format(warnFileNotDeleted, standardInputFilename)); String.Format(warnFileNotDeleted, standardInputFilename));
} }
if (userDisplay != null) userDisplay.CloseActivityNotificationWindow();
ShutdownApplication(); ShutdownApplication();
} }
} }
@ -153,9 +158,7 @@ namespace PdfScribe
((Exception)e.ExceptionObject).StackTrace); ((Exception)e.ExceptionObject).StackTrace);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionUnexpectedError, errorDialogInstructionUnexpectedError,
((Exception)e.ExceptionObject).Message + String.Empty);
Environment.NewLine +
((Exception)e.ExceptionObject).StackTrace);
} }
static void LaunchActivityNotification() static void LaunchActivityNotification()
@ -164,8 +167,10 @@ namespace PdfScribe
{ {
guiApplication.Dispatcher.Invoke((Action)delegate() guiApplication.Dispatcher.Invoke((Action)delegate()
{ {
ActivityNotificationPresenter notificationPresenter = new ActivityNotificationPresenter(); //ActivityNotificationPresenter notificationPresenter = new ActivityNotificationPresenter();
notificationPresenter.ShowActivityNotificationWindow(); //notificationPresenter.ShowActivityNotificationWindow();
ActivityNotification testWindow = new ActivityNotification();
testWindow.Show();
} }
); );
} }
@ -176,9 +181,9 @@ namespace PdfScribe
if (guiApplication == null) if (guiApplication == null)
{ {
guiApplication = new Application();
var guiApplicationThread = new Thread(new ThreadStart(() => var guiApplicationThread = new Thread(new ThreadStart(() =>
{ {
guiApplication = new Application();
guiApplication.ShutdownMode = ShutdownMode.OnExplicitShutdown; guiApplication.ShutdownMode = ShutdownMode.OnExplicitShutdown;
guiApplication.Run(); guiApplication.Run();
} }
@ -189,6 +194,14 @@ namespace PdfScribe
} }
} }
static void DispatchToGUIApp(Action guiAction)
{
if (guiApplication != null)
{
guiApplication.Dispatcher.Invoke(guiAction);
}
}
static void ShutdownApplication() static void ShutdownApplication()
{ {
if (guiApplication != null) if (guiApplication != null)
@ -202,11 +215,15 @@ namespace PdfScribe
appWindow.Close(); appWindow.Close();
} }
} }
guiApplication.Shutdown();
//guiApplication.Dispatcher.InvokeShutdown();
} }
); );
guiApplication.Dispatcher.InvokeShutdown();
//guiApplication.Dispatcher.BeginInvokeShutdown(System.Windows.Threading.DispatcherPriority.Send);
//guiApplication.Shutdown(); //guiApplication.Shutdown();
//guiApplication = null;
} }
} }
} }