internal static IEnumerable <ExpandedRosterEvent> Expand(IEnumerable <RosterEvent> items, IEnumerable <int> excludeExceptionIds, DateTime rangeBegin, DateTime rangeEnd, string beginFieldName, string endFieldName, SPTimeZone timeZone)
        {
            List <ExpandedRosterEvent>              list        = new List <ExpandedRosterEvent>();
            Dictionary <Guid, RosterEvent>          dictionary  = new Dictionary <Guid, RosterEvent>();
            Dictionary <Guid, IList <RosterEvent> > dictionary2 = new Dictionary <Guid, IList <RosterEvent> >();

            foreach (RosterEvent item in items)
            {
                if (item.GetIsRecurrence() && item.GetShPEventType() == 1)
                {
                    if (!dictionary2.ContainsKey(item.Id))
                    {
                        dictionary2.Add(item.Id, new List <RosterEvent>());
                        dictionary.Add(item.Id, item);
                    }
                }
                else
                {
                    // non-recurrence event
                    var ere = new ExpandedRosterEvent(item, true, timeZone);
                    list.Add(ere);
                }
            }

            foreach (Guid itmId in dictionary.Keys)
            {
                IList <ExpandedRosterEvent> expanded = ExpandSeriesItem(dictionary[itmId], beginFieldName, endFieldName, rangeBegin, rangeEnd, timeZone);
                //ApplyRelatedItems(dictionary[itmId], expanded, dictionary2[itmId], excludeExceptionIds, beginFieldName, endFieldName, timeZone);
                list.AddRange(expanded);
            }
            return(list);
        }
        private static IList <ExpandedRosterEvent> ExpandSeriesItem(RosterEvent masterItem, string beginFieldName, string endFieldName, DateTime localTimeRangeBegin, DateTime localTimeRangeEnd, SPTimeZone localTZ)
        {
            DateTime       time;
            DateTime       time2;
            RecurrenceRule rule               = new RecurrenceRule(masterItem.GetRecurrence());
            bool           isAllDayEvent      = masterItem.GetIsAllDayEvent();
            SPTimeZone     timeZone           = GetTimeZone(masterItem, localTZ);
            DateTime       dateTimeFieldValue = masterItem.GetStartDate();
            DateTime       rangeEnd           = masterItem.GetEndDate();

            RecurrenceTimeZoneConverter converter = new RecurrenceTimeZoneConverter(timeZone, localTZ, dateTimeFieldValue, rangeEnd);

            if (isAllDayEvent)
            {
                time  = dateTimeFieldValue;
                time2 = rangeEnd;
            }
            else
            {
                time  = converter.ToOriginal(dateTimeFieldValue);
                time2 = converter.ToOriginal(rangeEnd);
            }
            TimeSpan itemLength = CalculateItemLength(time, time2);
            DateTime rangeBegin = converter.ToOriginal(localTimeRangeBegin);
            DateTime time6      = converter.ToOriginal(localTimeRangeEnd);

            if (isAllDayEvent)
            {
                rangeBegin = localTimeRangeBegin;
                time6      = localTimeRangeEnd;
            }
            DateTime time7 = new DateTime(dateTimeFieldValue.Ticks) + itemLength;

            if (time7.Day != dateTimeFieldValue.Day)
            {
                rangeBegin = rangeBegin.AddDays(-1.0);
            }
            rangeBegin = ComputeExpandBegin(rangeBegin, time, rule);
            time6      = ComputeExpandEnd(time6, time, time2, rule, timeZone);

            List <ExpandedRosterEvent> list = new List <ExpandedRosterEvent>();
            DateTime date = rangeBegin.Date;

            while (true)
            {
                DateTime itemBegin = ComputeTargetBegin(date, time, rule);
                DateTime time10    = ComputeTargetEnd(itemBegin, itemLength);
                TimeSpan span2     = (TimeSpan)(time10 - itemBegin);
                bool     flag2     = span2.Ticks == 0L;
                if ((time6 < itemBegin) || ((time6 == itemBegin) && !flag2))
                {
                    return(list);
                }
                if (999 <= list.Count)
                {
                    return(list);
                }
                if (((rule.Type == RecurrenceRule.RecurrenceType.Daily) && rule.IsWeekday) && ((itemBegin.DayOfWeek == DayOfWeek.Saturday) || (itemBegin.DayOfWeek == DayOfWeek.Sunday)))
                {
                    date = IncrementDate(date, rule);
                }
                else if ((rule.Type == RecurrenceRule.RecurrenceType.Weekly) && !rule.DaysOfWeek.Contains(itemBegin.DayOfWeek))
                {
                    date = IncrementDate(date, rule);
                }
                else
                {
                    ExpandedRosterEvent item = null;
                    if ((rangeBegin < time10) || ((rangeBegin == time10) && (itemLength.Ticks == 0L)))
                    {
                        item = new ExpandedRosterEvent(masterItem, false, null);
                        if (isAllDayEvent)
                        {
                            item.StartDate = itemBegin;
                            item.EndDate   = time10;
                        }
                        else
                        {
                            item.StartDate = converter.ToLocal(itemBegin);
                            item.EndDate   = converter.ToLocal(time10);
                        }
                        //item["ID"] = str2;
                        item.InstanceID = GenerateRecurrenceItemId(masterItem.Id, item.StartDate, localTZ, isAllDayEvent);
                        if (999 > list.Count)
                        {
                            list.Add(item);
                        }
                    }
                    date = IncrementDate(date, rule);
                }
            }
        }