Beispiel #1
0
 // Methods
 private static void ApplyRelatedItems(SPItem masterItem, IList <SPItem> expanded, IEnumerable <SPItem> related, IEnumerable <int> excludeExceptionIds, string beginFieldName, string endFieldName, SPTimeZone localTimeZone)
 {
     foreach (SPItem item in related)
     {
         int      integerFieldValue  = SafeFieldAccessor.GetIntegerFieldValue(masterItem, "ID");
         DateTime dateTimeFieldValue = SafeFieldAccessor.GetDateTimeFieldValue(item, "RecurrenceID");
         string   id    = GenerateRecurrenceItemId(integerFieldValue, dateTimeFieldValue, localTimeZone, false);
         SPItem   item2 = FindItemById(expanded, id);
         if (item2 != null)
         {
             expanded.Remove(item2);
         }
         int eventType = GetEventType(item);
         if ((eventType == 4) && ((excludeExceptionIds == null) || !excludeExceptionIds.Contains <int>(item.ID)))
         {
             DateTime start = SafeFieldAccessor.GetDateTimeFieldValue(item, beginFieldName);
             DateTime end   = SafeFieldAccessor.GetDateTimeFieldValue(item, endFieldName);
             item2 = FindItemByBeginEnd(expanded, beginFieldName, endFieldName, start, end);
             if (item2 != null)
             {
                 if (GetEventType(item2) == 4)
                 {
                     continue;
                 }
                 expanded.Remove(item2);
             }
             SPItem item3 = new ExpandedCalendarItem(item);
             string str2  = GenerateExceptionItemId(item.ID, integerFieldValue, eventType);
             item3["ID"] = str2;
             expanded.Add(item3);
         }
     }
 }
Beispiel #2
0
        internal static int GetMasterId(SPItem item)
        {
            int    num              = 0;
            int    eventType        = GetEventType(item);
            string stringFieldValue = SafeFieldAccessor.GetStringFieldValue(item, "ID");

            if ((eventType == 1) && !stringFieldValue.Contains <char>('.'))
            {
                return(SafeFieldAccessor.GetIntegerFieldValue(item, "ID"));
            }

            if ((eventType != 4) && (eventType != 3))
            {
                return(num);
            }

            return(SafeFieldAccessor.GetIntegerFieldValue(item, "MasterSeriesItemID"));
        }
Beispiel #3
0
 internal static int GetEventType(SPItem item)
 {
     return(SafeFieldAccessor.GetIntegerFieldValue(item, "EventType"));
 }
Beispiel #4
0
        private static IList <SPItem> ExpandSeriesItem(SPItem masterItem, string beginFieldName, string endFieldName, DateTime localTimeRangeBegin, DateTime localTimeRangeEnd, SPTimeZone localTZ)
        {
            DateTime       time;
            DateTime       time2;
            RecurrenceRule rule                   = new RecurrenceRule(SafeFieldAccessor.GetStringFieldValue(masterItem, "RecurrenceData"));
            bool           boolFieldValue         = SafeFieldAccessor.GetBoolFieldValue(masterItem, "fAllDayEvent");
            SPTimeZone     timeZone               = GetTimeZone(masterItem, localTZ);
            DateTime       dateTimeFieldValue     = SafeFieldAccessor.GetDateTimeFieldValue(masterItem, beginFieldName);
            DateTime       rangeEnd               = SafeFieldAccessor.GetDateTimeFieldValue(masterItem, endFieldName);
            RecurrenceTimeZoneConverter converter = new RecurrenceTimeZoneConverter(timeZone, localTZ, dateTimeFieldValue, rangeEnd);

            if (boolFieldValue)
            {
                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 (boolFieldValue)
            {
                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 <SPItem> list = new List <SPItem>();
            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 (0x3e7 <= 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
                {
                    ExpandedCalendarItem item = null;
                    if ((rangeBegin < time10) || ((rangeBegin == time10) && (itemLength.Ticks == 0L)))
                    {
                        item = new ExpandedCalendarItem(masterItem);
                        if (boolFieldValue)
                        {
                            item[beginFieldName] = itemBegin;
                            item[endFieldName]   = time10;
                        }
                        else
                        {
                            item[beginFieldName] = converter.ToLocal(itemBegin);
                            item[endFieldName]   = converter.ToLocal(time10);
                        }
                        string str2 = GenerateRecurrenceItemId(SafeFieldAccessor.GetIntegerFieldValue(masterItem, "ID"), (DateTime)item[beginFieldName], localTZ, boolFieldValue);
                        item["ID"] = str2;
                        if (0x3e7 > list.Count)
                        {
                            list.Add(item);
                        }
                    }
                    date = IncrementDate(date, rule);
                }
            }
        }
Beispiel #5
0
        internal static IEnumerable <SPItem> Expand(IEnumerable <SPItem> items, IEnumerable <int> excludeExceptionIds, DateTime rangeBegin, DateTime rangeEnd, string beginFieldName, string endFieldName, SPTimeZone timeZone)
        {
            List <SPItem>                     list        = new List <SPItem>();
            Dictionary <int, SPItem>          dictionary  = new Dictionary <int, SPItem>();
            Dictionary <int, IList <SPItem> > dictionary2 = new Dictionary <int, IList <SPItem> >();

            foreach (SPItem item in items)
            {
                if (SafeFieldAccessor.GetBoolFieldValue(item, "fRecurrence") && (GetEventType(item) == 1))
                {
                    int integerFieldValue = SafeFieldAccessor.GetIntegerFieldValue(item, "ID");
                    if (!dictionary2.ContainsKey(integerFieldValue))
                    {
                        dictionary2.Add(integerFieldValue, new List <SPItem>());
                        dictionary.Add(integerFieldValue, item);
                    }
                }
            }
            foreach (SPItem item2 in items)
            {
                int masterId = GetMasterId(item2);
                if (masterId != item2.ID)
                {
                    if (!dictionary.ContainsKey(masterId))
                    {
                        switch (GetEventType(item2))
                        {
                        case 3:
                        {
                            continue;
                        }

                        case 4:
                        {
                            SPItem     item3 = item2;
                            SPListItem item4 = item2 as SPListItem;
                            if (item4 != null)
                            {
                                item3       = new ExpandedCalendarItem(item4);
                                item3["ID"] = item4.RecurrenceID;
                            }
                            list.Add(item3);
                            continue;
                        }
                        }
                        list.Add(item2);
                    }
                    else
                    {
                        dictionary2[masterId].Add(item2);
                    }
                }
            }
            foreach (int num3 in dictionary.Keys)
            {
                IList <SPItem> expanded = ExpandSeriesItem(dictionary[num3], beginFieldName, endFieldName, rangeBegin, rangeEnd, timeZone);
                ApplyRelatedItems(dictionary[num3], expanded, dictionary2[num3], excludeExceptionIds, beginFieldName, endFieldName, timeZone);
                list.AddRange(expanded);
            }
            return(list);
        }