コード例 #1
0
 //Stores a single MatchItem in the database
 public Task <int> SaveItemAsync(MatchItem item)
 {
     if (item.Id != 0)
     {
         return(database.UpdateAsync(item));
     }
     else
     {
         return(database.InsertAsync(item));
     }
 }
コード例 #2
0
        //Scrapes the match data from the webpage associated with a given age group.
        //Creates a new MatchItem for each match detected the webpage and stores it in the database.
        public void ScrapeMatches(string AgeGroup)
        {
            string url = AgeGroupToURL(AgeGroup);

            var web = new HtmlWeb();
            var doc = web.Load(url);

            string ageGroup = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/div[3]").InnerHtml;
            string bracket  = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/h3[1]").InnerText;

            int numDates = doc.DocumentNode.SelectNodes("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table").Count;

            for (int i = 1; i <= numDates; i++)
            {
                string date = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table[" + i + "]/tr[1]/th").InnerText;

                int numMatches = doc.DocumentNode.SelectNodes("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table[" + i + "]/tr").Count - 2;
                for (int j = 3; j < (numMatches + 3); j++)
                {
                    var newMatch = new MatchItem
                    {
                        AgeGroup  = ageGroup,
                        Bracket   = bracket,
                        Date      = date,
                        Time      = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table[" + i + "]/tr[" + j + "]/td[2]/div").InnerText,
                        HomeTeam  = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table[" + i + "]/tr[" + j + "]/td[3]/a").InnerText,
                        HomeScore = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table[" + i + "]/tr[" + j + "]/td[4]/div[1]/span[1]").InnerText,
                        AwayScore = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table[" + i + "]/tr[" + j + "]/td[4]/div[1]/span[2]").InnerText,
                        AwayTeam  = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table[" + i + "]/tr[" + j + "]/td[5]/a").InnerText,
                        Location  = doc.DocumentNode.SelectSingleNode("//*[@id=\"aspnetForm\"]/table/tr/td[2]/table/tr/td/div[1]/div/table[" + i + "]/tr[" + j + "]/td[6]/div[1]/a").InnerText
                    };

                    SaveItemAsync(newMatch);
                }
            }
        }
コード例 #3
0
 //Deletes a given MatchItem from the database
 public Task <int> DeleteItemAsync(MatchItem item)
 {
     return(database.DeleteAsync(item));
 }