// Token: 0x06001DFA RID: 7674 RVA: 0x000ADA28 File Offset: 0x000ABC28
        private void LoadPagedSearch(int startRange, int itemCount, PropertyDefinition[] properties, bool retry)
        {
            int num = startRange;

            if (!string.IsNullOrEmpty(this.cookie))
            {
                num = startRange - (this.cookieIndex + 1);
            }
            int itemsToSkip = num;

            object[][] array;
            int        num2;

            if (DirectoryAssistance.IsEmptyAddressList(this.userContext))
            {
                array = new object[0][];
                num2  = 0;
            }
            else
            {
                array = AddressBookBase.PagedSearch(DirectoryAssistance.IsVirtualAddressList(this.userContext) ? this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN : null, DirectoryAssistance.IsVirtualAddressList(this.userContext) ? null : this.addressBookBase, this.userContext.ExchangePrincipal.MailboxInfo.OrganizationId, AddressBookBase.RecipientCategory.All, this.searchString, itemsToSkip, ref this.cookie, itemCount, out num2, ref this.lcid, ref this.preferredDC, properties);
            }
            if (array.Length > 0)
            {
                base.StartRange  = startRange;
                base.EndRange    = base.StartRange + (array.Length - 1);
                this.cookieIndex = base.EndRange;
                base.Items       = array;
                return;
            }
            if (this.cookie != null && this.cookie.Length != 0 && retry)
            {
                this.cookieIndex = 0;
                this.LoadPagedSearch(0, itemCount, properties, false);
                return;
            }
            if (num2 != 0 && retry)
            {
                if (this.cookieIndex > 0)
                {
                    num2 += this.cookieIndex + 1;
                }
                int num3 = num2 - 1;
                startRange = num3 - (itemCount - 1);
                if (startRange < 0)
                {
                    startRange = 0;
                }
                this.cookie      = null;
                this.cookieIndex = 0;
                this.lcid        = Culture.GetUserCulture().LCID;
                this.LoadPagedSearch(startRange, itemCount, properties, false);
                return;
            }
            base.StartRange  = int.MinValue;
            base.EndRange    = int.MinValue;
            this.cookie      = null;
            this.cookieIndex = 0;
            base.Items       = array;
        }
        public override void LoadData(int startRange, int endRange)
        {
            ExTraceGlobals.MailCallTracer.TraceDebug((long)this.GetHashCode(), "ADDataSource.LoadData(Start)");
            int    lcid        = Culture.GetUserCulture().LCID;
            string preferredDC = this.userContext.PreferredDC;

            ExTraceGlobals.MailCallTracer.TraceDebug <string>((long)this.GetHashCode(), "AddressBookDataSource.LoadData: preferred DC in user context = '{0}'", preferredDC);
            if (startRange < 1)
            {
                throw new ArgumentOutOfRangeException("startRange", "startRange must be greater than 0");
            }
            if (endRange < startRange)
            {
                throw new ArgumentOutOfRangeException("endRange", "endRange must be greater than or equal to startRange");
            }
            PropertyDefinition[] properties = base.CreateProperyTable();
            int    num         = endRange - startRange + 1;
            int    pagesToSkip = startRange / num;
            string cookie      = null;

            if (DirectoryAssistance.IsEmptyAddressList(this.userContext))
            {
                base.Items = new object[0][];
            }
            else if (!string.IsNullOrEmpty(this.searchString))
            {
                base.Items = AddressBookBase.PagedSearch(DirectoryAssistance.IsVirtualAddressList(this.userContext) ? this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN : null, DirectoryAssistance.IsVirtualAddressList(this.userContext) ? null : this.addressBook, this.userContext.ExchangePrincipal.MailboxInfo.OrganizationId, this.recipientCategory, this.searchString, ref cookie, pagesToSkip, num, out this.itemsTouched, ref lcid, ref preferredDC, properties);
            }
            else
            {
                ExTraceGlobals.MailCallTracer.TraceDebug <OrganizationId>((long)this.GetHashCode(), "AddressBookDataSource.LoadData: browse: OrganizationId of address book = '{0}'", this.addressBook.OrganizationId);
                int num2;
                base.Items = this.addressBook.BrowseTo(ref cookie, this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN, ref lcid, ref preferredDC, startRange, num + 1, out num2, DirectoryAssistance.IsVirtualAddressList(this.userContext), properties);
                if (base.Items != null && base.Items.Length < num + 1)
                {
                    cookie = null;
                }
            }
            this.userContext.PreferredDC = preferredDC;
            ExTraceGlobals.MailCallTracer.TraceDebug <string>((long)this.GetHashCode(), "AddressBookDataSource.LoadData: stamped preferred DC = '{0}' onto user context.", preferredDC);
            base.Cookie     = cookie;
            base.StartRange = startRange;
            if (base.Items == null || base.Items.Length == 0)
            {
                base.EndRange = 0;
                return;
            }
            if (base.Items.Length < num)
            {
                base.EndRange = startRange + base.Items.Length - 1;
                return;
            }
            base.EndRange = endRange;
        }
        // Token: 0x06001DFB RID: 7675 RVA: 0x000ADBC0 File Offset: 0x000ABDC0
        private void LoadBrowsePage(int startRange, int itemCount, bool seekToCondition, PropertyDefinition[] properties)
        {
            int num;

            if (startRange > 1 && startRange < 2147483647)
            {
                num = startRange - 1;
                itemCount++;
            }
            else
            {
                num = startRange;
            }
            object[][] array;
            int        num2;

            if (DirectoryAssistance.IsEmptyAddressList(this.userContext))
            {
                array = new object[0][];
                num2  = 0;
            }
            else if (seekToCondition)
            {
                array = this.addressBookBase.BrowseTo(ref this.cookie, this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN, ref this.lcid, ref this.preferredDC, this.searchString, itemCount, out num2, DirectoryAssistance.IsVirtualAddressList(this.userContext), properties);
            }
            else
            {
                array = this.addressBookBase.BrowseTo(ref this.cookie, this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN, ref this.lcid, ref this.preferredDC, num, itemCount, out num2, DirectoryAssistance.IsVirtualAddressList(this.userContext), properties);
                if (startRange > 1 && startRange < 2147483647)
                {
                    itemCount--;
                    if (array.Length > 1)
                    {
                        num2++;
                        this.offsetForData = 1;
                    }
                    else if (array.Length == 1)
                    {
                        int num3 = num % itemCount;
                        if (num3 == 0)
                        {
                            num = startRange - itemCount;
                        }
                        else
                        {
                            num = num - num3 + 1;
                        }
                        array = this.addressBookBase.BrowseTo(ref this.cookie, this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN, ref this.lcid, ref this.preferredDC, num, itemCount, out num2, DirectoryAssistance.IsVirtualAddressList(this.userContext), properties);
                    }
                }
            }
            int num4 = (array.Length <= itemCount) ? (array.Length - this.offsetForData) : itemCount;

            if (num4 == 0 && !DirectoryAssistance.IsEmptyAddressList(this.userContext))
            {
                this.offsetForData = 0;
                array      = this.addressBookBase.BrowseTo(ref this.cookie, this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN, ref this.lcid, ref this.preferredDC, 0, itemCount, out num2, DirectoryAssistance.IsVirtualAddressList(this.userContext), properties);
                startRange = num2 - (itemCount - 1);
                if (startRange < 1)
                {
                    startRange = 1;
                }
                array = this.addressBookBase.BrowseTo(ref this.cookie, this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN, ref this.lcid, ref this.preferredDC, startRange, itemCount, out num2, DirectoryAssistance.IsVirtualAddressList(this.userContext), properties);
                num4  = ((array.Length < itemCount) ? array.Length : itemCount);
            }
            if (num4 > 0)
            {
                base.StartRange = Math.Max(0, num2 - 1);
                base.EndRange   = base.StartRange + num4 - 1;
            }
            else
            {
                base.StartRange = int.MinValue;
                base.EndRange   = int.MinValue;
            }
            base.Items = array;
        }