/// <summary> /// Выполняет запрос на восстановление файловой системы /// </summary> /// <returns></returns> public bool RestoreFileSystem(out StateApplication state) { var result = MessageBoxHellpers.Questions("Восстанвоить файловую систему ?"); switch (result) { case System.Windows.MessageBoxResult.None: break; case System.Windows.MessageBoxResult.OK: break; case System.Windows.MessageBoxResult.Cancel: JournalFileSystemController.AddInfo("Восстановление файловой системы отменено"); break; case System.Windows.MessageBoxResult.Yes: this.ClearFileSystem(); this.backup.Restore(this.filesList); foreach (var file in this.filesList) { this.Save(file); } JournalFileSystemController.AddInfo("Сессия файловой системы успешно восстановлена"); break; case System.Windows.MessageBoxResult.No: JournalFileSystemController.AddInfo("Предыдущая версия файловой системы очищена"); this.ClearFileSystem(); this.backup.ClearFileSystem(); break; default: break; } if (MessageBoxHellpers.Questions("Восстанвоить предыдущую сессию приложения ?") == System.Windows.MessageBoxResult.Yes) { if (this.backup.RestoreState(out state)) { JournalFileSystemController.AddInfo("Сессию приложения успешно установлена"); return(true); } else { JournalFileSystemController.AddInfo("Сессию приложения не удалось восстанвоить"); return(false); } } else { JournalFileSystemController.AddInfo("Предыдущая сессия приложения отменена"); state = null; return(false); } }
/// <summary> /// Сохраняет состояние приложения /// </summary> private void SaveState() { StateApplication state = new StateApplication { file = new FileModel() { fileName = this.NameFileTb.Text, body = (new TextRange(this.BodyFileRtb.Document.ContentStart, this.BodyFileRtb.Document.ContentEnd)).Text }, IsNewFile = this.NameFileTb.IsEnabled }; this.FileSystem.SaveState(state); }
public bool SaveState(StateApplication state) { try { XmlSerializer serializer = new XmlSerializer(state.GetType()); using (StreamWriter sw = new StreamWriter(Path.Combine(this.path, StateApplication.fileName))) { serializer.Serialize(sw, state); } return(true); } catch (Exception exc) { MessageBoxHellpers.Error($"Исключение {nameof(FileSystemController)}.SaveState", exc.Message); } return(false); }
/// <summary> /// Восстанавливает состояние приложение из xml файла состояний /// </summary> /// <param name="state"></param> public bool RestoreState(out StateApplication state) { try { XmlSerializer serializer = new XmlSerializer(typeof(StateApplication)); using (StreamReader sr = new StreamReader(Path.Combine(this.path, StateApplication.fileName))) { state = (StateApplication)serializer.Deserialize(sr); } return(true); } catch (Exception exc) { MessageBoxHellpers.Error($"Исключение {nameof(FileSystemController)}.SaveState", exc.Message); } state = null; return(false); }
public void SaveState(StateApplication state) => this.backup.SaveState(state);