Exemple #1
0
        public bool CanWork(IShift shift)
        {
            if (_rules == null)
            {
                throw new ArgumentNullException("IBusinessRules", "Business Rules object must be set before CanWork can be called");
            }

            if (ShiftDuration >= MaxShiftDuration)
            {
                return(false);
            }

            if (!_rules.AllowConsecutiveDays)
            {
                if (Shifts.Any(s => s.Day == shift.Day - 1))
                {
                    return(false);
                }
            }

            if (Shifts.Count(s => s.Day == shift.Day) >= _rules.MaxShiftsPerDay)
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
 public virtual void AddShift(DeliveryShift deliveryShift)
 {
     if (Shifts.Any(ds => DomainHelper.EqualDomainObjects(ds, deliveryShift)))
     {
         logger.Warn("Смена {0} уже добавлена. Пропускаем...", deliveryShift.Name);
         return;
     }
     ObservableShifts.Add(deliveryShift);
 }
Exemple #3
0
    private Shift GetShift(DayOfWeek day, string strShift)
    {
        if (!Shifts.Any(x => x.Start.DayOfWeek == day && x.ShiftName.Trim() == strShift))
        {
            return(null);
        }
        Shift shift = Shifts.First(x => x.Start.DayOfWeek == day && x.ShiftName.Trim() == strShift);

        return(shift);
    }
Exemple #4
0
        /// <summary>
        /// Returns the next available <see cref="TimeBlock"/> at the specified <see cref="DateTime"/>.
        /// </summary>
        public TimeBlock GetNextBlock(DateTime time)
        {
            DayOfWeek day = time.DayOfWeek;

            if (Shifts.Count == 0)
            {
                throw new Exception("There must at least be one shift specified.");
            }
            int dayOffset = 0;

            // force offset if the shift is on the same day, but it already ended.
            if (Shifts.Any(x => x.Day == day))
            {
                Shift    last     = Shifts.First(x => x.Day == day);
                DateTime lastFrom = time.Date.AddHours(last.StartingHour).AddMinutes(last.StartingMinute);
                DateTime lastTo   = lastFrom.Add(last.Length);

                TimeBlock lastBlock = new TimeBlock(lastFrom, lastTo);

                // if the last shift is out of range, force another day so it can read the next upcoming shifts.
                if (!lastBlock.IsBefore(time) && !lastBlock.Contains(time))
                {
                    day = (DayOfWeek)((int)(day + 1) % 7);
                    dayOffset++;
                }
                else
                {
                    return(lastBlock);
                }
            }


            while (!Shifts.Any(x => x.Day == day))
            {
                day = (DayOfWeek)((int)(day + 1) % 7);
                dayOffset++;
            }

            Shift next = Shifts.First(x => x.Day == day);

            DateTime from = time.Date.AddDays(dayOffset)
                            .AddHours(next.StartingHour).AddMinutes(next.StartingMinute);

            DateTime to = from.Add(next.Length);

            Console.WriteLine(from.ToLongTimeString());
            Console.WriteLine(to.ToLongTimeString());

            return(new TimeBlock(from, to));
        }