void HandleAuthorisationClose() { var identity = GetCurrentPrincipal().Identity; if (identity.Name == "Admin") { ShowCreateNewUser(); } else { IsAuthorised = identity.IsAuthenticated; if (IsAuthorised) { using (var m = new MembershipContext()) { _backupService = new BackupService(_repository, m); //IsEnvelopeRandomising = BlowTrialDataService.IsEnvelopeRandomising(m); var backDetails = BlowTrialDataService.GetBackupDetails(m); if (backDetails.BackupData.IsBackingUpToCloud) { _transferLog = new TransferLog(backDetails.CloudDirectories.First() + '\\' + LogFileName); _backupService.OnBackup += OnBackupInterval; } } } else { OnRequestClose(); } } }
static string GetLogOutputPath() { BackupDataSet bak = BlowTrialDataService.GetBackupDetails(); if (bak != null) { string dir = bak.CloudDirectories.FirstOrDefault(); if (dir != null) { // if environment.machinename not working due to duplicate names, could try //var searcher = new System.Management.ManagementObjectSearcher("select * from " + Key); // key = Win32_DiskDrive or Win32_Processor return(Path.Combine(dir, StringExtensions.GetSafeFilename($"log_{Environment.MachineName}_{Environment.UserName}_{MAC()}.txt"))); } } return(null); }
public BackupService(IRepository repo, IAppData backupData) { _repo = repo; var backupDetails = BlowTrialDataService.GetBackupDetails(backupData); _repo.CloudDirectories = backupDetails.CloudDirectories; //use DispatcherTimer rather than dispatcher as CE does not handle multiple connections inevitable with multi threading _timer = new DispatcherTimer(DispatcherPriority.Normal) { Interval = new TimeSpan(0, backupDetails.BackupData.BackupIntervalMinutes, 0) }; if (backupDetails.BackupData.IsBackingUpToCloud) { _handler = new EventHandler(Backup); _isToBackup = true; } else { _handler = new EventHandler(Restore); Restore(this, new EventArgs()); } _timer.Tick += _handler; _timer.Start(); }
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(); }