/// <summary> /// Saves the current settings from the form to disk /// </summary> /// <returns>true, if save action was successful</returns> private bool saveSettings() { //preserve hidden flags //BackupSettings config = BackupSettingsDao.loadSettings(); if (config == null) { config = new BackupSettings(); } config.DestinationPath = txtDestination.Text; config.Interval = (int)numInterval.Value; config.BackupProgram = txtBackupExe.Text; config.BackupPrefix = txtPrefix.Text; config.BackupSuffix = txtSuffix.Text; config.PostBackupCmd = txtPostBackupCmd.Text; config.BackupAll = cbxBackupAll.Checked; config.CountdownSeconds = (int)numCountdown.Value; if (String.IsNullOrEmpty(txtLastBackup.Text)) { config.LastRun = DateTime.MinValue; } config.Items.Clear(); for (int i = 0; i < lvStores.Items.Count; i++) { if (lvStores.Items[i].Checked) { config.Items.Add(lvStores.Items[i].Text); } } return(BackupSettingsDao.saveSettings(config)); }
/// <summary> /// Schedule backup when outlook is closed /// </summary> public void ScheduleBackupOnExit(Office.IRibbonControl control) { var config = BackupSettingsDao.loadSettings(); config.LastRun = new DateTime(); BackupSettingsDao.saveSettings(config); }
/// <summary> /// Waits, till outlook ends and then starts the backup process /// </summary> /// <param name="config">Stored configuration from outlook plugin</param> /// <param name="log">logging delegate to send error information</param> /// <returns>number of occurred errors</returns> public static int tryBackup(BackupSettings config, Logger log) { int iError = 0; if (config == null) { log("backup not configured"); return(0); } log("Starting backup...please wait..."); try { if (config.Items.Count > 0) { log("Check whether outlooks is still running ..."); if (WaitForProcessEnd(OUTLOOK_PROC, log)) { log("No outlook process found"); iError += doBackup(config, log); if (!String.IsNullOrEmpty(config.PostBackupCmd)) { int iRes = RunPostCmd(config.PostBackupCmd, config.ProfileName, log); iError += iRes; } } else { iError++; log("Error waiting for " + OUTLOOK_PROC); } } else { iError++; log("Error: no files for backup selected"); } //if no errors occurred, save current timestamp if (iError == 0) { config.LastRun = DateTime.Now; BackupSettingsDao.saveSettings(config); } } catch (InstanceAlreadyRunningException) { log("Backup already running..."); iError++; } return(iError); }
/// <summary> /// Run backup program if neccessary /// </summary> void ThisAddIn_Quit() { try { BackupSettings config = BackupSettingsDao.loadSettings(); //if configuration was done and backup program was configured if (config != null && !String.IsNullOrEmpty(config.BackupProgram)) { //and if not yet backuped or if backup too old, then run program if (config.LastRun == null || config.LastRun.AddDays(config.Interval).AddHours(config.IntervalHours) <= DateTime.Now) { bool configChanged = false; if (config.BackupAll) { //If alles pdf-files should be saved, enumerate them and save to config-file //Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); config.Items.Clear(); var list = BackupUtils.GetStoreLocations(config, Application.Session.Stores); config.Items.AddRange(list.ToArray()); configChanged = true; } if (config.ProfileName != Application.Session.CurrentProfileName) { config.ProfileName = Application.Session.CurrentProfileName; configChanged = true; } if (configChanged) { BackupSettingsDao.saveSettings(config); } try { Process.Start(config.BackupProgram); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(config.BackupProgram + " not found! " + e.Message); } } }//config loaded } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } }