Example #1
0
        public void RunMethodWithEachTimeAndGetTheMostCommonSeries(MethodInfo action, int count, Enums.TypesOfDrawn typesOfDrawn)
        {
            if (LotteryModels == null)
            {
                LotteryModels = new List <LotteryModel>();
            }
            Dictionary <string, int> numbersDictionary = new Dictionary <string, int>();

            Console.WriteLine($"{typesOfDrawn} {count} Times");
            int index = 0;

            while (index != count)
            {
                LotteryModel returnedModel = (LotteryModel)action.Invoke(this, null);
                if (returnedModel == null || !returnedModel.ValidationTuple().Item1)
                {
                    continue;
                }

                index++;

                if (numbersDictionary.Count > 0 && numbersDictionary.ContainsKey(returnedModel.ToString()))
                {
                    numbersDictionary[returnedModel.ToString()]++;
                }
                else
                {
                    numbersDictionary.Add(returnedModel.ToString(), 1);
                }
            }

            KeyValuePair <string, int> sortedDic = numbersDictionary.OrderByDescending(x => x.Value).ToList()[0];
            LotteryModel resultLotteryModel      = new LotteryModel(lotteryRule);
            var          numbers = sortedDic.Key.Split(", ");

            foreach (string number in numbers)
            {
                resultLotteryModel.Numbers.Add(Convert.ToInt32(number));
            }


            if (LotteryModels.AddValueWithDetailsAndValidation(resultLotteryModel.ValidationTuple(), typesOfDrawn, Enums.GenerateType.MostCommonSeries))
            {
                OnLotteryModelEvent(resultLotteryModel);
            }
        }