示例#1
0
        private static async Task ComputeSync(Container container, UsaGovermentApi api, IEnumerable <UsaCountryModel> countries)
        {
            foreach (var country in countries)
            {
                try
                {
                    UsaCountryInfo info = await api.CountryInfo(country.Code);

                    if (info != null)
                    {
                        CountryService service = container.GetInstance <CountryService>();

                        await service.AddOrUpdate(info, country);
                    }
                    else
                    {
                        Console.WriteLine($"No info for {country.Code}");
                    }
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine($"Failed for {country.Code} {ex.Message}");
                }
            }
        }
示例#2
0
        public async Task <UsaCountryInfo> CountryInfo(string countryCode)
        {
            try
            {
                string url = string.Format(countryInfoUrl, domain, countryCode);

                using (HttpClient client = new HttpClient())
                {
                    string countryInfoPath = await client.GetStringAsync(url);

                    string html = await client.GetStringAsync(domain + countryInfoPath.Trim());

                    var doc = new HtmlDocument();
                    doc.LoadHtml(html);

                    UsaCountryInfo info = factory.Create(doc);

                    return(info);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#3
0
        private static void ComputeAsync(Container container, UsaGovermentApi api, IEnumerable <UsaCountryModel> countries)
        {
            var a = Parallel.ForEach(countries, async(country) =>
            {
                try
                {
                    UsaCountryInfo info = await api.CountryInfo(country.Code);
                    if (info != null)
                    {
                        CountryService service = container.GetInstance <CountryService>();

                        await service.AddOrUpdate(info, country);
                    }
                    else
                    {
                        Console.WriteLine($"No info for {country.Code}");
                    }
                }
                catch (System.Exception ex)
                {
                }
            });

            while (!a.IsCompleted)
            {
            }
        }
示例#4
0
 public static void Update(CountryInfo infoToUpdate, UsaCountryInfo sourceInfo)
 {
     infoToUpdate.Access                   = sourceInfo.Access;
     infoToUpdate.Attorney                 = sourceInfo.Attorney;
     infoToUpdate.GeneralInformation       = sourceInfo.GeneralInformation;
     infoToUpdate.HagueAbductionConvention = sourceInfo.HagueAbductionConvention;
     infoToUpdate.Mediaton                 = sourceInfo.Mediaton;
     infoToUpdate.Return                   = sourceInfo.Return;
 }
示例#5
0
        private async Task Update(Country dbCountry, UsaCountryInfo countryInfo)
        {
            AssistanceInfoFactory.Update(dbCountry.AssistenceInfo, countryInfo.AssistanceInfo);
            CountryInfoFactory.Update(dbCountry.CountryInfo, countryInfo);

            await assistanceRepository.UpdateAsync(dbCountry.Id, dbCountry.AssistenceInfo);

            await countryInfoRepository.UpdateAsync(dbCountry.Id, dbCountry.CountryInfo);

            //TODO: Update Representatieves too
        }
示例#6
0
        public async Task AddOrUpdate(UsaCountryInfo countryInfo, UsaCountryModel country)
        {
            Country dbCountry = await countryRepository.CountryByCodeAsync(country.Code);

            if (dbCountry == null)
            {
                await Add(countryInfo, country);
            }
            else
            {
                await Update(dbCountry, countryInfo);
            }
        }
示例#7
0
        public static CountryInfo Create(UsaCountryInfo sourceInfo)
        {
            var info = new CountryInfo
            {
                Access                   = sourceInfo.Access,
                Attorney                 = sourceInfo.Attorney,
                GeneralInformation       = sourceInfo.GeneralInformation,
                HagueAbductionConvention = sourceInfo.HagueAbductionConvention,
                Mediaton                 = sourceInfo.Mediaton,
                Return                   = sourceInfo.Return
            };

            return(info);
        }
示例#8
0
        public UsaCountryInfo Create(HtmlDocument xml)
        {
            HtmlNode generalInfoContainer = FindGeneralInfoContainer(xml);

            if (generalInfoContainer != null)
            {
                List <HtmlNode> ddElements = GetDdElements(generalInfoContainer);

                UsaCountryInfo info = PopulateCountryInfoModel(xml, ddElements);

                return(info);
            }
            else
            {
                return(null);
            }
        }
示例#9
0
 private async Task Add(UsaCountryInfo countryInfo, UsaCountryModel country)
 {
     Country countryToInsert = CountryFactory.Create(country, AssistanceInfoFactory.Create(countryInfo.AssistanceInfo), CountryInfoFactory.Create(countryInfo));
     await countryRepository.InsertAsync(countryToInsert);
 }