Exemplo n.º 1
0
        /// <summary>
        /// Get a page's worth of Workbook listings
        /// </summary>
        /// <param name="onlineWorkbooks"></param>
        /// <param name="pageToRequest">Page # we are requesting (1 based)</param>
        /// <param name="totalNumberPages">Total # of pages of data that Server can return us</param>
        private void ExecuteRequest_ForPage(List <SiteWorkbook> onlineWorkbooks, int pageToRequest, out int totalNumberPages)
        {
            int pageSize = urls.PageSize;

            if (pageToRequest < 1)
            {
                pageToRequest = 1;
            }
            //Create a web request, in including the users logged-in auth information in the request headers
            var urlQuery   = urls.UrlDownloadWorkbooksForSite(Login, pageSize, pageToRequest);
            var webRequest = CreateLoggedInRequest(urlQuery, HttpMethod.Get);

            Login.Logger.Information("Web request: " + urlQuery);
            var response = SendHttpRequest(webRequest);
            var xmlDoc   = GetHttpResponseAsXml(response);

            //Get all the workbook nodes
            var xDoc             = xmlDoc.ToXDocument();
            var workbookElements = xDoc.Root.Descendants(XName.Get("workbook", xmlNamespace));

            //Get information for each of the data sources
            foreach (var element in workbookElements)
            {
                try
                {
                    var workbook = ParseWorkbookElement(element);
                    onlineWorkbooks.Add(workbook);
                }
                catch
                {
                    Login.Logger.Error("Error parsing workbook: " + element.Value);
                }
            } //end: foreach

            //-------------------------------------------------------------------
            //Get the updated page-count
            //-------------------------------------------------------------------
            var paginationElement = xDoc.Root.Descendants(XName.Get("pagination", xmlNamespace)).FirstOrDefault();

            totalNumberPages = GetPageCount(paginationElement, pageSize);
        }