Esempio n. 1
0
        public string GetPropertyFromPropertyType(string propertyType, Pao pao)
        {
            switch (propertyType)
            {
            case nameof(Pao.Action):
                return(pao.Action);

            case nameof(Pao.Number):
                return(pao.Number);

            case nameof(Pao.Object):
                return(pao.Object);

            case nameof(Pao.Person):
                return(pao.Person);

            default:
                return(String.Empty);
            }
        }
Esempio n. 2
0
        public bool IsPropertyPartOfPao(string property, string propertyType, Pao pao)
        {
            bool result = false;

            switch (propertyType)
            {
            case nameof(pao.Action):
                if (String.Compare(pao.Action, property, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    result = true;
                }
                break;

            case nameof(pao.Number):
                if (String.Compare(pao.Number, property, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    result = true;
                }
                break;

            case nameof(pao.Object):
                if (String.Compare(pao.Object, property, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    result = true;
                }
                break;

            case nameof(pao.Person):
                if (String.Compare(pao.Person, property, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    result = true;
                }
                break;
            }

            return(result);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //var repository = new DummyPaosRepository();
            var           repository = new XmlPaosRepository(AppDomain.CurrentDomain.BaseDirectory + "/DataForDrill/PaosList.xml");
            var           paoService = new PaoService(repository);
            int           requestedNumberOfQuestions;
            int           remainingNumberOfQuestions;
            var           paos = new List <Pao>();
            List <string> propertyTypesToTest;

            Console.WriteLine("How many questions do you want? (default is as many questions as you want!)");
            if (!(int.TryParse(Console.ReadLine(), out requestedNumberOfQuestions)))
            {
                Console.WriteLine("Default defined: as many as you want!");
                requestedNumberOfQuestions = 10000;
            }

            Console.WriteLine("Which information do you want I give you?");
            DisplayAvailableChoices("x");

            string givenPropertyType;
            var    givenInformationChoice = Console.ReadKey().Key.ToString();

            Console.WriteLine();
            givenPropertyType = paoService.GetPropertyTypeFromFirstLetter(givenInformationChoice);

            Console.WriteLine("Do you want to be questioned on all the different properties (default, [y]) or only one [n]?");
            var questionOnAllProperties = Console.ReadKey().Key.ToString();

            if (String.Compare(questionOnAllProperties, "n", true) == 0)
            {
                Console.WriteLine("Which information do you want to give?");
                DisplayAvailableChoices(givenInformationChoice);
                var informationToGiveChoice = Console.ReadKey().Key.ToString();
                Console.WriteLine();
                propertyTypesToTest = new List <string> {
                    paoService.GetPropertyTypeFromFirstLetter(informationToGiveChoice)
                };
            }
            else
            {
                propertyTypesToTest = paoService.GetListOfPropertyTypesToAsk(givenPropertyType);
            }

            string answer         = givenInformationChoice;
            int    totalQuestions = 0;
            int    goodAnswers    = 0;
            int    partialGoodAnswers;

            remainingNumberOfQuestions = requestedNumberOfQuestions;
            while (remainingNumberOfQuestions > 0)
            {
                totalQuestions++;
                remainingNumberOfQuestions--;
                partialGoodAnswers = 0;

                Pao randomPao = paoService.GetRandomPao();
                foreach (string propertyType in propertyTypesToTest)
                {
                    Console.WriteLine($"{totalQuestions}) What is the {propertyType.ToLower()} for the {givenPropertyType.ToLower()} \"{paoService.GetPropertyFromPropertyType(givenPropertyType, randomPao)}\"?");
                    answer = Console.ReadLine();
                    if (String.Compare(answer, "x", true) == 0)
                    {
                        remainingNumberOfQuestions = 0;
                        break;
                    }
                    else
                    {
                        if (paoService.IsPropertyPartOfPao(answer, propertyType, randomPao))
                        {
                            Console.WriteLine("Bravo!");
                            partialGoodAnswers++;
                        }
                        else
                        {
                            Console.WriteLine($"The wright answer was \"{paoService.GetPropertyFromPropertyType(propertyType, randomPao)}\".");
                        }
                    }
                }
                if (partialGoodAnswers == propertyTypesToTest.Count)
                {
                    goodAnswers++;
                }
                Console.WriteLine();
            }

            if (String.Compare(answer, "x", true) == 0)
            {
                totalQuestions--;
            }
            Console.WriteLine();
            Console.WriteLine();
            if ((goodAnswers == totalQuestions) & goodAnswers > 0)
            {
                Console.WriteLine("Super! No error!");
            }
            Console.WriteLine($"{goodAnswers} good complete answer{(goodAnswers > 1 ? "s" : "")} out of {totalQuestions} question{(totalQuestions > 1 ? "s" : "")} (or group of questions).");
            Console.Read();
        }