コード例 #1
0
        static async Task Main(string[] args)
        {
            var dbManager   = new SqliteDbManager();
            var statService = new ConcreteStatService();

            List <Tuple <string, int> > serviceResults = await statService.GetCountryPopulationsAsync();

            List <Tuple <string, int> > dbResults = await dbManager.GetCountryPopulationsAsync();

            List <Tuple <string, int> > results = AccumulateResults.Aggregate(dbResults, serviceResults);

            PrintResults.Print(results);
        }
コード例 #2
0
        /// <summary>
        /// The method combines the population information of countries obtained from
        /// database and API in Dictionary, if the same country information in both
        /// data sources information from database is given preference.
        /// </summary>
        /// <returns>Dictionary with all the countries and its population
        /// key as country name and value as populations
        /// </returns>
        public Dictionary <string, int> GetCountryPopulations()
        {
            Dictionary <string, int> dict   = sqliteDbManagerImpl.GetCountryPopulations();
            StatsUtilityServices     helper = new StatsUtilityServices();

            IStatService statServiceFromConcrete = new ConcreteStatService();

            List <Tuple <string, int> > listFromConcrete = statServiceFromConcrete.GetCountryPopulations();

            helper.AddPopulationsToDictionary(dict, listFromConcrete);

            Console.WriteLine("Total results and merging both lists --------------------------------------size : " + dict.Count);
            return(dict);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Started");
            Console.WriteLine("Getting DB Connection...");

            ISqlQueries  sql         = new SqlQueries();
            IStatService statService = new ConcreteStatService();

            AggregateCountryPopulation aggregateCountryPopulation = new AggregateCountryPopulation(statService, sql);

            var aggCountryPopulations = aggregateCountryPopulation.AggergateCountryData();

            foreach (var countryPopulation in aggCountryPopulations)
            {
                Console.WriteLine(String.Format("CountryName: {0}, Population: {1}", countryPopulation.CountryName, countryPopulation.Population));
            }

            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Started");
            Console.WriteLine("Getting DB Connection...");

            // Instantiate new list of tuples to house the results from sql query
            List <Tuple <string, int> > baseCountryPopulation = GetCountryPopulationsFromSQLAsync().Result;

            // Retrive other tuple list
            ConcreteStatService         concreteStatService      = new ConcreteStatService();
            List <Tuple <string, int> > countryPopulationFromApi = concreteStatService.GetCountryPopulationsAsync().Result;

            // Merge the tuples with the sql data as the base
            baseCountryPopulation = MergeTupleLists(baseCountryPopulation, countryPopulationFromApi).Result;

            var sorted = baseCountryPopulation.OrderBy(t => t.Item1).ToList();

            foreach (var tuple in sorted)
            {
                Console.WriteLine("{0} - {1}", tuple.Item1, tuple.Item2);
            }
            Console.ReadLine();
        }