using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Browser; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SilverlightNaited { public partial class App : Application { public App() { this.Startup += this.Application_Startup; this.Exit += this.Application_Exit; this.UnhandledException += this.Application_UnhandledException; InitializeComponent(); } private void Application_Startup(object sender, StartupEventArgs e) { this.RootVisual = new MainPage(); string s = null; HtmlPage.Document.QueryString.TryGetValue("leht", out s); if (s == null) { e.InitParams.TryGetValue("leht", out s); } if (s == null) { return; } if (s.Equals("RuuduLoomine")) { this.RootVisual = new RuuduLoomine(); } if (s.Equals("Arvutus")) { this.RootVisual = new Arvutus(); } if (s.Equals("Tervitus")) { this.RootVisual = new Tervitus(); } if (s.Equals("GridPaigutus")) { this.RootVisual = new GridPaigutus(); } if (s.Equals("GridJaStack")) { this.RootVisual = new GridJaStack(); } if (s.Equals("NuppudeLoomine")) { this.RootVisual = new NuppudeLoomine(); } if (s.Equals("NupudLouendil")) { this.RootVisual = new NupudLouendil(); } if (s.Equals("RuuduLiikumine")) { this.RootVisual = new RuuduLiikumine(); } if (s.Equals("RuuduHiir")) { this.RootVisual = new RuuduHiir(); } if (s.Equals("RuuduSuurus")) { this.RootVisual = new RuuduSuurus(); } if (s.Equals("RuuduSuurus2")) { this.RootVisual = new RuuduSuurus2(); } if (s.Equals("RuutudeArv")) { this.RootVisual = new RuutudeArv(); } if (s.Equals("RuutudeArv2")) { this.RootVisual = new RuutudeArv2(); } if (s.Equals("KujunditeJoonistus")) { this.RootVisual = new KujunditeJoonistus(); } if (s.Equals("KujunditeJoonistus2")) { this.RootVisual = new KujunditeJoonistus2(); } if (s.Equals("Animatsioon1")) { this.RootVisual = new Animatsioon1(); } if (s.Equals("Animatsioon2")) { this.RootVisual = new Animatsioon2(); } if (s.Equals("PiltideKeeramine")) { this.RootVisual = new PiltideKeeramine(); } } private void Application_Exit(object sender, EventArgs e) { } private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { // If the app is running outside of the debugger then report the exception using // the browser's exception mechanism. On IE this will display it a yellow alert // icon in the status bar and Firefox will display a script error. if (!System.Diagnostics.Debugger.IsAttached) { // NOTE: This will allow the application to continue running after an exception has been thrown // but not handled. // For production applications this error handling should be replaced with something that will // report the error to the website and stop the application. e.Handled = true; Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); } } private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) { try { string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); } catch (Exception) { } } } }