Пример #1
0
 public void InitializeTest()
 {
     _rangedList    = new RangedList <int?>(_defaultValue, false);
     _rangedList[1] = 10;
     _rangedList[2] = null;
     _rangedList[4] = 40;
 }
Пример #2
0
        private void Init()
        {
            Dependencies.Cache(this);

            if (GameSession != null)
            {
                GameSession.OnHardInit    += OnHardInit;
                GameSession.OnSoftInit    += OnSoftInit;
                GameSession.OnSoftDispose += OnSoftDispose;
                GameSession.OnHardDispose += OnHardDispose;
            }

            hitCircleRecycler     = new ManagedRecycler <HitCircleView>(CreateHitCircle);
            draggerCircleRecycler = new ManagedRecycler <DraggerCircleView>(CreateDraggerCircle);
            tickRecycler          = new ManagedRecycler <DraggerTickView>(CreateTick);
            draggerRecycler       = new ManagedRecycler <DraggerView>(CreateDragger);

            hitObjectViews = new RangedList <HitObjectView>(400);

            // Add tick and drag circle as dependencies for dragger view to draw its nested objects.
            Dependencies.CacheAs <IRecycler <DraggerCircleView> >(draggerCircleRecycler);
            Dependencies.CacheAs <IRecycler <DraggerTickView> >(tickRecycler);
        }
        /// <summary>
        /// Returns a list of time slots available for the given course under the restrictions that it should be a lab room,
        /// class room, instructional room, etc.
        /// </summary>
        /// <param name="course">
        /// The course to account for.
        /// </param>
        /// <param name="labRoom">
        /// Should the room be a lab room?
        /// </param>
        /// <param name="classRoom">
        /// Should the room be a class room?
        /// </param>
        /// <param name="instructRoom">
        /// Should the room be an instructional room?
        /// </param>
        /// <returns>
        /// A list of time slots representing available times at what rooms.
        /// </returns>
        private List<TimeSlot> RequestAvailableRooms(Course course, bool labRoom, bool classRoom, bool instructRoom, bool library)
        {
            List<TimeSlot> availableSlots = new List<TimeSlot>();

            foreach (Room room in Program.Database.Rooms)
            {
                if ((room.RoomID != "Lib" && library) && (!room.Resource.Cad && course.Requirement.Cad) && (!room.Resource.Program && course.Requirement.Program)
                && (!room.Resource.Multi && course.Requirement.Multi) && (!room.Resource.Gaming && course.Requirement.Gaming))
                continue;

                if ((labRoom && !room.Resource.Lab) || (classRoom && !room.Resource.Classroom) || (instructRoom && !room.Resource.Instruct) || (library && !room.RoomID.Contains("Lib")))
                    continue;

                // Figure out where existing schedule usages are
                var usages = from schedule in CurrentSchedules
                             where schedule.RoomID == room.RoomID
                             select schedule;

                // We don't care so much about what's already here, just flag it
                RangedList<Room> usedSlots = new RangedList<Room>();
                usedSlots.Payload = usedSlots.Payload.Distinct().ToList();
                foreach (Schedule schedule in usages)
                {
                    usedSlots.AddRange(schedule.StartTime, schedule.EndTime, room);
                }

                // We start on monday and blow through each day of the week, looking in 1-hour increments for available slots
                DateTime startDate = StartDate();

                for (int day = 0; day < 5; day++)
                {
                    DateTime currentDate = startDate.AddDays(day).AddHours(8.335);
                    DateTime? openStart = currentDate;

                    for (int hour = 0; hour < 8; hour++)
                    {
                        // Is the current date available?
                        RangedList<Room>.PayloadIndex currentSlot = usedSlots.GetIndex(currentDate);

                        if (currentSlot != null)
                        {
                            // We've got to close an availability block
                            if (openStart != null && (DateTime)openStart != currentDate)
                            {
                                DateTime start = (DateTime)openStart;
                                DateTime end = currentDate;

                                // Record our availability range
                                TimeSlot newSlot = new TimeSlot()
                                {
                                    Start = start,
                                    End = end,
                                    TargetRoom = room,
                                };

                                availableSlots.Add(newSlot);
                            }

                            openStart = null; // Not available, move along to the next hour
                        }
                        else
                            if (openStart == null)
                                openStart = currentDate;

                        currentDate = currentDate.AddHours(1);
                    }

                    // This will happen on our first pass because entire days are still available
                    if (openStart != null && (DateTime)openStart != currentDate)
                    {
                        DateTime start = (DateTime)openStart;
                        DateTime end = currentDate;

                        // Record our availability range
                        TimeSlot newSlot = new TimeSlot()
                        {
                            Start = start,
                            End = end,
                            TargetRoom = room,
                        };

                        availableSlots.Add(newSlot);
                    }
                }
            }

            List<TimeSlot> result = availableSlots.Distinct().ToList();
            return result;
        }