using System;
using System.Windows;
using Microsoft.SPOT.Emulator;
using Microsoft.SPOT.Emulator.Wpf;
namespace KioskEmulator
{
public partial class App
{
KioskEmulatorEngine Engine;
KioskEmulatorViewModel ViewModel;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup( e );
// create a new emulator instance
KioskEmulatorEngine eng =
new KioskEmulatorEngine(new EmulatorNative());
// let the view model connect to the emulator events
// *before* starting the emulator, otherwise it might
// miss the initialize event. (E.g. try to connect
// after the one time event is fired.)
this.ViewModel = new KioskEmulatorViewModel(eng);
this.Engine = eng;
this.Engine.StartEmulator( );
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
// Setting the DataContext here instead of in XAML
// is an optimization (see:
// http://msdn.microsoft.com/en-us/library/cc656914.aspx )
// it also ensures that the engine the viewmodel connects
// to is started before the databinding starts trying to
// access it.
// only hook up the data context the first time the
// Application is activated
if( this.MainWindow.DataContext == null )
this.MainWindow.DataContext = this.ViewModel;
}
protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
// shut down the emulator engine if it isn't already
// shutting down
if( Engine.State != Emulator.EmulatorState.ShutDown
&& Engine.State != Emulator.EmulatorState.Uninitialize
)
{
Engine.Stop();
}
}
}
}