Beispiel #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}");
                }
            }
        }
Beispiel #2
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)
            {
            }
        }