Esempio n. 1
0
        public void ThrottledDownloadTest()
        {
            MatchInfoRequester client  = new MatchInfoRequester(3);
            List <string>      results = new List <string>();

            Console.WriteLine("starting");
            for (long i = 3607383684; i < 3607383694; i++)
            {
                try
                {
                    string result = client.GetJsonFormattedMatchInfo(i).Result;
                    Console.WriteLine("Match downloaded " + i);
                    Console.WriteLine(result.Substring(0, 10));
                }
                catch (AggregateException e)
                {
                    if (e.InnerExceptions.Count == 1 && e.InnerExceptions[0].GetType() == typeof(System.Net.Http.HttpRequestException)) //if its a webexception caught in an aggregate
                    {
                        Console.WriteLine("match not found");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Esempio n. 2
0
            }                                                   //reference to the shared queu
            public void DownloadThread()
            {
                //each thread has its own requester
                MatchInfoRequester requester = new MatchInfoRequester(MaxRequestsPerSecond);
                //and its own parser
                DBObjectFactory factory = new DBObjectFactory();

                //lets goooooo
                //logging statement: thread x starting to download

                //download pattern is as follows: if n = numthreads then the nth thread downloads matches n + k*n
                for (long i = start; i < highest; i += ThreadAmount)
                {
                    log.Info("Attempting to download match: " + i.ToString());
                    try
                    {
                        string json = requester.GetJsonFormattedMatchInfo(i).Result;
                        queuRef.Enqueue(factory.CreateMatchFromJson(json));
                    }
                    catch (AggregateException e)
                    {
                        //if its a httpexception caught inside an aggregate
                        if (e.InnerExceptions.Count == 1 && e.InnerExceptions[0].GetType() == typeof(System.Net.Http.HttpRequestException))
                        {
                            log.Info("Exception thrown when downloading match: " + i.ToString() + Environment.NewLine + e.InnerExceptions[0].Message);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
Esempio n. 3
0
        public void MatchInfoRequesterTest()
        {
            MatchInfoRequester client = new MatchInfoRequester();

            string result = client.GetJsonFormattedMatchInfo("3607383685").Result;

            Assert.IsNotNull(result);
            Console.WriteLine(result);
        }
Esempio n. 4
0
        public void InsertTest()
        {
            Random rand    = new Random();
            long   matchid = 3607300000 + rand.Next(10000, 55555);

            Console.WriteLine("Attempting to download the following match: {0}", matchid);
            MatchInfoRequester requester = new MatchInfoRequester();
            string             json      = requester.GetJsonFormattedMatchInfo(matchid.ToString()).Result;
            DBObjectFactory    factory   = new DBObjectFactory();
            MatchInfoWriter    writer    = new MatchInfoWriter();
            Match match = factory.CreateMatchFromJson(json);

            writer.Insert(match);
        }