periodic commit

This commit is contained in:
S T Chan 2014-01-09 01:23:49 -05:00
parent 989cf81ff6
commit 4d2fdb79c4
2 changed files with 140 additions and 20 deletions

View File

@ -11,18 +11,38 @@ namespace PdfScribe
{ {
public class ActivityNotificationPresenter public class ActivityNotificationPresenter
{ {
public ActivityNotificationPresenter() public ActivityNotificationPresenter(Application guiApplication)
{ {
progressTimer = new SysTimers.Timer(); this.activityWindowApp = guiApplication;
progressTimer.Enabled = false; this.progressTimer = new SysTimers.Timer();
progressTimer.Interval = 250; // Quarter second is default this.progressTimer.Enabled = false;
progressTimer.Elapsed += new SysTimers.ElapsedEventHandler(progressTimer_Elapsed); this.progressTimer.Interval = 250; // Quarter second is default
this.progressTimer.Elapsed += new SysTimers.ElapsedEventHandler(progressTimer_Elapsed);
this.activityWindow = new ActivityNotification();
/*
if (guiApplication.Dispatcher.CheckAccess())
{
this.activityWindow = new ActivityNotification();
}
else
{
guiApplication.Dispatcher.Invoke((Action)delegate()
{
this.activityWindow = new ActivityNotification();
progressTimer = new SysTimers.Timer();
progressTimer.Enabled = false;
progressTimer.Interval = 250; // Quarter second is default
progressTimer.Elapsed += new SysTimers.ElapsedEventHandler(progressTimer_Elapsed);
}
);
}
*/
} }
private Application activityWindowApp = null; private Application activityWindowApp;
private ActivityNotification activityWindow; private ActivityNotification activityWindow = null;
private SysTimers.Timer progressTimer; private SysTimers.Timer progressTimer;
readonly String progressString = "CAPTURING"; readonly String progressString = "CAPTURING";
@ -32,6 +52,27 @@ namespace PdfScribe
/// a separate thread /// a separate thread
/// </summary> /// </summary>
public void ShowActivityNotificationWindow() public void ShowActivityNotificationWindow()
{
if (this.activityWindow != null)
{
if (this.activityWindow.Dispatcher.CheckAccess())
{
this.activityWindow.Show();
}
else
{
this.activityWindow.Dispatcher.Invoke((Action)delegate()
{
this.activityWindow.Show();
}
);
}
this.progressTimer.Start();
}
}
/*
public void ShowActivityNotificationWindow()
{ {
if (this.activityWindowApp == null) if (this.activityWindowApp == null)
{ {
@ -48,6 +89,7 @@ namespace PdfScribe
this.progressTimer.Enabled = true; this.progressTimer.Enabled = true;
} }
} }
*/
/// <summary> /// <summary>
/// Shuts down the WPF Application showing /// Shuts down the WPF Application showing
@ -55,6 +97,25 @@ namespace PdfScribe
/// </summary> /// </summary>
public void CloseActivityNotificationWindow() public void CloseActivityNotificationWindow()
{ {
this.progressTimer.Enabled = false;
if (this.activityWindow != null)
{
if (this.activityWindow.Dispatcher.CheckAccess())
{
this.activityWindow.Close();
}
else
{
this.activityWindow.Dispatcher.Invoke((Action)delegate()
{
this.activityWindow.Close();
}
);
}
this.activityWindow = null;
}
/*
if (activityWindowApp != null) if (activityWindowApp != null)
{ {
this.progressTimer.Stop(); this.progressTimer.Stop();
@ -73,6 +134,7 @@ namespace PdfScribe
this.progressTimer.Dispose(); this.progressTimer.Dispose();
this.progressTimer = null; this.progressTimer = null;
} }
*/
} }
@ -80,15 +142,26 @@ namespace PdfScribe
private void progressTimer_Elapsed(object sender, SysTimers.ElapsedEventArgs e) private void progressTimer_Elapsed(object sender, SysTimers.ElapsedEventArgs e)
{ {
((SysTimers.Timer)sender).Enabled = false; ((SysTimers.Timer)sender).Enabled = false;
activityWindowApp.Dispatcher.Invoke((Action)delegate() if (activityWindow != null)
{ {
if (this.progressCounter >= progressString.Length) if (this.progressCounter >= progressString.Length)
this.progressCounter = 0; this.progressCounter = 0;
activityWindow.labelProgress.Content = progressString.Substring(0, progressCounter + 1);
progressCounter++; if (activityWindow.labelProgress.Dispatcher.CheckAccess())
} {
); activityWindow.labelProgress.Content = progressString.Substring(0, progressCounter + 1);
((SysTimers.Timer)sender).Enabled = true; }
else
{
activityWindow.labelProgress.Dispatcher.Invoke((Action)delegate()
{
activityWindow.labelProgress.Content = progressString.Substring(0, progressCounter + 1);
}
);
}
progressCounter++;
((SysTimers.Timer)sender).Enabled = true;
}
} }
} }

View File

@ -7,6 +7,7 @@ using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Windows;
using PdfScribeCore; using PdfScribeCore;
@ -38,7 +39,8 @@ namespace PdfScribe
#endregion #endregion
static ActivityNotificationPresenter userDisplay = new ActivityNotificationPresenter(); static Application guiApplication = null;
static ActivityNotificationPresenter userDisplay;
static TraceSource logEventSource = new TraceSource(traceSourceName); static TraceSource logEventSource = new TraceSource(traceSourceName);
[STAThread] [STAThread]
@ -46,8 +48,13 @@ 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
// handle Windows and other displayables
LaunchApplication();
userDisplay = new ActivityNotificationPresenter(guiApplication);
userDisplay.ShowActivityNotificationWindow(); userDisplay.ShowActivityNotificationWindow();
Thread.Sleep(3000); //Thread.Sleep(20000);
String standardInputFilename = Path.GetTempFileName(); String standardInputFilename = Path.GetTempFileName();
String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename); String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename);
@ -125,6 +132,7 @@ namespace PdfScribe
String.Format(warnFileNotDeleted, standardInputFilename)); String.Format(warnFileNotDeleted, standardInputFilename));
} }
userDisplay.CloseActivityNotificationWindow(); userDisplay.CloseActivityNotificationWindow();
ShutdownApplication();
} }
} }
@ -140,12 +148,51 @@ namespace PdfScribe
{ {
logEventSource.TraceEvent(TraceEventType.Critical, logEventSource.TraceEvent(TraceEventType.Critical,
(int)TraceEventType.Critical, (int)TraceEventType.Critical,
((Exception)e.ExceptionObject).Message); ((Exception)e.ExceptionObject).Message + Environment.NewLine +
((Exception)e.ExceptionObject).StackTrace);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionUnexpectedError, errorDialogInstructionUnexpectedError,
String.Empty); ((Exception)e.ExceptionObject).Message +
Environment.NewLine +
((Exception)e.ExceptionObject).StackTrace);
} }
static void LaunchApplication()
{
if (guiApplication == null)
{
guiApplication = new Application();
var guiApplicationThread = new Thread(new ThreadStart(() =>
{
guiApplication.ShutdownMode = ShutdownMode.OnExplicitShutdown;
guiApplication.Run();
}
));
guiApplicationThread.SetApartmentState(ApartmentState.STA);
guiApplicationThread.Start();
}
}
static void ShutdownApplication()
{
if (guiApplication != null)
{
guiApplication.Dispatcher.Invoke((Action)delegate()
{
if (guiApplication.Windows != null && guiApplication.Windows.Count > 0)
{
foreach (Window appWindow in guiApplication.Windows)
{
appWindow.Close();
}
}
}
);
guiApplication.Dispatcher.InvokeShutdown();
guiApplication = null;
}
}
} }
} }