private void ReadSingleCity(IDataRecord record) { var aoguid = record.GetGuid(record.GetOrdinal("AOGUID")); var code = record.GetString(record.GetOrdinal("REGIONCODE")); var offname = record.GetString(record.GetOrdinal("OFFNAME")); var prefix = record.GetString(record.GetOrdinal("SHORTNAME")); var citycode = record.GetString(record.GetOrdinal("CITYCODE")); var areacode = record.GetString(record.GetOrdinal("AREACODE")); var id = int.Parse($"{code}{areacode}{citycode}"); var nregion = new City { Id = id, Name = offname, Slug = _trans.Transliterate(offname).GetWebSafe(), Prefix = $"{prefix}.", Guid = aoguid, RegionId = int.Parse(code) }; var pos = record.GetOrdinal("PARENTGUID"); if (!record.IsDBNull(pos)) { var parent = record.GetGuid(pos); nregion.Parent = GetParent(parent); } Cityes.Add(nregion); }
public async Task <List <GoogleDriveFolder> > SeedCacheAsync(bool force = false) { var categories = MemoryCache.Default.Get("categories") as List <GoogleDriveFolder>; if (force || categories == null) { logger.Info("seeding cache"); var dataSvc = new PhotoDataSvcWrapper(); categories = await Task.Run(async() => await dataSvc.GetCategoriesAsync()); var translitParser = new RuEngParser(); var separators = new[] { ' ', ',', '_', '.' }; Func <string, string> aliasFactory = (e) => { return(string.Join("-", e.Split(separators, StringSplitOptions.RemoveEmptyEntries) .Select(ee => translitParser.Transliterate(ee) .Replace("`", "")))); }; categories.ForEach(e => { e.Alias = aliasFactory(e.Name); }); foreach (var category in categories) { var byCategory = await Task.Run(async() => await dataSvc.GetByCategoryAsync(category.Id)); byCategory.ForEach(e => { e.Alias = aliasFactory(e.Name); e.ParentAlias = category.Alias; }); category.Children = byCategory; } MemoryCache.Default.Remove("categories"); MemoryCache.Default.Set("categories", categories, new CacheItemPolicy()); } return(categories); }