Exemplo n.º 1
0
        ///<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);
            }
        }
Exemplo n.º 2
0
        ///<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);
        }
Exemplo n.º 3
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);
            }
        }