Ejemplo n.º 1
0
        private void SetSelector()
        {
            ConsoleExt.WriteLine($" Файл для обработки: {_filePath}\n", ConsoleColor.DarkGray);
            ConsoleExt.WriteLine("\n Как поступить дальше? Выберите пожалуйста следующее действие:\n");
            ConsoleExt.WriteSelect(1);
            ConsoleExt.Write("Удалить символ;\n");
            ConsoleExt.WriteSelect(2);
            ConsoleExt.Write("Удалить строку;\n");
            ConsoleExt.WriteSelect(3);
            ConsoleExt.Write("Вывести каждое 10-ое слово + инфа;\n");
            ConsoleExt.WriteSelect(4);
            ConsoleExt.Write("Реверс третьего предложения;\n");
            ConsoleExt.WriteSelect(0);
            ConsoleExt.Write("Выйти из приложения.\n", ConsoleColor.DarkCyan);

            try
            {
                switch (int.Parse(Console.ReadKey().KeyChar.ToString()))
                {
                case 0:
                    ConsoleExt.Clear();
                    break;

                case 1:
                    deleteSymbol.EditSymbol(1, _filePath);
                    SelectWork();
                    break;

                case 2:
                    deleteSymbol.EditSymbol(2, _filePath);
                    SelectWork();
                    break;

                case 3:
                    infoText.GetInfo(_filePath);
                    SelectWork();
                    break;

                case 4:
                    reverceText.Reverce(_filePath);
                    SelectWork();
                    break;

                default:
                    ConsoleExt.Clear();
                    ConsoleExt.WriteLine(" Пожалуйста, выберите из списка.", ConsoleColor.Yellow);
                    SetSelector();
                    break;
                }
            }
            catch
            {
                ConsoleExt.Clear();
                ConsoleExt.WriteLine(" Пожалуйста, воспользуйтесь цифрами. :)", ConsoleColor.Yellow);
                SetSelector();
            }
        }
Ejemplo n.º 2
0
        public void ShowList()
        {
            foreach (var finder in resultList)
            {
                ConsoleExt.WriteSelect(finder.Id);
                switch (finder.Type)
                {
                case "Dir ":
                    ConsoleExt.Write($"|{ finder.Type}", ConsoleColor.DarkGray);
                    break;

                case "File":
                    ConsoleExt.Write($"|{ finder.Type}", ConsoleColor.DarkCyan);
                    break;
                }
                Console.Write($"| {finder.Name}\n");
            }

            try
            {
                int sel    = int.Parse(Console.ReadLine());
                var result = resultList[sel - 1];
                switch (result.Type)
                {
                //Конструктор пути к файлу
                case "Dir ":
                    _fileCreatePath += result.Name + "/";
                    fileList.Clear();
                    dirList.Clear();
                    resultList.Clear();
                    BeginSteps();
                    break;

                case "File":
                    _fileCreatePath += result.Name;
                    Console.Clear();
                    Console.Write($"{_fileCreatePath}\n");
                    SelectTextWork _textWork = new SelectTextWork(_fileCreatePath);
                    _textWork.SelectWork();
                    break;
                }
            }
            catch
            {
                Console.WriteLine("Error in ShowList");
                Console.ReadLine();
            }
        }
Ejemplo n.º 3
0
        public static void Backup(string filepath)
        {
            FileInfo original = new FileInfo(filepath);
            FileInfo backup   = new FileInfo(Constants.BackupPath);

            try
            {
                using (FileStream fs = backup.Create()) { } //источник
                if (File.Exists(Constants.BackupPath))
                {
                    backup.Delete();
                }                                                           //если существует то удалить :3

                //Копирование...
                original.CopyTo(Constants.BackupPath);
                ConsoleExt.Write($"\tКопия создана в корневой папке (*{Constants.BackupPath})\n ", ConsoleColor.DarkGray);
            }
            catch (IOException e)
            {
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("\n Скорее всего не существует файл, но на всякий\n ERROR:\n\n", e);
                Console.Read();
            }
        }
Ejemplo n.º 4
0
        private void UserIteraction(string textFile, int id)
        {
            ConsoleExt.Write("\n Какой символ удалить из файла?\n Символ: ", ConsoleColor.Yellow);
            try
            {
                string x      = null;
                string choice = null;
                if (id == 1)
                {
                    char x1 = Console.ReadKey().KeyChar;
                    x      = Convert.ToString(x1);
                    choice = "Символ";
                    if (textFile.Contains(x))
                    {
                        textFile = Regex.Replace(textFile, $@"[{x}]", "");
                    }
                    else
                    {
                        ConsoleExt.WriteLine("\n Увы, но такого символа уже нет с нами... ", ConsoleColor.Cyan);
                    }
                }
                if (id == 2)
                {
                    string x2 = Console.ReadLine();
                    x        = x2; choice = "Слово";
                    textFile = textFile.Replace(x2, "");
                }

                FileTextWriter.Save(_filePath, textFile);
                ConsoleExt.WriteLine($"\n{textFile}\n");
            }
            catch
            {
                ConsoleExt.WriteLine(" Ошибка при удалении символа", ConsoleColor.Magenta);
            }
        }