// Token: 0x0600020F RID: 527 RVA: 0x000081AC File Offset: 0x000063AC
        internal static DownloadResult SendRestRequest(string requestMethod, string requestUri, OwaIdentity identity, Stream requestStream, DataProviderCallLogEvent logEvent, string spCallName)
        {
            DownloadResult result;

            using (HttpClient httpClient = new HttpClient())
            {
                HttpSessionConfig httpSessionConfig = new HttpSessionConfig
                {
                    Method          = requestMethod,
                    Credentials     = OauthUtils.GetOauthCredential(identity.GetOWAMiniRecipient()),
                    UserAgent       = OneDriveProUtilities.UserAgentString,
                    RequestStream   = requestStream,
                    ContentType     = "application/json;odata=verbose",
                    PreAuthenticate = true
                };
                httpSessionConfig.Headers = OneDriveProUtilities.GetOAuthRequestHeaders();
                if (logEvent != null)
                {
                    logEvent.TrackSPCallBegin();
                }
                ICancelableAsyncResult cancelableAsyncResult = httpClient.BeginDownload(new Uri(requestUri), httpSessionConfig, null, null);
                cancelableAsyncResult.AsyncWaitHandle.WaitOne();
                DownloadResult downloadResult = httpClient.EndDownload(cancelableAsyncResult);
                if (logEvent != null)
                {
                    string correlationId = (downloadResult.ResponseHeaders == null) ? null : downloadResult.ResponseHeaders["SPRequestGuid"];
                    logEvent.TrackSPCallEnd(spCallName, correlationId);
                }
                result = downloadResult;
            }
            return(result);
        }
 // Token: 0x06000212 RID: 530 RVA: 0x00008570 File Offset: 0x00006770
 internal static void ExecuteQueryWithTraces(UserContext userContext, IClientContext context, DataProviderCallLogEvent logEvent, string spCallName)
 {
     try
     {
         if (logEvent != null)
         {
             logEvent.TrackSPCallBegin();
         }
         context.ExecuteQuery();
     }
     finally
     {
         if (logEvent != null)
         {
             logEvent.TrackSPCallEnd(spCallName, context.TraceCorrelationId);
         }
         OneDriveProUtilities.SendPendingGetNotification(userContext, new AttachmentOperationCorrelationIdNotificationPayload
         {
             CorrelationId      = context.TraceCorrelationId,
             SharePointCallName = spCallName
         });
     }
 }
        // Token: 0x0600223D RID: 8765 RVA: 0x0007E938 File Offset: 0x0007CB38
        private OneDriveProItemsPage UpdatePageCache(IClientContext clientContext, UserContext userContext, IList list, string listName, string location, IndexedPageView requestedData, AttachmentItemsSort sort, DataProviderCallLogEvent logEvent)
        {
            string changeToken;
            bool   flag;

            this.GetListItemChangesSinceToken(clientContext, userContext.LogonIdentity, listName, location, out changeToken, out flag, logEvent);
            this.ChangeToken = changeToken;
            if (flag)
            {
                this.PageMap.Clear();
            }
            int num = this.ComputeStartPageIndex(requestedData);
            OneDriveProItemsPage nearestPage = this.GetNearestPage(num);
            int num2 = (nearestPage != null) ? nearestPage.PageIndex : -1;

            if (nearestPage == null || num != nearestPage.PageIndex)
            {
                ListItemCollectionPosition listItemCollectionPosition = this.GetListItemCollectionPosition(nearestPage);
                CamlQuery           query = OneDriveProUtilities.CreatePagedCamlPageQuery(location, sort, listItemCollectionPosition, Math.Abs(num - num2) * 200 + 200);
                IListItemCollection items = list.GetItems(query);
                items.Load(clientContext, new Expression <Func <ListItemCollection, object> > [0]);
                OneDriveProUtilities.ExecuteQueryWithTraces(userContext, clientContext, logEvent, "UpdatePageCache");
                this.UpdateCache(items, nearestPage);
            }
            OneDriveProItemsPage result;

            this.PageMap.TryGetValue(num, out result);
            return(result);
        }
        // Token: 0x0600223B RID: 8763 RVA: 0x0007E7A4 File Offset: 0x0007C9A4
        internal IEnumerable <IListItem> GetItems(UserContext userContext, string endPointUrl, string documentLibrary, string location, IndexedPageView requestedData, AttachmentItemsSort sort, out int totalItemCount, DataProviderCallLogEvent logEvent)
        {
            IEnumerable <IListItem> result;

            using (IClientContext clientContext = OneDriveProUtilities.CreateAndConfigureClientContext(userContext.LogonIdentity, endPointUrl))
            {
                totalItemCount = 0;
                IList documentsLibrary             = OneDriveProUtilities.GetDocumentsLibrary(clientContext, documentLibrary);
                OneDriveProItemsPage page          = this.UpdatePageCache(clientContext, userContext, documentsLibrary, documentLibrary, location, requestedData, sort, logEvent);
                CamlQuery            camlDataQuery = this.GetCamlDataQuery(location, requestedData, this.GetListItemCollectionPosition(page), sort);
                IListItemCollection  items         = documentsLibrary.GetItems(camlDataQuery);
                IFolder folder = string.IsNullOrEmpty(location) ? documentsLibrary.RootFolder : clientContext.Web.GetFolderByServerRelativeUrl(location);
                items.Load(clientContext, new Expression <Func <ListItemCollection, object> > [0]);
                folder.Load(clientContext, new Expression <Func <Folder, object> >[]
                {
                    (Folder x) => (object)x.ItemCount
                });
                OneDriveProUtilities.ExecuteQueryWithTraces(userContext, clientContext, logEvent, "GetItems");
                int startIndex = requestedData.Offset % 200;
                int endIndex   = startIndex + requestedData.MaxRows;
                totalItemCount = folder.ItemCount;
                result         = items.ToList <IListItem>().Where((IListItem item, int index) => index >= startIndex && index < endIndex);
            }
            return(result);
        }
        // Token: 0x0600223F RID: 8767 RVA: 0x0007EA34 File Offset: 0x0007CC34
        private void GetListItemChangesSinceToken(IClientContext context, OwaIdentity identity, string listName, string location, out string changeToken, out bool hasChanges, DataProviderCallLogEvent logEvent)
        {
            changeToken = null;
            hasChanges  = false;
            DownloadResult downloadResult = OneDriveProUtilities.SendRestRequest("POST", string.Format("{0}/_vti_bin/client.svc/web/lists/getByTitle('{1}')/GetListItemChangesSinceToken", context.Url, listName), identity, this.GetRequestStream(location, this.ChangeToken), logEvent, "GetListItemChangesSinceToken");

            if (!downloadResult.IsSucceeded)
            {
                OneDriveProItemsPagingMetadata.TraceError(OneDriveProItemsPagingMetadata.LogMetadata.GetListItemChangesSinceToken, downloadResult.Exception);
                hasChanges = true;
                return;
            }
            using (XmlReader xmlReader = XmlReader.Create(downloadResult.ResponseStream))
            {
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        if (xmlReader.LocalName == "Changes")
                        {
                            changeToken = xmlReader.GetAttribute("LastChangeToken");
                        }
                        else if (xmlReader.LocalName == "row" && xmlReader.NamespaceURI == "#RowsetSchema")
                        {
                            hasChanges = true;
                            break;
                        }
                    }
                }
            }
        }
        public static AttachmentResultCode GetResultCodeFromWebException(WebException exception, DataProviderCallLogEvent logEvent)
        {
            HttpWebResponse httpWebResponse = exception.Response as HttpWebResponse;

            if (httpWebResponse != null)
            {
                logEvent.ErrorResponseHeaders = httpWebResponse.Headers;
            }
            WebExceptionStatus status = exception.Status;

            if (status == WebExceptionStatus.ProtocolError)
            {
                if (httpWebResponse != null)
                {
                    HttpStatusCode statusCode = httpWebResponse.StatusCode;
                    if (statusCode <= HttpStatusCode.NotFound)
                    {
                        if (statusCode == HttpStatusCode.Unauthorized)
                        {
                            return(AttachmentResultCode.AccessDenied);
                        }
                        if (statusCode == HttpStatusCode.NotFound)
                        {
                            return(AttachmentResultCode.NotFound);
                        }
                    }
                    else if (statusCode == HttpStatusCode.RequestTimeout || statusCode == HttpStatusCode.GatewayTimeout)
                    {
                        return(AttachmentResultCode.Timeout);
                    }
                }
                return(AttachmentResultCode.GenericFailure);
            }
            if (status == WebExceptionStatus.Timeout)
            {
                return(AttachmentResultCode.Timeout);
            }
            return(AttachmentResultCode.GenericFailure);
        }