示例#1
0
 public void Distribute()
 {
     while (Creatures.Any() && Spots.Any(x => x.Available()))
     {
         var creature = Creatures.First();
         var spot     = GetRandomSpot();
         spot.Creatures.Add(creature);
         Creatures.Remove(creature);
     }
 }
示例#2
0
        public void RebuildSpots(bool keepExistedData = false)
        {
            if (!Parent.ParentScheduleSettings.FlightDateStart.HasValue || !Parent.ParentScheduleSettings.FlightDateEnd.HasValue)
            {
                return;
            }

            var startDate = Parent.ParentScheduleSettings.FlightDateStart.Value;
            var endDate   = Parent.ParentScheduleSettings.FlightDateEnd.Value;
            var spotDate  = startDate;

            var newSpots = new List <Spot>();

            while (spotDate < endDate)
            {
                var spot = new Spot(this)
                {
                    Date = spotDate
                };
                spotDate = Parent.SpotType == SpotType.Week ? spotDate.AddDays(7) : new DateTime(spotDate.AddMonths(1).Year, spotDate.AddMonths(1).Month, 1);
                newSpots.Add(spot);
            }

            if (!(Spots.Any() && Spots.First().Date == startDate && Spots.Count == newSpots.Count))
            {
                if (keepExistedData)
                {
                    if (Spots.Count >= newSpots.Count)
                    {
                        for (int i = 0; i < newSpots.Count; i++)
                        {
                            newSpots[i].Count = Spots[i].Count;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < Spots.Count; i++)
                        {
                            newSpots[i].Count = Spots[i].Count;
                        }
                    }
                }

                Spots.Clear();
                Spots.AddRange(newSpots);
            }
        }