// Token: 0x060010F1 RID: 4337 RVA: 0x00046AB0 File Offset: 0x00044CB0
        private int AddSyncItem(SyncCalendarItemType calendarItem, IList <SyncCalendarItemType> syncItemsList, HashSet <StoreId> syncItemsHashSet, IDictionary <StoreId, SyncCalendarItemType> unchangedMasters, bool addToUnchangedMasters)
        {
            int num = 0;

            if (!syncItemsHashSet.Contains(calendarItem.ItemId))
            {
                if (calendarItem.CalendarItemType != CalendarItemType.Occurrence)
                {
                    calendarItem.StartWallClock = null;
                    calendarItem.EndWallClock   = null;
                    if (!this.includeAdditionalDataInResponse)
                    {
                        if (calendarItem.CalendarItemType != CalendarItemType.RecurringMaster)
                        {
                            calendarItem.UID = null;
                        }
                        calendarItem.Start = null;
                        calendarItem.End   = null;
                    }
                }
                if (addToUnchangedMasters)
                {
                    unchangedMasters.Add(calendarItem.ItemId, calendarItem);
                    num++;
                }
                else
                {
                    syncItemsList.Add(calendarItem);
                    syncItemsHashSet.Add(calendarItem.ItemId);
                    if (!unchangedMasters.Remove(calendarItem.ItemId))
                    {
                        num++;
                    }
                }
            }
            return(num);
        }
        // Token: 0x060010EE RID: 4334 RVA: 0x00046958 File Offset: 0x00044B58
        private int AddNewOrChangedItems(StoreId id, IList <SyncCalendarItemType> updatedItemsList, IList <SyncCalendarItemType> recurrenceMastersWithInstances, IList <SyncCalendarItemType> recurrenceMastersWithoutInstances, IDictionary <StoreId, SyncCalendarItemType> unchangedRecurrenceMastersWithInstances, IList <StoreId> deletedItemsList, HashSet <StoreId> syncItemsHashSet, IList <KeyValuePair <StoreId, LocalizedException> > caughtExceptions)
        {
            int addedItems = 0;

            try
            {
                GrayException.MapAndReportGrayExceptions(delegate()
                {
                    using (CalendarItem calendarItem = CalendarItem.Bind(this.session, id, new PropertyDefinition[]
                    {
                        CalendarItemInstanceSchema.StartWallClock,
                        CalendarItemInstanceSchema.EndWallClock
                    }))
                    {
                        string uid;
                        try
                        {
                            uid = new GlobalObjectId(calendarItem).Uid;
                        }
                        catch (Exception arg)
                        {
                            ExTraceGlobals.SyncCalendarTracer.TraceWarning <StoreId, Exception>((long)this.GetHashCode(), "Skipping the corrupt recurring calendar GlobalObjectId (Id: '{0}'). {1}", id, arg);
                            uid = null;
                        }
                        SyncCalendarItemType typedItem = this.GetTypedItem(calendarItem.Id, uid, calendarItem.CalendarItemType, calendarItem.StartTime, calendarItem.StartWallClock, calendarItem.EndTime, calendarItem.EndWallClock);
                        if (calendarItem.CalendarItemType == CalendarItemType.RecurringMaster)
                        {
                            if (calendarItem.Recurrence == null)
                            {
                                ExTraceGlobals.SyncCalendarTracer.TraceWarning <StoreId>((long)this.GetHashCode(), "Skipping the corrupt recurring calendar item with no recurrence (Id: '{0}').", id);
                            }
                            else
                            {
                                IList <OccurrenceInfo> occurrenceInfoList = calendarItem.Recurrence.GetOccurrenceInfoList(this.windowStart, this.windowEnd);
                                if (occurrenceInfoList.Count != 0)
                                {
                                    addedItems += this.AddSyncItem(typedItem, recurrenceMastersWithInstances, syncItemsHashSet, unchangedRecurrenceMastersWithInstances, false);
                                    using (IEnumerator <OccurrenceInfo> enumerator = occurrenceInfoList.GetEnumerator())
                                    {
                                        while (enumerator.MoveNext())
                                        {
                                            OccurrenceInfo occurrenceInfo = enumerator.Current;
                                            CalendarItemType type;
                                            ExDateTime startWallClock;
                                            ExDateTime endWallClock;
                                            if (occurrenceInfo is ExceptionInfo)
                                            {
                                                type           = CalendarItemType.Exception;
                                                startWallClock = ExDateTime.MinValue;
                                                endWallClock   = ExDateTime.MinValue;
                                            }
                                            else
                                            {
                                                type           = CalendarItemType.Occurrence;
                                                startWallClock = calendarItem.StartWallClock.TimeZone.ConvertDateTime(occurrenceInfo.StartTime);
                                                endWallClock   = calendarItem.EndWallClock.TimeZone.ConvertDateTime(occurrenceInfo.EndTime);
                                            }
                                            SyncCalendarItemType typedItem2 = this.GetTypedItem(occurrenceInfo.VersionedId, uid, type, occurrenceInfo.StartTime, startWallClock, occurrenceInfo.EndTime, endWallClock);
                                            addedItems += this.AddSyncItem(typedItem2, updatedItemsList, syncItemsHashSet, unchangedRecurrenceMastersWithInstances, false);
                                        }
                                        goto IL_2D1;
                                    }
                                }
                                addedItems += this.AddSyncItem(typedItem, recurrenceMastersWithoutInstances, syncItemsHashSet, unchangedRecurrenceMastersWithInstances, false);
                            }
                        }
                        else
                        {
                            bool flag = this.windowStart <calendarItem.EndTime && this.windowEnd> calendarItem.StartTime;
                            if (flag)
                            {
                                addedItems += this.AddSyncItem(typedItem, updatedItemsList, syncItemsHashSet, unchangedRecurrenceMastersWithInstances, false);
                            }
                            else
                            {
                                addedItems += this.AddDeletedItem(id, syncItemsHashSet, deletedItemsList);
                            }
                        }
                        IL_2D1:;
                    }
                }, new GrayException.IsGrayExceptionDelegate(GrayException.IsSystemGrayException));
            }
            catch (LocalizedException ex)
            {
                ExTraceGlobals.SyncCalendarTracer.TraceWarning <string, LocalizedException>((long)this.GetHashCode(), "XsoSyncCalendar.AddNewOrChangedItems: Exception thrown while processing item {0}: {1}", id.ToBase64String(), ex);
                caughtExceptions.Add(new KeyValuePair <StoreId, LocalizedException>(id, ex));
            }
            return(addedItems);
        }
        // Token: 0x060010EC RID: 4332 RVA: 0x000462C8 File Offset: 0x000444C8
        private CalendarViewQueryResumptionPoint DoQuerySync(HashSet <StoreId> syncItemsHashSet, List <SyncCalendarItemType> updatedItemsList, List <SyncCalendarItemType> recurrenceMastersWithInstances, Dictionary <StoreId, SyncCalendarItemType> unchangedRecurrenceMastersWithInstances, ExDateTime queryWindowStart, ExDateTime queryWindowEnd, int maxCount, IList <KeyValuePair <StoreId, LocalizedException> > caughtExceptions, out int addedItems)
        {
            ExTraceGlobals.SyncCalendarTracer.TraceDebug((long)this.GetHashCode(), "XsoSyncCalendar.DoQuerySync: Start");
            int localAddedItems = 0;
            CalendarViewBatchingStrategy calendarViewBatchingStrategy = (this.syncState.QueryResumptionPoint == null) ? CalendarViewBatchingStrategy.CreateNewBatchingInstance(maxCount) : CalendarViewBatchingStrategy.CreateResumingInstance(maxCount, this.syncState.QueryResumptionPoint);

            using (CalendarFolder calendarFolder = CalendarFolder.Bind(this.session, this.folderId))
            {
                PropertyDefinition[] xsoRequiredProperties = this.getPropertiesToFetchDelegate(calendarFolder);
                object[][]           syncView = calendarFolder.GetSyncView(queryWindowStart, queryWindowEnd, calendarViewBatchingStrategy, xsoRequiredProperties, false);
                object[][]           array    = syncView;
                for (int i = 0; i < array.Length; i++)
                {
                    object[] itemRow = array[i];
                    try
                    {
                        GrayException.MapAndReportGrayExceptions(delegate()
                        {
                            ExDateTime t;
                            SyncCalendarItemType typedItem = this.GetTypedItem(xsoRequiredProperties, itemRow, out t);
                            if (typedItem.CalendarItemType != CalendarItemType.RecurringMaster)
                            {
                                if (this.windowStart == queryWindowStart || t >= queryWindowStart)
                                {
                                    localAddedItems += this.AddSyncItem(typedItem, updatedItemsList, syncItemsHashSet, unchangedRecurrenceMastersWithInstances, false);
                                }
                                return;
                            }
                            bool flag = false;
                            if (this.windowStart == queryWindowStart)
                            {
                                flag = true;
                            }
                            else
                            {
                                using (CalendarItem calendarItem = CalendarItem.Bind(this.session, typedItem.ItemId))
                                {
                                    IList <OccurrenceInfo> occurrenceInfoList = calendarItem.Recurrence.GetOccurrenceInfoList(this.windowStart, queryWindowStart);
                                    flag = (occurrenceInfoList.Count == 0);
                                }
                            }
                            if (flag)
                            {
                                localAddedItems += this.AddSyncItem(typedItem, recurrenceMastersWithInstances, syncItemsHashSet, unchangedRecurrenceMastersWithInstances, false);
                                return;
                            }
                            localAddedItems += this.AddSyncItem(typedItem, null, syncItemsHashSet, unchangedRecurrenceMastersWithInstances, true);
                        }, new GrayException.IsGrayExceptionDelegate(GrayException.IsSystemGrayException));
                    }
                    catch (LocalizedException ex)
                    {
                        StoreId storeId = (StoreId)itemRow[0];
                        ExTraceGlobals.SyncCalendarTracer.TraceWarning <string, LocalizedException>((long)this.GetHashCode(), "XsoSyncCalendar.DoQuerySync: Exception thrown while processing item {0}: {1}", storeId.ToBase64String(), ex);
                        caughtExceptions.Add(new KeyValuePair <StoreId, LocalizedException>(storeId, ex));
                    }
                }
            }
            ExTraceGlobals.SyncCalendarTracer.TraceDebug((long)this.GetHashCode(), "XsoSyncCalendar.DoQuerySync: End");
            addedItems = localAddedItems;
            return(calendarViewBatchingStrategy.ResumptionPoint);
        }