Beispiel #1
0
        static void Main(string[] args)
        {
            string     password, answer;
            Searchable category;

            //check password
            do
            {
                Console.Write("Password: "******"Password: "******"Password correct!");
            GreetTheUser();

            //TODO: make it less ugly pls
            //main program loop
            while (!EXIT)
            {
                do
                {
                    Console.WriteLine($"What are you looking for?");
                    Console.WriteLine("[c] - character");
                    Console.WriteLine("[l] - location");
                    Console.Write(SHELL_TEXT);
                    answer = Console.ReadLine().Replace(SHELL_TEXT, string.Empty);
                    if (answer.ToLower().Equals("c"))
                    {
                        category = Searchable.Character;
                    }
                    else if (answer.ToLower().Equals("l"))
                    {
                        category = Searchable.Location;
                    }
                    else if (answer.ToLower().Equals("exit"))
                    {
                        EXIT     = true;
                        category = Searchable.ABANDON;
                    }
                    else
                    {
                        category = Searchable.Null;
                    }
                } while (category.Equals(Searchable.Null));

                if (EXIT)
                {
                    continue;
                }
                //get filters
                Dictionary <string, string> filters = GetUserDefinedFilters(category);

                Console.WriteLine("Search pending...");

                Search_ search = SearchBuilder.Init()
                                 .WithSearchCategory(category)
                                 .WithSearchFilters(filters)
                                 .Build();
                try
                {
                    List <dynamic> results = search.GetResult();
                    if (category.Equals(Searchable.Character))
                    {
                        List <Character> characters = new List <Character>();
                        foreach (var result in results)
                        {
                            Character character = CharacterBuilder.Init()
                                                  .WithName(result.name)
                                                  .WithStatus(result.status)
                                                  .OfGender(result.gender)
                                                  .From(result.origin.name)
                                                  .SpeciesOf(result.species)
                                                  .PlayedIn((ushort)result.episode.Count)
                                                  .LastSeenAt(result.location.name)
                                                  .Build();
                            characters.Add(character);
                        }
                        _ = new PDFCreator($"characters.pdf", characters);
                        Console.WriteLine("Enjoy your results, nerd!\n");
                    }
                    else
                    {
                        List <Location> locations = new List <Location>();
                        foreach (var result in results)
                        {
                            Location location = LocationBuilder.Init()
                                                .WithName(result.name)
                                                .FromDimension(result.dimension)
                                                .OfType(result.type)
                                                .WithThatManyResidents((ushort)result.residents.Count)
                                                .Build();
                            locations.Add(location);
                        }
                        _ = new PDFCreator($"locations.pdf", locations);
                    }
                }
                catch (System.Net.Http.HttpRequestException)
                {
                    Console.WriteLine("There were no results for the search with your filters. Try again or exit. \n");
                }
            }
            Console.WriteLine("Thanks for using the app!");
        }