示例#1
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;
                        }
                    }
                }
            }
        public void CreateMatchFromJsonTest()
        {
            DBObjectFactory factory = new DBObjectFactory();
            string          json    = File.ReadAllText(@"C:\Users\MrMackey\source\repos\OpenDotaInterface\OpenDotaInterfaceTests\3607383684.json");
            Match           match   = factory.CreateMatchFromJson(json);

            Console.WriteLine(match.ToString());
        }
示例#3
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);
        }