Exemplo n.º 1
0
        /// <summary>
        /// Fetch the list of Providers from the CDN server.
        /// </summary>
        /// <remarks>
        /// If any provider configurations are returned from the server then
        /// override the local list of providers with the server's list.
        /// This methods attemps to download the logo, URL, and other information
        /// about the provider from the server.
        /// </remarks>
        /// <param>void</param>
        /// <returns>Task<bool></returns>
        private async Task <bool> LoadJsonProvidersAsync()
        {
            var imgCachePath = BuildStoragePath("img");

            try
            {
                List <VATRPDomain> domains = await Utilities.JsonWebRequest.MakeJsonWebRequestAsync <List <VATRPDomain> >(CDN_DOMAIN_URL);

                //  Added 3/3/2017 fjr Override Local Providers with the server's List
                if (m_OverRideLocalProvidersList)
                {
                    if (domains != null &&
                        domains.Count > 0)
                    {
                        ProviderService.ClearProvidersList();
                        VATRPServiceProvider CustomProvider = new VATRPServiceProvider();
                        CustomProvider.Address = null;
                        CustomProvider.Label   = "Custom";
                        ProviderService.AddProvider(CustomProvider);
                    }
                }

                // add these into the cache
                foreach (VATRPDomain domain in domains)
                {
                    VATRPServiceProvider provider = ProviderService.FindProviderLooseSearch(domain.name);
                    if (provider == null)
                    {
                        provider          = new VATRPServiceProvider();
                        provider.Label    = domain.name;
                        provider.Address  = domain.domain;
                        provider.ImageURI = domain.icon2x;
                        provider.IconURI  = domain.icon;
                        ProviderService.AddProvider(provider);
                    }
                    else
                    {
                        // update the provider information
                        provider.Label    = domain.name;
                        provider.Address  = domain.domain;
                        provider.ImageURI = domain.icon2x;
                        provider.IconURI  = domain.icon;
                    }

                    if (provider.ImageURI.NotBlank())
                    {
                        provider.LoadImage(imgCachePath, false);
                    }
                    if (provider.IconURI.NotBlank())
                    {
                        provider.LoadImage(imgCachePath, true);
                    }
                }

                VATRPServiceProvider noLogoProvider = ProviderService.FindProviderLooseSearch("_nologo");
                if (noLogoProvider == null)
                {
                    noLogoProvider = new VATRPServiceProvider();
                    ProviderService.AddProvider(noLogoProvider);
                }
                return(true);
            }
            catch (Exception ex)
            {
                // either the domains were mal-formed or we are not able to get to the internet. If this is the case, then allow the cached/defaults.
                return(false);
            }
        }