Beispiel #1
0
        public AutoBookResults AutoBook(List <EventToBook> eventsToBook, List <User> users)
        {
            AutoBookResults    result = new AutoBookResults();
            List <EventToBook> events = OrderBookings(eventsToBook);

            if (users.Count() == 0)
            {
                result.FailedToBook.AddRange(eventsToBook);
                return(result);
            }

            foreach (EventToBook toBook in events)
            {
                if (toBook.Length > _MAX_EVENT_LENGTH)
                {
                    result.FailedToBook.Add(toBook);
                    continue;
                }

                Event optimalBooking = null;
                foreach (User user in users)
                {
                    DateTime?dt = FindValidWorkingDay(user, toBook.DueDate, toBook.Length);
                    if (dt != null)
                    {
                        DateTime sDate = dt.Value;

                        const int MAX_DAYS_LOOKAHEAD = 10;
                        DateTime  maxDueDate         = toBook.DueDate.AddDays(MAX_DAYS_LOOKAHEAD);

                        Event provisonalBooking = null;
                        if (OnEventToBookCheck(toBook, user))
                        {
                            provisonalBooking = AllotAppointment(toBook, user, toBook.DueDate, maxDueDate);
                        }
                        if (provisonalBooking != null)
                        {
                            if (OnOptimalBookingCheck(optimalBooking, provisonalBooking))
                            {
                                optimalBooking = provisonalBooking;
                            }
                        }
                    }
                }


                if (optimalBooking != null)
                {
                    _EventStore.Appointments.Add(optimalBooking);
                    result.Booked.Add(optimalBooking);
                }
                else
                {
                    result.FailedToBook.Add(toBook);
                }
            }

            return(result);
        }
Beispiel #2
0
 public void ExecuteAutoBooking()
 {
     _AutoBookResults = Diary_.AutoBook(AppointmentsToBook, _UserStore.GetUsers());
     AppointmentsToBook.Clear();
 }