internal void UpdateFilterStateWithAddOrChange(ISyncItemId itemId, bool calendar, bool recurring, ExDateTime endTime)
 {
     if (itemId == null)
     {
         throw new ArgumentNullException("itemId");
     }
     DateTimeCustomSyncFilter.FilterState filterState = null;
     if (this.CustomFilterState == null)
     {
         this.CustomFilterState = new Dictionary <ISyncItemId, DateTimeCustomSyncFilter.FilterState>();
     }
     try
     {
         if (!this.CustomFilterState.ContainsKey(itemId))
         {
             filterState = new DateTimeCustomSyncFilter.FilterState();
             this.CustomFilterState[itemId] = filterState;
         }
         else
         {
             filterState = this.CustomFilterState[itemId];
         }
         filterState.IsCalendarItem = calendar;
         if (calendar)
         {
             filterState.IsRecurring = recurring;
             if (recurring)
             {
                 if (endTime.Equals(ExDateTime.MinValue))
                 {
                     filterState.DoesRecurrenceEnd = false;
                 }
                 else
                 {
                     filterState.DoesRecurrenceEnd = true;
                     filterState.EndTime           = endTime;
                 }
             }
             else
             {
                 filterState.EndTime = endTime;
             }
         }
     }
     catch (Exception ex)
     {
         if (ex is ObjectNotFoundException || !SyncCommand.IsItemSyncTolerableException(ex))
         {
             throw;
         }
         if (filterState != null)
         {
             filterState.IsCalendarItem = false;
         }
     }
 }
 private bool IsFilterStateInFilter(DateTimeCustomSyncFilter.FilterState itemFilterState)
 {
     return(itemFilterState != null && itemFilterState.IsCalendarItem && ((itemFilterState.IsRecurring && !itemFilterState.DoesRecurrenceEnd) || itemFilterState.EndTime > this.filterStartTime));
 }
 internal void Prepopulate(Folder folder)
 {
     if (folder == null)
     {
         throw new ArgumentNullException("folder");
     }
     this.prepopulate = true;
     if (this.CustomFilterState == null)
     {
         this.CustomFilterState = new Dictionary <ISyncItemId, DateTimeCustomSyncFilter.FilterState>();
     }
     using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, null, new PropertyDefinition[]
     {
         ItemSchema.Id,
         CalendarItemInstanceSchema.EndTime,
         CalendarItemBaseSchema.CalendarItemType,
         StoreObjectSchema.ItemClass,
         ItemSchema.Subject,
         CalendarItemInstanceSchema.StartTime
     }))
     {
         bool flag = false;
         while (!flag)
         {
             object[][] rows = queryResult.GetRows(10000);
             flag = (rows.Length == 0);
             for (int i = 0; i < rows.Length; i++)
             {
                 StoreObjectId storeObjectId = null;
                 DateTimeCustomSyncFilter.FilterState filterState = null;
                 ISyncItemId key = null;
                 try
                 {
                     storeObjectId = ((VersionedId)rows[i][0]).ObjectId;
                     string itemClass = rows[i][3] as string;
                     key = MailboxSyncItemId.CreateForNewItem(storeObjectId);
                     if (!this.CustomFilterState.ContainsKey(key))
                     {
                         filterState = new DateTimeCustomSyncFilter.FilterState();
                         this.CustomFilterState[key] = filterState;
                     }
                     else
                     {
                         filterState = this.CustomFilterState[key];
                     }
                     if (!ObjectClass.IsCalendarItem(itemClass))
                     {
                         filterState.IsCalendarItem = false;
                     }
                     else
                     {
                         filterState.IsCalendarItem = true;
                         if (!(rows[i][2] is CalendarItemType))
                         {
                             filterState.IsCalendarItem = false;
                         }
                         else
                         {
                             filterState.IsRecurring = (CalendarItemType.RecurringMaster == (CalendarItemType)rows[i][2]);
                             if (filterState.IsRecurring)
                             {
                                 using (CalendarItem calendarItem = CalendarItem.Bind(folder.Session, storeObjectId))
                                 {
                                     if (calendarItem.Recurrence != null)
                                     {
                                         if (calendarItem.Recurrence.Range is NoEndRecurrenceRange)
                                         {
                                             filterState.DoesRecurrenceEnd = false;
                                         }
                                         else
                                         {
                                             filterState.DoesRecurrenceEnd = true;
                                             OccurrenceInfo lastOccurrence = calendarItem.Recurrence.GetLastOccurrence();
                                             filterState.EndTime = lastOccurrence.EndTime;
                                         }
                                     }
                                     else
                                     {
                                         filterState.IsCalendarItem = false;
                                     }
                                     goto IL_1E6;
                                 }
                             }
                             if (!(rows[i][1] is ExDateTime))
                             {
                                 filterState.IsCalendarItem = false;
                             }
                             else
                             {
                                 filterState.EndTime = (ExDateTime)rows[i][1];
                             }
                             IL_1E6 :;
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     if (ex is ObjectNotFoundException)
                     {
                         this.CustomFilterState.Remove(key);
                     }
                     else
                     {
                         if (!SyncCommand.IsItemSyncTolerableException(ex))
                         {
                             throw;
                         }
                         string     text       = "Unknown";
                         ExDateTime exDateTime = ExDateTime.MinValue;
                         try
                         {
                             text       = (rows[i][4] as string);
                             exDateTime = (ExDateTime)rows[i][5];
                         }
                         catch
                         {
                         }
                         AirSyncUtility.ExceptionToStringHelper exceptionToStringHelper = new AirSyncUtility.ExceptionToStringHelper(ex);
                         AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Exception was caught in Prepopulate. Item id=\"{0}\", subject=\"{1}\", meetingTime={2}\r\n{3}\r\nIgnoring exception and proceeding to next item.", new object[]
                         {
                             (storeObjectId != null) ? storeObjectId : "null",
                             text,
                             exDateTime,
                             exceptionToStringHelper
                         });
                         if (filterState != null)
                         {
                             filterState.IsCalendarItem = false;
                         }
                     }
                 }
             }
         }
     }
 }