Exemple #1
0
        /// <summary>
        /// The run method with each time.
        /// </summary>
        /// <param name="invoke">
        /// The invoke.
        /// </param>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <param name="typesOfDrawn">
        /// The t drawn.
        /// </param>
        private void RunMethodWithEachTime(MethodInfo invoke, int count, Enums.TypesOfDrawn typesOfDrawn)
        {
            if (LotteryModels == null)
            {
                LotteryModels = new List <LotteryModel>();
            }
            Console.WriteLine(typesOfDrawn.ToString());
            int index = 0;

            while (true)
            {
                var returnedModel = (LotteryModel)invoke.Invoke(this, null);

                if (returnedModel == null)
                {
                    continue;
                }
                if (LotteryModels.AddValueWithDetailsAndValidation(returnedModel.ValidationTuple(), typesOfDrawn))
                {
                    index++;
                    OnLotteryModelEvent(returnedModel);
                }
                else
                {
                    continue;
                }

                if (index == count)
                {
                    break;
                }
            }
        }
        /// <summary>
        /// The run method with each time.
        /// </summary>
        /// <param name="invoke">
        /// The invoke.
        /// </param>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <param name="typesOfDrawn">
        /// The t drawn.
        /// </param>
        private void RunMethodWithEachTime(MethodInfo invoke, int count, Enums.TypesOfDrawn typesOfDrawn)
        {
            if (LotteryModels == null)
            {
                LotteryModels = new List <LotteryModel>();
            }
            Console.WriteLine(typesOfDrawn.ToString());
            int index        = 0;
            int errorCounter = 0;
            int skipRutinWhenReachThisNumber = 200;

            while (true)
            {
                var returnedModel = (LotteryModel)invoke.Invoke(this, null);
                if (skipRutinWhenReachThisNumber == errorCounter)
                {
                    Console.WriteLine("You cant genreate numbers with this method, because numbers dosent right for it");
                    break;
                }

                if (returnedModel == null)
                {
                    errorCounter++;
                    continue;
                }

                if (LotteryModels.AddValueWithDetailsAndValidation(returnedModel.ValidationTuple(), typesOfDrawn))
                {
                    index++;
                    OnLotteryModelEvent(returnedModel);
                }
                else
                {
                    continue;
                }

                if (index == count)
                {
                    break;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// The use earlier week percentage for numbers draw.
        /// </summary>
        /// <param name="typesOfDrawn">
        /// The t drawn.
        /// </param>
        public void UseEarlierWeekPercentageForNumbersDraw(Enums.TypesOfDrawn typesOfDrawn)
        {
            List <SaveNumber> getLotteryDrawing = this.SaveNumbers.Where(x => x.WeekOfPull == this.lotteryCollection.Last().WeekOfLotteryDrawing).ToList();

            //if (getLotteryDrawing.Count == 0)
            //{
            //    throw new InvalidOperationException("You haven't earlier week result");
            //}

            if (LotteryModels == null)
            {
                throw new InvalidOperationException("You didn't generate numbers from which I can calculate");
            }
            Console.WriteLine("Calculated From earlier week");

            var lmt = LotteryModels.Clone();

            foreach (LotteryModel lotteryModel in lmt)
            {
                foreach (SaveNumber saveNumber in getLotteryDrawing)
                {
                    LotteryModel lm = new LotteryModel(lotteryRule);
                    if (saveNumber.Message != lotteryModel.Message)
                    {
                        continue;
                    }
                    for (int i = 0; i < lotteryRule.PiecesOfDrawNumber; i++)
                    {
                        double calculatedNumber =
                            lotteryModel.Numbers[i] * saveNumber.DifferentInPercentage[i];
                        lm.Numbers.Add((int)calculatedNumber);
                    }

                    LotteryModels.AddValueWithDetailsAndValidation(lm.ValidationTuple(), typesOfDrawn);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// The run method with each time and get the best numbers.
        /// </summary>
        /// <param name="action">
        /// The action.
        /// </param>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <param name="typesOfDrawn">
        /// The t drawn.
        /// </param>
        public void RunMethodWithEachTimeAndGetTheBestNumbers(MethodInfo action, int count, Enums.TypesOfDrawn typesOfDrawn)
        {
            if (LotteryModels == null)
            {
                LotteryModels = new List <LotteryModel>();
            }
            Dictionary <int, int> numbersDictionary = new Dictionary <int, 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++;
                foreach (var returnedModelNumber in returnedModel.Numbers)
                {
                    if (numbersDictionary.Count > 0 && numbersDictionary.ContainsKey(returnedModelNumber))
                    {
                        numbersDictionary[returnedModelNumber]++;
                    }
                    else
                    {
                        numbersDictionary.Add(returnedModelNumber, 1);
                    }
                }
            }

            var          sortedDic          = numbersDictionary.OrderByDescending(x => x.Value).Take(lotteryRule.PiecesOfDrawNumber);
            LotteryModel resultLotteryModel = new LotteryModel(lotteryRule);

            foreach (KeyValuePair <int, int> keyValuePair in sortedDic)
            {
                resultLotteryModel.Numbers.Add(keyValuePair.Key);
            }

            if (LotteryModels.AddValueWithDetailsAndValidation(resultLotteryModel.ValidationTuple(), typesOfDrawn))
            {
                OnLotteryModelEvent(resultLotteryModel);
            }
        }
Exemple #5
0
        /// <summary>
        /// The calculate numbers.
        /// </summary>
        /// <param name="typesOfDrawn">
        /// The t drawn.
        /// </param>
        /// <param name="generateType">
        /// The generate type.
        /// </param>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// </exception>
        public void CalculateNumbers(Enums.TypesOfDrawn typesOfDrawn, Enums.GenerateType generateType, int count)
        {
            // Get the method information using the method info class
            MethodInfo mi = this.GetType().GetMethod(typesOfDrawn + "Execute");

            switch (typesOfDrawn)
            {
            case Enums.TypesOfDrawn.ByInterval:
            case Enums.TypesOfDrawn.ByOccurrence:
            case Enums.TypesOfDrawn.ByAverageSteps:
            case Enums.TypesOfDrawn.ByAverageRandoms:
            case Enums.TypesOfDrawn.BySums:
            case Enums.TypesOfDrawn.Calculated:
                switch (generateType)
                {
                case Enums.GenerateType.EachByEach:
                    this.RunMethodWithEachTime(mi, count, typesOfDrawn);
                    break;

                case Enums.GenerateType.GetTheBest:
                    this.RunMethodWithEachTimeAndGetTheBestNumbers(mi, count, typesOfDrawn);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(generateType), generateType, null);
                }

                break;

            case Enums.TypesOfDrawn.All:
                foreach (Enums.TypesOfDrawn drawn in (Enums.TypesOfDrawn[])Enum.GetValues(typeof(Enums.TypesOfDrawn)))
                {
                    MethodInfo mis = this.GetType().GetMethod(drawn.ToString() + "Execute");
                    if (mis != null)
                    {
                        switch (generateType)
                        {
                        case Enums.GenerateType.EachByEach:
                            RunMethodWithEachTime(mis, count, drawn);
                            break;

                        case Enums.GenerateType.GetTheBest:
                            RunMethodWithEachTimeAndGetTheBestNumbers(mis, count, drawn);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(generateType), generateType, null);
                        }
                    }
                }

                break;

            case Enums.TypesOfDrawn.ByDistributionBasedCurrentDraw:
                switch (generateType)
                {
                case Enums.GenerateType.EachByEach:
                    break;

                case Enums.GenerateType.GetTheBest:
                    break;

                case Enums.GenerateType.Unique:
                    MethodInfo mis = this.GetType().GetMethod("CalcTheFiveMostCommonNumbers");
                    if (mis != null)
                    {
                        RunMethodWithEachTime(mis, count, typesOfDrawn);
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(generateType), generateType, null);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(typesOfDrawn), typesOfDrawn, null);
            }

            // Invoke the method
            // (null- no parameter for the method call
            // or you can pass the array of parameters...)
            if (mi != null)
            {
                mi.Invoke(this, null);
            }
        }
Exemple #6
0
        public static void AddValueWithDetails(this List <LotteryModel> theList, LotteryModel lm, Enums.TypesOfDrawn tDrawn, bool isShowNumberOnConsole = true)
        {
            lm.Message = tDrawn;
            theList.Add(lm);

            if (isShowNumberOnConsole)
            {
                Console.WriteLine(lm);
            }
        }
        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);
            }
        }