コード例 #1
0
 public void Excecute(MangaInfo manga, string value)
 {
     _actionCommand?.Invoke(manga, RegexPattern.Match(value));
 }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.Title = "ReadMangaDownloader";
            MangaInfo manga;

            while (true)
            {
                int index = 1;
                ShowMessage($"Доступные источники:\n");
                foreach (string item in _webSites)
                {
                    ShowMessage($"{index++}", ConsoleColor.Yellow);
                    ShowMessage($" - {item}\n");
                }
                ShowMessageLine("Выберите источник: ", ConsoleColor.Cyan);
                string webSiteIndex = Console.ReadLine();

                if (int.TryParse(webSiteIndex, out int select_index) &&
                    select_index <= _webSites.Count && select_index >= 1)
                {
                    _rootUrl      = _webSites[select_index - 1] + "/";
                    Console.Title = _webSites[select_index - 1];;
                }
                else
                {
                    ShowMessage("Неккоректный ввод!\n", ConsoleColor.Red);
                    continue;
                }

                while (true)
                {
                    string command;
                    string url = string.Empty;

                    ShowMessageLine($"Введите URL адрес: \n", ConsoleColor.Cyan);
                    ShowMessageLine(_rootUrl);
                    command = Console.ReadLine();

                    if (Regex.IsMatch(command, @"^return\s+/c\s*$"))
                    {
                        break;
                    }
                    else if (Regex.IsMatch(command, @"^[^/]+$"))
                    {
                        if (Regex.IsMatch(command, @"https:\/\/[a-zA-Z0-9]+\.[A-Za-z]+\/.+ "))
                        {
                            url = command;
                        }
                        else
                        {
                            url = _rootUrl + command;
                        }
                    }
                    else
                    {
                        ShowMessage("Неккоректный ввод\n", ConsoleColor.Red);
                        continue;
                    }

                    try
                    {
                        ShowMessage("Загрузка...", ConsoleColor.Green);
                        manga = new MangaInfo(url);
                        manga.GetChapters();

                        while (true)
                        {
                            ShowMessageLine($"\n{url}/", ConsoleColor.Cyan);
                            command = Console.ReadLine();

                            if (command == "commands")
                            {
                                ShowCommandsList();
                            }
                            else if (command == "return")
                            {
                                break;
                            }
                            else
                            {
                                bool isTitleCommand = false;
                                foreach (Command cmd in _titleCommands)
                                {
                                    if (cmd.IsThisCommand(command))
                                    {
                                        cmd.Excecute(manga, command);
                                        isTitleCommand = true;
                                        break;
                                    }
                                }
                                if (!isTitleCommand)
                                {
                                    ShowMessage("Неизвестная комманда!\n", ConsoleColor.Red);
                                    ShowCommandsList();
                                }
                            }
                        }
                    }

                    catch (Exception e)
                    {
                        ShowMessageLine(e.Message + "\n", ConsoleColor.Red);
                    }
                }
            }
        }