/// <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); } }
///<inheritdoc/> public override bool Save(FileModel file) { Thread.Sleep(FileSystemController.timeOperation); if (IsFileExist(Path.Combine(this.path, $"{file.fileName}{file.extension}"))) { var result = MessageBoxHellpers.Questions("Файл с данным именем уже существует, вы уверены, что хотите перезаписать данные в нём ?"); switch (result) { case System.Windows.MessageBoxResult.Cancel: return(false); case System.Windows.MessageBoxResult.Yes: break; case System.Windows.MessageBoxResult.No: FileSystemHellpers.SetOriginalFileName(this.path, file); break; default: break; } } try { using (StreamWriter sw = new StreamWriter(Path.Combine(this.path, $"{file.fileName}{file.extension}"))) { sw.Write(file.body); } return(true); } catch (Exception exc) { MessageBoxHellpers.Error($"Исключение {nameof(FileSystemController)}.Save", exc.Message); } return(false); }