예제 #1
0
        private static async Task ValidateService(string apiBaseUrl, PaginationResults paginationResults, dynamic service, WebServiceReader webServiceReader)
        {
            dynamic obj = service;

            try
            {
                WebServiceResponse result = await webServiceReader.ConvertToDynamic(apiBaseUrl + "/services/" + service.id);

                if (result != null)
                {
                    obj = result.Data;
                    paginationResults.HasAllowOrigin = result.HasAllowOrigin;
                }

                if (obj == null)
                {
                    obj = service;
                    paginationResults.MissingDetailIDs.Add(Convert.ToString(service.id));
                }
            }
            catch
            {
                try
                {
                    paginationResults.MissingDetailIDs.Add(Convert.ToString(service.id));
                }
                catch
                {
                    //bad data don't stop the test for this
                }
            }

            paginationResults.Items.Add(obj);
        }
예제 #2
0
        public async Task PaginateServices(string apiBaseUrl, string id, ServiceProcessorAsync processor, WebServiceReader webServiceReader, string parameters = "", int?totalPagesOverride = null)
        {
            int pageNo     = 0;
            int totalPages = totalPagesOverride ?? 1;

            while (pageNo < totalPages)
            {
                pageNo++;

                string serviceUrl = apiBaseUrl + "/services/";

                serviceUrl += parameters;

                if (!serviceUrl.Contains("?"))
                {
                    serviceUrl += "?";
                }
                else
                {
                    serviceUrl += "&";
                }

                WebServiceResponse serviceList = await webServiceReader.ConvertToDynamic(serviceUrl + "page=" + pageNo);

                try
                {
                    if (serviceList == null)
                    {
                        continue;
                    }
                    int tmp = Convert.ToInt32(serviceList.Data.totalPages);
                    if (!totalPagesOverride.HasValue || tmp < totalPages)
                    {
                        totalPages = tmp;
                    }
                }
                catch
                {
                    //if this isn't here we will ignore it and just paginate the first page. This issue will be reported upon in pagination
                }

                if (!await processor(serviceList.Data, totalPages, serviceList.HashCode))
                {
                    break;
                }

                ProgressCache.Update(id, pageNo, totalPages);
            }
        }
        private async System.Threading.Tasks.Task <dynamic> GetResourceJSON()
        {
            try
            {
                if (json == null)
                {
                    WebServiceResponse response = await webServiceReader.ConvertToDynamic(ExtendedDataPackage).ConfigureAwait(false);

                    if (response != null)
                    {
                        json = response.Data;
                    }
                }
                return(json);
            }
            catch (Exception e)
            {
                throw new ServiceDirectoryException("Error reading extended data package", e);
            }
        }