///<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);
            }
        }
示例#2
0
        private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
        {
            if (this.FilesListBox.SelectedItem != null)
            {
                FileModel file = new FileModel();

                file.fileName = this.NameFileTb.Text;
                if (!string.IsNullOrEmpty(file.fileName))
                {
                    if (file.fileName != FileModel.DefaultFileName)
                    {
                        file.body = (new TextRange(this.BodyFileRtb.Document.ContentStart, this.BodyFileRtb.Document.ContentEnd)).Text;
                        if (FileSystem.Save(file))
                        {
                            JournalFileSystemController.AddInfo($"Файл {file.ToString()} успешно сохранён");
                        }
                        else
                        {
                            JournalFileSystemController.AddInfo($"Файл {file.ToString()} не сохранён");
                        }
                    }
                    else
                    {
                        MessageBoxHellpers.Error("Ошибка", "Недопустимое имя файла");
                    }
                }
                else
                {
                    MessageBoxHellpers.Error("Ошибка", "Поле 'Имя файла' обязательно для заполнения !");
                }
            }
        }
        /// <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()}");
            }
        }
示例#5
0
        ///<inheritdoc/>
        public override bool Save(FileModel file)
        {
            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);
        }
示例#6
0
        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);
        }
示例#7
0
        /// <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);
        }
        ///<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);
        }
示例#9
0
        ///<inheritdoc/>
        public override void Load()
        {
            try
            {
                DirectoryInfo directory = new DirectoryInfo(this.path);

                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
                    };

                    this.filesBackupList.Add(fileModel);
                }
            }
            catch (Exception exc)
            {
                MessageBoxHellpers.Error("Ошибка", exc.Message);
            }
        }