// 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: 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: 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;
                        }
                    }
                }
            }
        }
        // Token: 0x060019CD RID: 6605 RVA: 0x0005C2F0 File Offset: 0x0005A4F0
        internal static CreateAttachmentResponse AttachReferenceAttachment(AttachmentDataProvider attachmentDataProvider, UserContext userContext, string location, string dataProviderItemId, string parentItemId, IdConverter idConverter, string dataProviderParentItemId = null, string providerEndpointUrl = null)
        {
            CreateAttachmentResponse result = null;

            if (!userContext.IsDisposed)
            {
                if (string.IsNullOrEmpty(providerEndpointUrl))
                {
                    providerEndpointUrl = attachmentDataProvider.GetEndpointUrlFromItemLocation(location);
                }
                string linkingUrl = attachmentDataProvider.GetLinkingUrl(userContext, location, providerEndpointUrl, dataProviderItemId, dataProviderParentItemId);
                string text       = Path.GetFileName(HttpUtility.UrlDecode(linkingUrl));
                if (OneDriveProUtilities.IsDurableUrlFormat(text))
                {
                    text = text.Substring(0, text.LastIndexOf("?", StringComparison.InvariantCulture));
                }
                try
                {
                    userContext.LockAndReconnectMailboxSession();
                    IdAndSession            idAndSession            = new IdAndSession(StoreId.EwsIdToStoreObjectId(parentItemId), userContext.MailboxSession);
                    ReferenceAttachmentType referenceAttachmentType = new ReferenceAttachmentType
                    {
                        Name = text,
                        AttachLongPathName  = linkingUrl,
                        ProviderEndpointUrl = providerEndpointUrl,
                        ProviderType        = attachmentDataProvider.Type.ToString()
                    };
                    if (!userContext.IsGroupUserContext)
                    {
                        referenceAttachmentType.ContentId   = Guid.NewGuid().ToString();
                        referenceAttachmentType.ContentType = "image/png";
                    }
                    AttachmentHierarchy attachmentHierarchy = new AttachmentHierarchy(idAndSession, true, true);
                    using (AttachmentBuilder attachmentBuilder = new AttachmentBuilder(attachmentHierarchy, new AttachmentType[]
                    {
                        referenceAttachmentType
                    }, idConverter, true))
                    {
                        ServiceError serviceError;
                        Attachment   attachment = attachmentBuilder.CreateAttachment(referenceAttachmentType, out serviceError);
                        if (serviceError == null)
                        {
                            attachmentHierarchy.SaveAll();
                        }
                        result = CreateAttachmentHelper.CreateAttachmentResponse(attachmentHierarchy, attachment, referenceAttachmentType, idAndSession, serviceError);
                    }
                }
                finally
                {
                    userContext.UnlockAndDisconnectMailboxSession();
                }
            }
            return(result);
        }
        // Token: 0x0600020D RID: 525 RVA: 0x00008150 File Offset: 0x00006350
        internal static IClientContext CreateAndConfigureClientContext(OwaIdentity identity, string url)
        {
            ICredentials   oneDriveProCredentials = OneDriveProUtilities.GetOneDriveProCredentials(identity);
            IClientContext clientContext          = ClientContextFactory.Create(url);

            clientContext.Credentials = oneDriveProCredentials;
            clientContext.FormDigestHandlingEnabled = false;
            clientContext.ExecutingWebRequest      += delegate(object sender, WebRequestEventArgs args)
            {
                if (args != null)
                {
                    args.WebRequestExecutor.RequestHeaders.Add(OneDriveProUtilities.GetOAuthRequestHeaders());
                    args.WebRequestExecutor.WebRequest.PreAuthenticate = true;
                    args.WebRequestExecutor.WebRequest.UserAgent       = OneDriveProUtilities.UserAgentString;
                }
            };
            return(clientContext);
        }
        // Token: 0x06001AD6 RID: 6870 RVA: 0x00065F4C File Offset: 0x0006414C
        private static WacAttachmentType CreateWacAttachmentType(OwaIdentity identity, AttachmentIdType attachmentIdType, string webServiceUrl, string contentUrl, bool isEdit, bool isInDraft)
        {
            string wacUrl;

            try
            {
                wacUrl = OneDriveProUtilities.GetWacUrl(identity, webServiceUrl, contentUrl, isEdit);
            }
            catch (Exception ex)
            {
                ex.ToString();
                throw;
            }
            return(new WacAttachmentType
            {
                AttachmentId = attachmentIdType,
                IsEdit = isEdit,
                IsInDraft = isInDraft,
                WacUrl = wacUrl,
                Status = WacAttachmentStatus.Success
            });
        }
 // 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: 0x0600020C RID: 524 RVA: 0x000080E7 File Offset: 0x000062E7
 internal static CamlQuery CreateCamlDataQuery(string location, AttachmentItemsSort sort)
 {
     return(OneDriveProUtilities.CreateCamlQuery(location, null, string.Format("<View>\r\n                                                <Query>\r\n                                                    <OrderBy>\r\n                                                        <FieldRef Name='FSObjType' Ascending='FALSE' />\r\n                                                        <FieldRef Name='{0}' Ascending='{1}' />\r\n                                                    </OrderBy>\r\n                                                </Query>\r\n                                                <ViewFields>\r\n                                                    <FieldRef Name='ID' />\r\n                                                    <FieldRef Name='FileLeafRef' />\r\n                                                    <FieldRef Name='FSObjType' />\r\n                                                    <FieldRef Name='FileRef' />\r\n                                                    <FieldRef Name='File_x0020_Size' />\r\n                                                    <FieldRef Name='Modified' />\r\n                                                    <FieldRef Name='Editor' />\r\n                                                    <FieldRef Name='ItemChildCount' />\r\n                                                    <FieldRef Name='FolderChildCount' />\r\n                                                    <FieldRef Name='ProgId' />\r\n                                                </ViewFields></View>", OneDriveProUtilities.GetSortColumn(sort.SortColumn), OneDriveProUtilities.GetSortOrder(sort.SortOrder))));
 }
 // Token: 0x0600020B RID: 523 RVA: 0x000080D7 File Offset: 0x000062D7
 internal static CamlQuery CreatePagedCamlDataQuery(string location, AttachmentItemsSort sort, ListItemCollectionPosition listItemCollectionPosition, int numberOfItems)
 {
     return(OneDriveProUtilities.CreatePagedCamlQuery(location, sort, listItemCollectionPosition, numberOfItems, "<View>\r\n                                                <Query>\r\n                                                    <OrderBy>\r\n                                                        <FieldRef Name='FSObjType' Ascending='FALSE' />\r\n                                                        <FieldRef Name='{0}' Ascending='{1}' />\r\n                                                    </OrderBy>\r\n                                                </Query>\r\n                                                <ViewFields>\r\n                                                    <FieldRef Name='ID' />\r\n                                                    <FieldRef Name='FileLeafRef' />\r\n                                                    <FieldRef Name='FSObjType' />\r\n                                                    <FieldRef Name='FileRef' />\r\n                                                    <FieldRef Name='File_x0020_Size' />\r\n                                                    <FieldRef Name='Modified' />\r\n                                                    <FieldRef Name='Editor' />\r\n                                                    <FieldRef Name='ItemChildCount' />\r\n                                                    <FieldRef Name='FolderChildCount' />\r\n                                                    <FieldRef Name='ProgId' />\r\n                                                </ViewFields><RowLimit>{2}</RowLimit></View>"));
 }
 // Token: 0x0600020A RID: 522 RVA: 0x000080C7 File Offset: 0x000062C7
 internal static CamlQuery CreatePagedCamlPageQuery(string location, AttachmentItemsSort sort, ListItemCollectionPosition listItemCollectionPosition, int numberOfItems)
 {
     return(OneDriveProUtilities.CreatePagedCamlQuery(location, sort, listItemCollectionPosition, numberOfItems, "<View>\r\n                                                    <Query>\r\n                                                        <OrderBy>\r\n                                                            <FieldRef Name='FSObjType' Ascending='FALSE' />\r\n                                                            <FieldRef Name='{0}' Ascending='{1}' />\r\n                                                        </OrderBy>\r\n                                                    </Query>\r\n                                                    <ViewFields>\r\n                                                        <FieldRef Name='ID' />\r\n                                                        <FieldRef Name='FileLeafRef' />\r\n                                                        <FieldRef Name='FSObjType' />\r\n                                                        <FieldRef Name='SortBehavior' />\r\n                                                    </ViewFields>\r\n                                                    <RowLimit>{2}</RowLimit>\r\n                                                </View>"));
 }
 // Token: 0x06000218 RID: 536 RVA: 0x00008757 File Offset: 0x00006957
 private static string GetSortColumn(AttachmentItemsSortColumn column)
 {
     OneDriveProUtilities.EnsureColumnMap();
     return(OneDriveProUtilities.columnToOneDriveProColumn[column]);
 }
 // Token: 0x06000216 RID: 534 RVA: 0x000086F5 File Offset: 0x000068F5
 private static CamlQuery CreatePagedCamlQuery(string location, AttachmentItemsSort sort, ListItemCollectionPosition listItemCollectionPosition, int numberOfItems, string viewXmlFormat)
 {
     return(OneDriveProUtilities.CreateCamlQuery(location, listItemCollectionPosition, string.Format(viewXmlFormat, OneDriveProUtilities.GetSortColumn(sort.SortColumn), OneDriveProUtilities.GetSortOrder(sort.SortOrder), numberOfItems)));
 }
        // Token: 0x06000211 RID: 529 RVA: 0x000082BC File Offset: 0x000064BC
        internal static string GetWacUrl(OwaIdentity identity, string endPointUrl, string documentUrl, bool isEdit)
        {
            string arg  = isEdit ? "2" : "4";
            string text = string.Format("{0}/_api/Microsoft.SharePoint.Yammer.WACAPI.GetWacToken(fileUrl=@p, wopiAction={2})?@p='{1}'", endPointUrl, documentUrl, arg);
            string result;

            using (HttpClient httpClient = new HttpClient())
            {
                OWAMiniRecipient    owaminiRecipient    = identity.GetOWAMiniRecipient();
                ICredentials        oauthCredential     = OauthUtils.GetOauthCredential(owaminiRecipient);
                WebHeaderCollection oauthRequestHeaders = OneDriveProUtilities.GetOAuthRequestHeaders();
                HttpSessionConfig   sessionConfig       = new HttpSessionConfig
                {
                    Method          = "GET",
                    Credentials     = oauthCredential,
                    UserAgent       = OneDriveProUtilities.UserAgentString,
                    ContentType     = "application/json;odata=verbose",
                    PreAuthenticate = true,
                    Headers         = oauthRequestHeaders
                };
                DownloadResult downloadResult;
                try
                {
                    downloadResult = OneDriveProUtilities.TryTwice(httpClient, sessionConfig, text);
                }
                catch (WebException ex)
                {
                    if (!OneDriveProUtilities.IsDurableUrlFormat(documentUrl))
                    {
                        throw ex;
                    }
                    ExTraceGlobals.AttachmentHandlingTracer.TraceWarning <string>(0L, "OneDriveProUtilities.GetWacUrl Exception while trying to get wac token using durable url. : {0}", ex.StackTrace);
                    documentUrl = documentUrl.Substring(0, documentUrl.LastIndexOf("?", StringComparison.InvariantCulture));
                    text        = string.Format("{0}/_api/Microsoft.SharePoint.Yammer.WACAPI.GetWacToken(fileUrl=@p, wopiAction={2})?@p='{1}'", endPointUrl, documentUrl, arg);
                    ExTraceGlobals.AttachmentHandlingTracer.TraceWarning <string>(0L, "OneDriveProUtilities.GetWacUrl Fallback to canonical url format: {0}", text);
                    OwaServerTraceLogger.AppendToLog(new TraceLogEvent("SP.GWT", null, "GetWacToken", string.Format("Error getting WAC Token fallback to canonical format:{0}", text)));
                    downloadResult = OneDriveProUtilities.TryTwice(httpClient, sessionConfig, text);
                }
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(downloadResult.ResponseStream);
                string namespaceURI = "http://schemas.microsoft.com/ado/2007/08/dataservices";
                string text2        = null;
                string text3        = null;
                string text4        = null;
                foreach (object obj in xmlDocument.GetElementsByTagName("*", namespaceURI))
                {
                    XmlNode xmlNode = (XmlNode)obj;
                    if (xmlNode is XmlElement)
                    {
                        if (text2 != null && text3 != null && text4 != null)
                        {
                            break;
                        }
                        if (string.CompareOrdinal(xmlNode.LocalName, "AppUrl") == 0)
                        {
                            text2 = xmlNode.InnerText;
                        }
                        else if (string.CompareOrdinal(xmlNode.LocalName, "AccessToken") == 0)
                        {
                            text3 = xmlNode.InnerText;
                        }
                        else if (string.CompareOrdinal(xmlNode.LocalName, "AccessTokenTtl") == 0)
                        {
                            text4 = xmlNode.InnerText;
                        }
                    }
                }
                if (text2 == null || text3 == null || text4 == null)
                {
                    throw new OwaException("SharePoint's GetWacToken response is not usable.");
                }
                string text5 = isEdit ? "OwaEdit" : "OwaView";
                result = string.Format("{0}&access_token={1}&access_token_ttl={2}&sc={3}", new object[]
                {
                    text2,
                    text3,
                    text4,
                    text5
                });
            }
            return(result);
        }
        // Token: 0x0600223E RID: 8766 RVA: 0x0007EA08 File Offset: 0x0007CC08
        private CamlQuery GetCamlDataQuery(string location, IndexedPageView requestedData, ListItemCollectionPosition position, AttachmentItemsSort sort)
        {
            int numberOfItems = requestedData.Offset % 200 + requestedData.MaxRows;

            return(OneDriveProUtilities.CreatePagedCamlDataQuery(location, sort, position, numberOfItems));
        }