public Autorecover() { InitializeComponent(); RecoveryDatabase recovery = new RecoveryDatabase(RecoveryVersion.LastRun); Appointment recoveryAppointment = recovery.RecoveryAppointment; if (recoveryAppointment != null) { listBox.Items.Add(new AppointmentGraphic(recoveryAppointment)); } Contact recoveryContact = recovery.RecoveryContact; if (recoveryContact != null) { listBox.Items.Add(new ContactGraphic(recoveryContact)); } UserTask recoveryTask = recovery.RecoveryTask; if (recoveryTask != null) { listBox.Items.Add(new TaskGraphic(recoveryTask)); } }
private void ShowRecoveryMessages() { // Make sure we are dealing with the correct set of files. new RecoveryDatabase(RecoveryVersion.Current).SetToLastRun(); RecoveryDatabase recovery = new RecoveryDatabase(RecoveryVersion.LastRun); if (recovery.ItemsExist()) { MessageBar msgBar = new MessageBar(); msgBar.Title = "RECOVERY"; msgBar.Message = "Daytimer shut down unexpectedly. We recovered your work, and need you to confirm what we should keep."; msgBar.ButtonText = "_View Items"; msgBar.Icon = new BitmapImage(new Uri("pack://application:,,,/Daytimer.Images;component/Images/info_mdm.png", UriKind.Absolute)); msgBar.Closed += (m, args) => { Close(msgBar); }; msgBar.ButtonClick += (b, args) => { Autorecover recover = new Autorecover(); recover.Owner = this; if (recover.ShowDialog() == true) { foreach (DatabaseObject each in recover.SelectedItems) { if (each is Appointment) { RecoverAppointment(each as Appointment); } else if (each is Contact) { RecoverContact(each as Contact); } else if (each is UserTask) { RecoverTask(each as UserTask); } } if (!recovery.ItemsExist()) { msgBar.Close(); } } }; messageBar.Children.Add(msgBar); UpdateMessageBarVisibility(); } }
private void QuoteDatabase_OnSaveCompletedEvent(object sender, EventArgs e) { Dispatcher.BeginInvoke(() => { MainWindow window = (MainWindow)MainWindow; window.ShowStatus("SAVING AUTORECOVER INFORMATION..."); RecoveryDatabase recovery = new RecoveryDatabase(RecoveryVersion.Current); recovery.RecoveryAppointment = window.LiveAppointment; recovery.RecoveryContact = window.LiveContact; recovery.RecoveryTask = window.LiveTask; window.ShowStatus("DATABASE SAVED"); }); }
private async void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { // We don't want to overwhelm the user with multiple error dialogs. However, // we will still log the error for debugging purposes. if (_isErrorDialogShowing) { e.Handled = true; await Task.Factory.StartNew(() => { Log(e.Exception); }); return; } _isErrorDialogShowing = true; try { // We handle our own errors, so that we can write error logs // and attempt application recovery. e.Handled = true; if (e.Exception is NotImplementedException) { TaskDialog td = new TaskDialog(MainWindow, "Not Implemented", !string.IsNullOrEmpty(e.Exception.Message) ? e.Exception.Message : "This isn't hooked up yet. Check for updates and try again.", MessageType.Error); td.ShowDialog(); _isErrorDialogShowing = false; return; } await Task.Factory.StartNew(() => { Log(e.Exception); }); // Try and save the databases, but we still place this in a catch // in case an error in the database caused the crash. bool saveError = false; await Task.Factory.StartNew(() => { try { AppointmentDatabase.Save(); } catch { saveError = true; } }); if (saveError) { saveError = false; await Task.Factory.StartNew(() => { try { ContactDatabase.Save(); } catch { saveError = true; } }); } if (saveError) { saveError = false; await Task.Factory.StartNew(() => { try { TaskDatabase.Save(); } catch { saveError = true; } }); } if (saveError) { saveError = false; try { ((MainWindow)MainWindow).SaveNotesView(); } catch { } await Task.Factory.StartNew(() => { try { NoteDatabase.Save(); } catch { saveError = true; } }); } if (saveError) { saveError = false; await Task.Factory.StartNew(() => { try { SyncDatabase.Save(); } catch { saveError = true; } }); } if (saveError) { saveError = false; await Task.Factory.StartNew(() => { try { QuoteDatabase.Save(); } catch { saveError = true; } }); } if (saveError) { try { // Autorecover RecoveryDatabase recovery = new RecoveryDatabase(RecoveryVersion.LastRun); MainWindow window = (MainWindow)MainWindow; try { recovery.RecoveryAppointment = window.LiveAppointment; } catch { } try { recovery.RecoveryContact = window.LiveContact; } catch { } try { recovery.RecoveryTask = window.LiveTask; } catch { } } catch { } } try { new RecoveryDatabase(RecoveryVersion.Current).Delete(); } catch { } if (MainWindow != null) { try { ((MainWindow)MainWindow).SaveSettings(); } catch { } } // Try and show an error message, but again we still place this in a catch // in case an error in the dialog caused the crash. try { Error error = new Error(null, e.Exception); if (error.ShowDialog() == true) { Feedback f = new Feedback(FeedbackType.Error, e.Exception.ToString()); if (MainWindow != null && MainWindow.IsLoaded) { f.Owner = MainWindow; } else { f.WindowStartupLocation = WindowStartupLocation.CenterScreen; } f.ShowDialog(); } else if (error.IgnoreError) { _isErrorDialogShowing = false; return; } } catch { if (Settings.JoinedCEIP) { MessageBox.Show("Oops...\r\n\r\n" + e.Exception.ToString(), GlobalAssemblyInfo.AssemblyName + " Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show("Oops...\r\n\r\n" + e.Exception.Message, GlobalAssemblyInfo.AssemblyName + " Error", MessageBoxButton.OK, MessageBoxImage.Error); } } // Restart Dimension 4 ProcessStartInfo restartInfo = new ProcessStartInfo(Process.GetCurrentProcess().MainModule.FileName, "/nosingleinstance"); restartInfo.UseShellExecute = true; Process.Start(restartInfo); #if DEBUG Debug.WriteLine(e.Exception.ToString()); #endif Shutdown(-1); } catch { } }