Пример #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);
        }