예제 #1
0
        public static List <RangeIntersection> FindAllIntersections(List <List <Availability> > availabilitiesPerEntities)
        {
            List <RangeIntersection> retVal = null;

            foreach (var row in availabilitiesPerEntities)
            {
                List <RangeIntersection> tempResult = null;
                if (retVal != null)
                {
                    tempResult = new List <RangeIntersection>(retVal);
                }
                retVal = new List <RangeIntersection>();
                if (tempResult == null)
                {
                    foreach (var item in row)
                    {
                        retVal.Add(new RangeIntersection()
                        {
                            DayOfWeek         = item.DayOfWeek,
                            IsIntersects      = true,
                            IntersectionStart = item.PeriodStart,
                            IntersectionEnd   = item.PeriodEnd,
                            DurationInSec     = (item.PeriodEnd - item.PeriodStart).TotalSeconds
                        });
                    }
                }
                else
                {
                    foreach (var item in row)
                    {
                        foreach (var intersection in tempResult)
                        {
                            var newIntersec = TimeRangeUtils.Intersection(intersection, item);
                            if (newIntersec.IsIntersects)
                            {
                                retVal.Add(newIntersec);
                            }
                        }
                    }

                    if (retVal.Count == 0)
                    {
                        break;
                    }
                }
            }

            return(retVal);
        }
        public static List <RangeIntersection> FindAllIntersections(List <List <RangeIntersection> > intersectionsGroupedPerResource)
        {
            List <RangeIntersection> retVal = null;

            foreach (var resourceRanges in intersectionsGroupedPerResource)
            {
                List <RangeIntersection> tempResult = null;
                if (retVal != null)
                {
                    tempResult = new List <RangeIntersection>(retVal);
                }

                retVal = new List <RangeIntersection>();

                if (tempResult == null)
                {
                    tempResult = resourceRanges;
                    retVal     = tempResult;
                }
                else
                {
                    foreach (var item in resourceRanges)
                    {
                        foreach (var intersection in tempResult)
                        {
                            var newIntersec = TimeRangeUtils.Intersection(intersection, item);
                            if (newIntersec.IsIntersects)
                            {
                                retVal.Add(newIntersec);
                            }
                        }
                    }

                    if (retVal.Count == 0)
                    {
                        break;
                    }
                }
            }

            return(retVal);
        }
예제 #3
0
        public static bool IntersectionWithExclusions(TimeSlot slot, List <ExceptionTime> exceptions)
        {
            bool retVal = false;

            foreach (var exception in exceptions)
            {
                switch (exception.Recurency)
                {
                case Recurency.None:
                    retVal = TimeRangeUtils.PeriodIntersectionsRawDates(slot.PeriodStart, slot.PeriodEnd, exception.PeriodStart, exception.PeriodEnd);
                    break;

                case Recurency.Daily:
                    DateTime currentDayStart = slot.PeriodStart.Date.Add(exception.PeriodStart.TimeOfDay);
                    DateTime currentDayEnd   = slot.PeriodStart.Date.Add(exception.PeriodStart.TimeOfDay);

                    retVal = TimeRangeUtils.PeriodIntersectionsRawDates(slot.PeriodStart, slot.PeriodEnd, currentDayStart, currentDayEnd);
                    break;

                case Recurency.Weekly:
                    DateTime currentWeekStart = slot.PeriodStart.Date.AddDays((int)(slot.PeriodStart - exception.PeriodStart).TotalDays % 7).Add(exception.PeriodStart.TimeOfDay);
                    DateTime currentWeekEnd   = slot.PeriodStart.Date.AddDays((int)(slot.PeriodStart - exception.PeriodEnd).TotalDays % 7).Add(exception.PeriodEnd.TimeOfDay);
                    retVal = TimeRangeUtils.PeriodIntersectionsRawDates(slot.PeriodStart, slot.PeriodEnd, currentWeekStart, currentWeekEnd);
                    break;

                case Recurency.Monthly:
                    DateTime currentMonthStart;
                    DateTime currentMonthEnd;
                    try
                    {
                        currentMonthStart = new DateTime(slot.PeriodStart.Year, slot.PeriodStart.Month, exception.PeriodStart.Day, exception.PeriodStart.Hour, exception.PeriodStart.Minute, exception.PeriodStart.Second);
                    }
                    catch
                    {
                        currentMonthStart = new DateTime(slot.PeriodStart.Year, slot.PeriodStart.Month, exception.PeriodStart.Day - 1, exception.PeriodStart.Hour, exception.PeriodStart.Minute, exception.PeriodStart.Second);
                    }
                    try
                    {
                        currentMonthEnd = new DateTime(slot.PeriodEnd.Year, slot.PeriodStart.Month, exception.PeriodEnd.Day, exception.PeriodEnd.Hour, exception.PeriodEnd.Minute, exception.PeriodEnd.Second);
                    }
                    catch
                    {
                        currentMonthEnd = new DateTime(slot.PeriodEnd.Year, slot.PeriodStart.Month, exception.PeriodEnd.Day - 1, exception.PeriodEnd.Hour, exception.PeriodEnd.Minute, exception.PeriodEnd.Second);
                    }
                    retVal = TimeRangeUtils.PeriodIntersectionsRawDates(slot.PeriodStart, slot.PeriodEnd, currentMonthStart, currentMonthEnd);
                    break;

                case Recurency.Yearly:
                    DateTime currentYearStart;
                    DateTime currentYearEnd;
                    try
                    {
                        currentYearStart = new DateTime(slot.PeriodStart.Year, exception.PeriodStart.Month, exception.PeriodStart.Day, exception.PeriodStart.Hour, exception.PeriodStart.Minute, exception.PeriodStart.Second);
                    }
                    catch
                    {
                        currentYearStart = new DateTime(slot.PeriodStart.Year, exception.PeriodStart.Month, exception.PeriodStart.Day - 1, exception.PeriodStart.Hour, exception.PeriodStart.Minute, exception.PeriodStart.Second);
                    }
                    try
                    {
                        currentYearEnd = new DateTime(slot.PeriodEnd.Year, exception.PeriodEnd.Month, exception.PeriodEnd.Day, exception.PeriodEnd.Hour, exception.PeriodEnd.Minute, exception.PeriodEnd.Second);
                    }
                    catch
                    {
                        currentYearEnd = new DateTime(slot.PeriodEnd.Year, exception.PeriodEnd.Month, exception.PeriodEnd.Day - 1, exception.PeriodEnd.Hour, exception.PeriodEnd.Minute, exception.PeriodEnd.Second);
                    }
                    retVal = TimeRangeUtils.PeriodIntersectionsRawDates(slot.PeriodStart, slot.PeriodEnd, currentYearStart, currentYearEnd);

                    break;
                }

                if (retVal)
                {
                    break;
                }
            }

            return(retVal);
        }