Beispiel #1
0
            public void Run()
            {
                ILifecycle lifecycle = PoultryEnum.Rabbit.GetLifecycle(PoultryList);

                for (DateTime date = StartDate; date <= EndDate; date = date.AddDays(CommonConstant._one))
                {
                    lifecycle.Date = date;
                    lifecycle.NextDay();
                }

                int femaleRabbitNumber = PoultryList.Where(condition => condition.isMale == false).Count();
                int maleRabbitNumber   = PoultryList.Count() - femaleRabbitNumber;

                Console.WriteLine("Dişi tavşan sayısı = {0}", femaleRabbitNumber);
                Console.WriteLine("Erkek tavşan sayısı = {0}", maleRabbitNumber);
                Console.Read();

                foreach (IPoultry poultry in PoultryList)
                {
                    RabbitProvider rabbitProvider = new RabbitProvider(poultry, EndDate);
                    Console.WriteLine(rabbitProvider.GetAge());
                }

                Console.ReadLine();
            }
        private void GiveBirth(IPoultry femalePoultry)
        {
            RabbitProvider rabbitValidator = new RabbitProvider(femalePoultry, Date);
            int            childLength     = rabbitValidator.GetNumberOffSpring();

            for (int i = 0; i < childLength; i++)
            {
                double randomValue = _random.NextDouble();

                Poultry child = new Poultry();
                if (randomValue > RabbitConstant.FemaleBirthRate)
                {
                    child.isMale = false;
                }
                else
                {
                    child.isMale = true;
                }

                child.isPregnant  = false;
                child.BirthDate   = Date;
                child.PoultryEnum = (int)PoultryEnum.Rabbit;
                _poultryList.Add(child);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 定时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            var list = DANQueue <User> .TryTakeAll();

            if (list.Count > 0)
            {
                RabbitProvider.Publish(ExchangeStr, QueueStr, TypeUserName, list);
            }
        }
        private void ImpregnateTheRabbit(IPoultry femalePoultry)
        {
            RabbitProvider rabbitValidator = new RabbitProvider(femalePoultry, Date);

            if (rabbitValidator.isPregnant() == true)
            {
                femalePoultry.isPregnant    = true;
                femalePoultry.PregnancyDate = Date;
            }
        }
        public void DeathOperation()
        {
            List <IPoultry> rabbitList = _poultryList.Where(condition => condition.PoultryEnum == (int)Enum.PoultryEnum.Rabbit).ToList();

            foreach (IPoultry poultry in rabbitList)
            {
                RabbitProvider rabbitValidator = new RabbitProvider(poultry, Date);

                if (_random.NextDouble() <= rabbitValidator.FindProbabilityDeath())
                {
                    _poultryList.Remove(poultry);
                }
            }
        }
        public void BirthOperation()
        {
            List <IPoultry> rabbitList        = _poultryList.Where(condition => condition.PoultryEnum == (int)Enum.PoultryEnum.Rabbit).ToList();
            List <IPoultry> femalePoultryList = rabbitList.Where(condition => condition.isMale == false).ToList();

            foreach (IPoultry femalePoultry in femalePoultryList)
            {
                RabbitProvider rabbitValidator = new RabbitProvider(femalePoultry, Date);
                if (rabbitValidator.isGiveBirth())
                {
                    GiveBirth(femalePoultry);
                    femalePoultry.isPregnant = false;
                }
            }
        }
        private void Mating(List <IPoultry> femalePoultryList, List <IPoultry> malePoultryList)
        {
            foreach (IPoultry femalePoultry in femalePoultryList)
            {
                //Önce dişi tavşanın çiftleşme kurallarına uyup uymadığına bakıyorum
                RabbitProvider rabbitValidator = new RabbitProvider(femalePoultry, Date);
                if (rabbitValidator.isCanMate())
                {
                    //Burada eş olan erkek tavşanı buluyorum.
                    IPoultry male = GetWillingToMateMaleRabbit(malePoultryList);


                    ImpregnateTheRabbit(femalePoultry);
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// 只推送一次
 /// </summary>
 public void RunOncePush()
 {
     //批量测试聚合通知。
     stopwatch.Restart();
     for (var i = 0; i <= 100000; i++)
     {
         var user = new User()
         {
             CompanyId = 13232,
             Mobile    = "11111" + i
         };
         repository.Update(user);
     }
     RabbitProvider.Publish(ExchangeStr, QueueStr, TypeUserName, DANQueue <User> .TryTakeAll());
     stopwatch.Stop();
     Console.WriteLine($"UpdateDelayPush-Time:" + stopwatch.ElapsedMilliseconds);
 }
Beispiel #9
0
 /// <summary>
 /// 每次都推送
 /// </summary>
 public void RunEachPush()
 {
     stopwatch.Restart();
     //批量测试循环实时通知
     for (var i = 0; i <= 5000; i++)
     {
         var user = new User()
         {
             CompanyId = 13232,
             Mobile    = "11111" + i
         };
         repository.Update(user);
         RabbitProvider.Publish(ExchangeStr, QueueStr, TypeUserName, DANQueue <User> .TryTake());
     }
     stopwatch.Stop();
     Console.WriteLine($"UpdateWithPush-Time:" + stopwatch.ElapsedMilliseconds);
 }
        //Sıradaki dişi tavşana karşı en istekli erkek tavşanı alıyorum.
        private IPoultry GetWillingToMateMaleRabbit(List <IPoultry> malePoultryList)
        {
            IPoultry most       = null;
            double   mostDesire = CommonConstant._zero;

            foreach (IPoultry malePoultry in malePoultryList)
            {
                double desire = _random.NextDouble();

                if (desire >= mostDesire)
                {
                    RabbitProvider rabbitValidatorForMaleRabbit = new RabbitProvider(malePoultry, Date);
                    //Erkek tavşanın çiftleşme kurallarına uyuyormu
                    if (rabbitValidatorForMaleRabbit.isCanMate())
                    {
                        most = malePoultry;
                    }
                }
            }

            return(most);
        }