Beispiel #1
0
 public void InsertGoldTurnament(GolfTurnament golf)
 {
     using (SqlConnection objConn = new SqlConnection(OddsConnection.GetConnectionString()))
     {
         try
         {
             SqlCommand cmd = new SqlCommand("sp_GolfSport", objConn);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@Mode", "Insert");
             cmd.Parameters.AddWithValue("@Duration", golf.Duration.Replace(" ", ""));
             cmd.Parameters.AddWithValue("@Turnament", golf.Turnament);
             cmd.Parameters.AddWithValue("@Course", golf.Course.Replace(" ", ""));
             cmd.Parameters.AddWithValue("@Champion", golf.Champion);
             cmd.Parameters.AddWithValue("@Link", golf.Link);
             objConn.Open();
             cmd.ExecuteNonQuery();
             objConn.Close();
         }
         catch (Exception ex)
         {
             objConn.Close();
         }
     }
 }
Beispiel #2
0
        public string CrawlGolfTurnament(string url, string sportid)
        {
            try
            {
                TraceService("Crawling Started: Golf:0 ,SportID:" + sportid + " , URL:" + url + "\n");

                string  html = Helper.GetWebSiteContent(url);
                DataSet ds   = new DataSet();
                HtmlAgilityPack.HtmlDocument doc       = Helper.LoadHtml(html);
                CrawlFirstPageData           crawldata = new CrawlFirstPageData();
                Matches              match             = new Matches();
                XmlDocument          xmldoc            = new XmlDocument();
                List <GolfTurnament> turnamentlist     = new List <GolfTurnament>();
                var row11 = doc.DocumentNode.SelectSingleNode("//div[@class='containerHeight']");

                var row  = row11.SelectNodes(".//a[@class='stats_link']");
                var rows = row11.SelectNodes("//div[@class='stats']");
                if (rows != null)
                {
                    string enddatetime = String.Empty;
                    for (int ii = 0; ii < rows.Count; ii = ii + 0)
                    {
                        GolfTurnament golf = new GolfTurnament();
                        int           i    = ii;
                        try
                        {
                            var n = rows[ii].ParentNode;
                            if (n.Name == "a")
                            {
                                if (n == null)
                                {
                                    golf.Link = "";
                                }
                                else
                                {
                                    golf.Link = "http://wikiform.com.au/oddschecker/" + n.Attributes["href"].Value;
                                }
                            }
                            else
                            {
                                golf.Link = "";
                            }

                            if (rows[ii].Attributes["style"].Value == "clear:both;width:100px;")
                            {
                                golf.Duration = rows[ii].InnerText.Trim();
                                ii           += 1;
                            }
                            else
                            {
                                golf.Duration = "";
                            }
                            if (rows[ii].Attributes["style"].Value == "width:317px;text-decoration:underline;" || rows[ii].Attributes["style"].Value == "width:317px;")
                            {
                                golf.Turnament = rows[ii].InnerText.Trim();
                                ii            += 1;
                            }
                            else
                            {
                                golf.Turnament = "";
                            }
                            if (rows[ii].Attributes["style"].Value == "width:242px;")
                            {
                                golf.Course = rows[ii].InnerText.Trim();
                                ii         += 1;
                            }
                            else
                            {
                                golf.Course = "";
                            }
                            if (rows[ii].Attributes["style"].Value == "width:122px;border-right:0;")
                            {
                                golf.Champion = rows[ii].InnerText.Trim();
                                ii           += 1;
                            }
                            else
                            {
                                golf.Champion = "";
                            }
                            InsertGoldTurnament(golf);
                        }
                        catch (Exception ex)
                        {
                        }
                        if (i == ii)
                        {
                            ii += 1;
                        }
                        turnamentlist.Add(golf);
                    }

                    xmldoc = GenerateXmlGolfTurnament(turnamentlist);
                    //  InsertGoldTurnament(xmldoc, sportid);
                    TraceService("Data Inserted: Golf:0  ,SportID:" + sportid + " , URL:" + url + "\n");
                }
                //ds = crawldata.NewRecords(xmldoc);
                //return ds;
                return("Command completed successfully");
            }
            catch (Exception ex)
            {
                TraceService("Error:0 ,SportID:" + sportid + " , URL:" + url + "\n");
                return(ex.Message);
            }
        }