internal void CompleteMatch(MyMatch match) { match.MatchCompleted(); MyMatch matchtoupdate = context.Matches.Where(m => m.MatchId == match.MatchId).FirstOrDefault(); context.Entry(matchtoupdate).CurrentValues.SetValues(match); }
public void AddMatchToMatchHistory(long summonerid, MyMatch match) { if (Summoners.ContainsKey(summonerid)) { MySummoner sum; Summoners.TryGetValue(summonerid, out sum); sum.AddMatchToHistory(match); } }
public void AddMatch(MyMatch match) { long matchid = match.MatchId; if (!Matches.ContainsKey(matchid)) { Matches.Add(matchid, match); context.Matches.Add(match); context.SaveChanges(); } }
//public void StartCrawl(Region region, int numberOfSummoners = 50) //{ // InitiateSeedList(); // using(context){ // while (Summoners.Count() < numberOfSummoners) // { // foreach (long summonerid in seedList) // { // Console.WriteLine("Get Match history"); // ChooseApiKey(); // var matchHistory = Task.Run(async () => { return await api.Match.GetMatchListAsync(region, summonerid, queues: new List<int> { 420 }, beginTime: DateTime.Now.AddDays(-5)); }).Result; // Console.WriteLine("Match history retrieved"); // foreach (MatchReference mr in matchHistory.Matches) // { // ChooseApiKey(); // Match match = Task.Run(async () => { return await api.Match.GetMatchAsync(region, mr.GameId); }).Result; // MyMatch matchToComplete = new MyMatch(match); // context.Matches.Add(matchToComplete); // context.SaveChanges(); // Console.WriteLine("Match started"); // if (!matchCompletedList.Contains(matchToComplete.MatchId)) // { // CompleteMatch(region, matchToComplete); // } // } // } // StartCrawl(region); // } // } //} public void StartCrawlQueue(Region region, int numberOfMatches = 50) { InitiateSeedList(); try { using (context) { while (Matches.Count() < numberOfMatches) { while (seedQueue.Count != 0) { Console.WriteLine("Get Match history"); MySummoner summoner = seedQueue.Dequeue(); if (!summonersCompletedList.Contains(summoner.SummonerId)) { ChooseApiKey(); System.Threading.Thread.Sleep(500); var matchHistory = Task.Run(async() => { return(await api.Match.GetMatchListAsync(region, summoner.AccountId, queues: new List <int> { 420 }, beginTime: DateTime.Now.AddDays(-5))); }).Result; Console.WriteLine("Match history retrieved"); foreach (MatchReference mr in matchHistory.Matches) { ChooseApiKey(); System.Threading.Thread.Sleep(500); Match match = Task.Run(async() => { return(await api.Match.GetMatchAsync(region, mr.GameId)); }).Result; MyMatch matchToComplete = new MyMatch(match); Matches.AddMatch(matchToComplete); Console.WriteLine("Match started"); if (!matchCompletedList.Contains(matchToComplete.MatchId)) { CompleteMatch(region, matchToComplete); } } Summoners.CompleteSummoner(summoner); Console.WriteLine("Match History complete"); } } } } } catch (Exception e) { Console.WriteLine("Application restarted with error: " + e.Message + "\n" + e.StackTrace); StartCrawlQueue(region, numberOfMatches); } }
private void CompleteMatch(Region region, MyMatch match) { foreach (MyParticipant p in match.Participants) { ChooseApiKey(); System.Threading.Thread.Sleep(500); MySummoner sum = new MySummoner(Task.Run(async() => { return(await api.Summoner.GetSummonerBySummonerIdAsync(region, p.SummonerId)); }).Result); if (!summonersCompletedList.Contains(sum.SummonerId)) { Summoners.AddSummoner(sum); seedQueue.Enqueue(sum); Console.WriteLine("Summoner added!"); } } matchCompletedList.Add(match.MatchId); Matches.CompleteMatch(match); Console.WriteLine("Match added"); }
public void AddMatchToHistory(MyMatch match) { MatchHistory.Add(match); }