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 ActivityNotificationPresenter()
public ActivityNotificationPresenter(Application guiApplication)
{
this.activityWindowApp = guiApplication;
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);
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 ActivityNotification activityWindow;
private Application activityWindowApp;
private ActivityNotification activityWindow = null;
private SysTimers.Timer progressTimer;
readonly String progressString = "CAPTURING";
@ -32,6 +52,27 @@ namespace PdfScribe
/// a separate thread
/// </summary>
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)
{
@ -48,6 +89,7 @@ namespace PdfScribe
this.progressTimer.Enabled = true;
}
}
*/
/// <summary>
/// Shuts down the WPF Application showing
@ -55,6 +97,25 @@ namespace PdfScribe
/// </summary>
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)
{
this.progressTimer.Stop();
@ -73,6 +134,7 @@ namespace PdfScribe
this.progressTimer.Dispose();
this.progressTimer = null;
}
*/
}
@ -80,16 +142,27 @@ namespace PdfScribe
private void progressTimer_Elapsed(object sender, SysTimers.ElapsedEventArgs e)
{
((SysTimers.Timer)sender).Enabled = false;
activityWindowApp.Dispatcher.Invoke((Action)delegate()
if (activityWindow != null)
{
if (this.progressCounter >= progressString.Length)
this.progressCounter = 0;
if (activityWindow.labelProgress.Dispatcher.CheckAccess())
{
activityWindow.labelProgress.Content = progressString.Substring(0, progressCounter + 1);
}
else
{
activityWindow.labelProgress.Dispatcher.Invoke((Action)delegate()
{
activityWindow.labelProgress.Content = progressString.Substring(0, progressCounter + 1);
progressCounter++;
}
);
}
progressCounter++;
((SysTimers.Timer)sender).Enabled = true;
}
}
}
}

View File

@ -7,6 +7,7 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows;
using PdfScribeCore;
@ -38,7 +39,8 @@ namespace PdfScribe
#endregion
static ActivityNotificationPresenter userDisplay = new ActivityNotificationPresenter();
static Application guiApplication = null;
static ActivityNotificationPresenter userDisplay;
static TraceSource logEventSource = new TraceSource(traceSourceName);
[STAThread]
@ -46,8 +48,13 @@ namespace PdfScribe
{
// Install the global exception handler
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();
Thread.Sleep(3000);
//Thread.Sleep(20000);
String standardInputFilename = Path.GetTempFileName();
String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename);
@ -125,6 +132,7 @@ namespace PdfScribe
String.Format(warnFileNotDeleted, standardInputFilename));
}
userDisplay.CloseActivityNotificationWindow();
ShutdownApplication();
}
}
@ -140,12 +148,51 @@ namespace PdfScribe
{
logEventSource.TraceEvent(TraceEventType.Critical,
(int)TraceEventType.Critical,
((Exception)e.ExceptionObject).Message);
((Exception)e.ExceptionObject).Message + Environment.NewLine +
((Exception)e.ExceptionObject).StackTrace);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
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;
}
}
}
}