Пример #1
0
        private WorldData DynamicToModel(ExpandoObject record, string filePath)
        {
            IDictionary <string, object> recordDict = record;

            string recoveredKey = (from o in recordDict where o.Key.ToLower().Contains("recovered") select o.Key).FirstOrDefault();
            string deathKey     = (from o in recordDict where o.Key.ToLower().Contains("death") select o.Key).FirstOrDefault();
            string confirmedKey = (from o in recordDict where o.Key.ToLower().Contains("confirmed") select o.Key).FirstOrDefault();
            string countryKey   = (from o in recordDict where o.Key.ToLower().Contains("country") select o.Key).FirstOrDefault();
            int    num          = 0;

            DateTime date;

            date = DateTime.TryParseExact(_directory.ExtractDateFromFileName(filePath), "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date) ? date : DateTime.MinValue;

            return(new WorldData
            {
                Country = recordDict[countryKey].ToString(),
                Date = date,
                ConfirmedCases = int.TryParse(recordDict[confirmedKey].ToString(), out num) ? num : 0,
                Recovered = int.TryParse(recordDict[recoveredKey].ToString(), out num)?num:0,
                Death = int.TryParse(recordDict[deathKey].ToString(), out num) ? num : 0
            });
        }