///<inheritdoc/> public override void Load() { try { DirectoryInfo directory = new DirectoryInfo(this.path); JournalFileSystemController journal = new JournalFileSystemController(); ObservableCollection <FileModel> currentFiles = new ObservableCollection <FileModel>(); foreach (var file in directory.GetFiles()) { var fileModel = new FileModel() { body = FileSystemHellpers.GetBodyFile(file.FullName), fileName = file.Name.Substring(0, file.Name.LastIndexOf('.')), extension = file.Extension }; currentFiles.Add(fileModel); journal.Add(fileModel, this.filesList); } journal.CheckDeleteFiles(this.filesList, currentFiles); FileSystemHellpers.UpdateFileList(this.filesList, journal); } catch (Exception exc) { MessageBoxHellpers.Error("Ошибка", exc.Message); } }
/// <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> /// <param name="fileName">Имя файла.</param> public void Delete(FileModel file) { JournalFileSystemController.AddInfo($"Начало удаление файла {file.ToString()}"); Thread.Sleep(FileSystemController.timeOperation); var path = Path.Combine(this.path, file.ToString()); if (IsFileExist(path)) { File.Delete(path); JournalFileSystemController.AddInfo($"Конец операции удаление файла {file.ToString()}"); } else { MessageBoxHellpers.Error("Ошибка", $"Файл с именем: {file.ToString()} не существует в дириктории {path}"); JournalFileSystemController.AddInfo($"Ошибка при удалении файла {file.ToString()}"); } }
/// <summary> /// Сохраняет текущую сессию в backup /// </summary> public void SaveSession() { this.backup.ClearFileSystem(); this.backup.SaveAll(this.filesList); JournalFileSystemController.AddInfo("Сессия сохранена"); }