public static HomeViewModel Load() { HomeViewModel hmv = new HomeViewModel(); hmv.Roles = LoadRoles(); hmv.Ranks = LoadRanks(); IList <Champion> champions; using (var data = new SqlData()) { champions = data.GetChampions(); } hmv.Champions = new List <ChampionViewModel>(); foreach (var champion in champions) { var championVM = new ChampionViewModel(); championVM.Id = champion.Id; championVM.Name = champion.Name; string linkName; if (champion.Name.Contains(" ")) { linkName = champion.Name.Replace(" ", string.Empty).Replace("'", string.Empty).Replace(".", string.Empty); } else { linkName = champion.Name.Replace("'", string.Empty).Replace(".", string.Empty).ToLower().FirstLetterToUpper(); } switch (linkName) { case "Kogmaw": linkName = "KogMaw"; break; case "Reksai": linkName = "RekSai"; break; case "Fiddlesticks": linkName = "FiddleSticks"; break; case "Wukong": linkName = "MonkeyKing"; break; } championVM.ImageUrl = string.Format(@"http://ddragon.leagueoflegends.com/cdn/5.16.1/img/champion/{0}.png", linkName); hmv.Champions.Add(championVM); } return(hmv); }
private static void LoadCache() { if (DateTime.Now < expiration) return; try { rwls.EnterWriteLock(); if (DateTime.Now < expiration) return; using (var data = new SqlData()) { cache = new ConcurrentDictionary<int, Champion>(data.GetChampions().ToDictionary(c => c.Id, c => c)); } expiration = DateTime.Now.AddHours(2); } finally { rwls.ExitWriteLock(); } }
private static void LoadCache() { if (DateTime.Now < expiration) { return; } try { rwls.EnterWriteLock(); if (DateTime.Now < expiration) { return; } using (var data = new SqlData()) { cache = new ConcurrentDictionary <int, Champion>(data.GetChampions().ToDictionary(c => c.Id, c => c)); } expiration = DateTime.Now.AddHours(2); } finally { rwls.ExitWriteLock(); } }