Exemple #1
0
        internal void CompleteSummoner(MySummoner summoner)
        {
            summoner.SummonerCompleted();
            MySummoner sumtoupdate = context.Summoners.Where(s => s.SummonerId == summoner.SummonerId).FirstOrDefault();

            context.Entry(sumtoupdate).CurrentValues.SetValues(summoner);
        }
Exemple #2
0
        public void AddSummoner(MySummoner summoner)
        {
            long summonerid = summoner.SummonerId;

            if (!Summoners.ContainsKey(summonerid))
            {
                Summoners.Add(summonerid, summoner);
                context.Summoners.Add(summoner);
                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");
 }