Exemplo n.º 1
0
        public void Handle(AutoSaveRecoveryEvent message)
        {
            _autoSaveRecoveryIndex = message.AutoSaveMasterIndex;

            if (!message.RecoveryInProgress)
            {
                // if auto save recovery is not already in progress
                // prompt the user for which files should be recovered
                var autoSaveRecoveryDialog = new AutoSaveRecoveryDialogViewModel();

                var filesToRecover = message.AutoSaveMasterIndex.Values.Where(i => i.ShouldRecover && i.IsCurrentVersion).SelectMany(entry => entry.Files);

                if (filesToRecover.Count() == 0)
                {
                    // if there are no files to recover then clean up
                    // the recovery folder and exit here
                    AutoSaver.CleanUpRecoveredFiles();
                    return;
                }

                autoSaveRecoveryDialog.Files = new ObservableCollection <AutoSaveIndexEntry>(filesToRecover);

                _windowManager.ShowDialogBox(autoSaveRecoveryDialog, settings: new Dictionary <string, object>
                {
                    { "WindowStyle", WindowStyle.None },
                    { "ShowInTaskbar", false },
                    { "ResizeMode", ResizeMode.NoResize },
                    { "Background", System.Windows.Media.Brushes.Transparent },
                    { "AllowsTransparency", true }
                });

                if (autoSaveRecoveryDialog.Result != OpenDialogResult.Cancel)
                {
                    message.RecoveryInProgress = true;

                    var fileToOpen = _autoSaveRecoveryIndex.Values.Where(i => i.ShouldRecover).FirstOrDefault().Files.Where(x => x.ShouldOpen).FirstOrDefault();

                    if (fileToOpen != null)
                    {
                        // the first file will mark itself as opened then re-publish the message
                        // to open the next file (if there is one)
                        RecoverAutoSaveFile(fileToOpen);
                    }
                }
                else
                {
                    // if recovery has been cancelled open a new blank document
                    NewQueryDocument("");
                    // and remove unwanted recovery files
                    AutoSaver.CleanUpRecoveredFiles();
                }
            }

            // TODO - maybe move this to a RecoverNextFile message and store the files to recover in a private var
            //        then at the end of the ViewLoaded event we can trigger this event and run code like the
            //        section below
        }
Exemplo n.º 2
0
        public void Handle(RecoverNextAutoSaveFileEvent message)
        {
            var fileToOpen = _autoSaveRecoveryIndex.Values.Where(i => i.ShouldRecover).FirstOrDefault().Files.Where(x => x.ShouldOpen).FirstOrDefault();

            if (fileToOpen != null)
            {
                // the first file will mark itself as opened then re-publish the message
                // to open the next file (if there is one)
                RecoverAutoSaveFile(fileToOpen);
            }
            else
            {
                // if no files have been opened open a new blank document
                if (Items.Count == 0)
                {
                    OpenNewBlankDocument(null);
                }

                AutoSaver.CleanUpRecoveredFiles();

                // Now that any files have been recovered start the auto save timer
                _eventAggregator.PublishOnUIThreadAsync(new StartAutoSaveTimerEvent());
            }
        }