void MigrateIfRequired(string fullFilename) { if (_baksForgoingMigration == null) { _baksForgoingMigration = new List <string>(); } if (!_baksForgoingMigration.Contains(fullFilename)) { if (!CodeBasedMigration.ApplyPendingMigrations <BlowTrial.Migrations.TrialData.TrialDataConfiguration>(TrialDataContext.GetConnectionString(fullFilename), ContextCeConfiguration.ProviderInvariantName)) { _baksForgoingMigration.Add(fullFilename); } } }
protected override void OnStartup(StartupEventArgs e) { _log = LogManager.GetLogger(typeof(App)); #if !DEBUG if (CurrentClickOnceVersion != null) { ThreadContext.Properties["deploymentVersion"] = CurrentClickOnceVersion; } this.DispatcherUnhandledException += Application_DispatcherUnhandledException; log4net.Config.XmlConfigurator.Configure(); #endif base.OnStartup(e); // AppDomain.CurrentDomain.SetData("DataDirectory", baseDir); //Application initialisation AutoMapperConfiguration.Configure(); /* * catch (Exception ex) * { * _log.Error("App_AutomapperConfigurationException", ex); * MessageBox.Show("An error has occured with automapper. An error has been logged, but this file will have to be attached and emailed to the application developer"); * throw; * } */ //Security CustomPrincipal customPrincipal = new CustomPrincipal(); AppDomain.CurrentDomain.SetThreadPrincipal(customPrincipal); ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; //test if wizard needs to run #if !DEBUG try { #endif CodeBasedMigration.ApplyPendingMigrations <BlowTrial.Migrations.TrialData.TrialDataConfiguration>(TrialDataContext.GetConnectionString(), ContextCeConfiguration.ProviderInvariantName, true); CodeBasedMigration.ApplyPendingMigrations <BlowTrial.Migrations.Membership.MembershipConfiguration>(MembershipContext.GetConnectionString(), ContextCeConfiguration.ProviderInvariantName, true); #if !DEBUG } catch (Exception ex) { string usrErrMsg = null; if (ex.Message.StartsWith("Access to the database file is not allowed")) { string administratorInstructions = string.Format("User:{0}\nRequies modify permissions be allowed for folder:\n{1}\nAnd all files within", System.Security.Principal.WindowsIdentity.GetCurrent().Name, DataDirectory); usrErrMsg = "Cannot access database: \nPlease contact the systems administrator with the following message:\n" + administratorInstructions; } else { usrErrMsg = "An error has occured trying to access the database: \n" + ex.Message; } if (usrErrMsg != null) { _log.Error("App_FirstDatabaseAccessException", ex); MessageBox.Show(usrErrMsg); throw; } } #endif var backDetails = BlowTrialDataService.GetBackupDetails(); bool displayWizard = (backDetails.BackupData == null); if (!displayWizard && backDetails.BackupData.IsBackingUpToCloud) { using (var t = new TrialDataContext()) { displayWizard = !t.StudyCentres.Any(); } } if (displayWizard && !DisplayAppSettingsWizard()) { Shutdown(259); return; } // Create the ViewModel to which // the main window binds. var mainWindowVm = new MainWindowViewModel(); MainWindow window = new MainWindow(mainWindowVm); // When the ViewModel asks to be closed, // close the window. EventHandler handler = null; handler = delegate { window.Close(); if (!window.IsLoaded) //in case user cancelled { mainWindowVm.RequestClose -= handler; } }; mainWindowVm.RequestClose += handler; _log.InfoFormat("Application started {0}", DateTime.Now); window.Show(); }