public FileReaderService(string url, ToAnimalParser animalParser)
 {
     _url = url;
     _animalParser = animalParser;
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                string         url           = @"ZooInfo.txt";
                ZooPark        zoo           = new ZooPark();
                IGetService    getService    = new GetConsole();
                INotifyService notifyService = new NotifyConsole();

                Dictionary <string, IParser> dict = new Dictionary <string, IParser>();
                dict.Add("Chiken", new ToChikenParser());
                dict.Add("Stork", new ToStorkParser());
                dict.Add("Wolf", new ToWolfParser());
                dict.Add("Tiger", new ToTigerParser());
                dict.Add("Cat", new ToCatParser());
                dict.Add("Dog", new ToDogParser());
                ToAnimalParser toAnimalParser = new ToAnimalParser(dict);


                Dictionary <string, IFabric> fabrics = new Dictionary <string, IFabric>();
                fabrics.Add("1", new GetChiken(getService, notifyService));
                fabrics.Add("2", new GetStork(getService, notifyService));
                fabrics.Add("3", new GetWolf(getService, notifyService));
                fabrics.Add("4", new GetTiger(getService, notifyService));
                fabrics.Add("5", new GetCat());
                fabrics.Add("6", new GetDog(getService, notifyService));

                Dictionary <string, ICommand> commands = new Dictionary <string, ICommand>();
                commands.Add("stop", new StopCommand());
                commands.Add("1", new AddAnimalCommand(zoo, new AnimalFabric(fabrics, getService, notifyService)));
                commands.Add("2", new DeleteCommand(zoo, notifyService, getService));
                commands.Add("3", new InfoCommand(zoo, notifyService, getService));
                commands.Add("4", new InfoAllComand(zoo));
                commands.Add("5", new SoundCommand(zoo, notifyService, getService));
                commands.Add("6", new SoundAllCommand(zoo));
                commands.Add("7", new GetZooCommand(zoo, new FileReaderService(url, toAnimalParser)));
                commands.Add("8", new SaveCommand(zoo, new FileWriterService(url)));
                Menu menu = new Menu(commands);

                string variant = "";
                menu.Choose("7");
                do
                {
                    PrintMenu();
                    variant = Console.ReadLine();
                    Console.Clear();
                    if (menu.IsThere(variant))
                    {
                        Console.WriteLine(menu.Choose(variant));
                    }
                    else
                    {
                        Console.WriteLine("Неверный ввод");
                    }
                } while (variant != "stop");
            }
            catch (Exception a)
            {
                Console.WriteLine(a.Message);
            }
        }