/// <summary> /// /// </summary> /// <param name="sportType"></param> /// <returns></returns> public ISport Sport(Constant.SportType sportType) { foreach (ISport sp in sports) { if (sp.ID == (int)sportType) { return(sp); } } return(null); }
/// <summary> /// /// </summary> /// <param name="sport"></param> /// <returns></returns> private ISport SportTitabetParse(Constant.SportType sport) { ISport _sport = new Sport(); string urlPath = Constant.SourceXML.TITABETURL; string mainSport = ConfigurationManager.AppSettings["TITANBETMAINSPORT"].ToString(); XmlTextReader reader = new XmlTextReader(urlPath); // Skip non-significant whitespace reader.WhitespaceHandling = WhitespaceHandling.Significant; XPathDocument doc = new XPathDocument(reader, XmlSpace.Preserve); XPathNavigator nav = doc.CreateNavigator(); int sportID = 0; /* * * Cricket * Handball * Horse Racing * Motor Sports * Boxing * Golf * Tennis * */ switch (sport) { case Constant.SportType.CRICKET: sportID = 33948; break; case Constant.SportType.HANDBALL: sportID = 33945; break; case Constant.SportType.HORSE_RACING: sportID = 55882; break; case Constant.SportType.MOTOR_SPORTS: sportID = 0; break; case Constant.SportType.BOXING: sportID = 6638; break; case Constant.SportType.GOLF: sportID = 0; break; case Constant.SportType.TENNIS: sportID = 2490; break; } XPathExpression exprSport; exprSport = nav.Compile("/bookmaker/sport[@id='" + sportID + "']"); XPathNodeIterator iteratorSport = nav.Select(exprSport); while (iteratorSport.MoveNext()) { XPathNavigator _sportNameNavigator = iteratorSport.Current.Clone(); _sport.ID = sportID; _sport.Name = _sportNameNavigator.GetAttribute("name", ""); // League if (_sportNameNavigator.HasChildren) { XPathExpression exprevent; exprevent = _sportNameNavigator.Compile("group"); XPathNodeIterator iteratorEvent = _sportNameNavigator.Select(exprevent); while (iteratorEvent.MoveNext()) { ILeague _league = LeagueTitabetParse(iteratorEvent, _sport.ID); if (_sport.Leagues == null) { _sport.Leagues = new List <ILeague>(); } //check league not null if (_league != null) { _sport.Leagues.Add(_league); } } } } return(_sport); }
private List <ISport> XMLParse() { List <ISport> _sports = new List <ISport>(); string urlPathSport = string.Empty; string urlPathLeague = string.Empty; string urlPathFeed = string.Empty; urlPathSport = Constant.SourceXML.PINNACLESPORTSURL; if (urlPathSport.IndexOf("http://") > -1) { urlPathLeague = Constant.SourceXML.PINNACLELEAGUEURL; urlPathFeed = Constant.SourceXML.PINNACLEFEEDURL; } else { string[] arrPlitUrl = urlPathSport.Split('_'); string timetick = arrPlitUrl[2].Replace(".xml", ""); urlPathLeague = arrPlitUrl[0] + "_league_{0}_" + timetick + ".xml"; urlPathFeed = arrPlitUrl[0] + "_feed_{0}_{1}_" + timetick + ".xml"; } //sport XmlTextReader readerSport = new XmlTextReader(urlPathSport); // Skip non-significant whitespace readerSport.WhitespaceHandling = WhitespaceHandling.Significant; XPathDocument doc = new XPathDocument(readerSport, XmlSpace.Preserve); XPathNavigator nav = doc.CreateNavigator(); XPathExpression exprSport; exprSport = nav.Compile("/rsp/sports/sport"); XPathNodeIterator iteratorSport = nav.Select(exprSport); // try // { // Loop all sports int test = 0; while (iteratorSport.MoveNext()) { XPathNavigator _sportNameNavigator = iteratorSport.Current.Clone(); int feedContentSport = Convert.ToInt32(_sportNameNavigator.GetAttribute("feedContents", "")); int sportID = int.Parse(_sportNameNavigator.GetAttribute("id", "")); /* * Algorithm * 2. Loop all SPORT in PINACLE * VAR SOURCETYPE = null * 3. If SPORT=BOXING THEN * IF NO DATA from PINACLE THEN * Get from TITABET * SOURCETYPE = TITABET * -GROUPS-LEAGUES * -EVENTS-MATCHES * -MARKETS * -OUTCOMES * //ELSE * // Get data from PINACLE * END IF * END IF * 3. If SPORT=CRICKET THEN * IF NO DATA from PINACLE THEN * Get from TITABET * SOURCETYPE = TITABET * // ELSE * // Get data from PINACLE * END IF * END IF * 3. If SPORT=SOCCER THEN * IF NO DATA from TITABET THEN * // Get from PINACLE * // ELSE * Get data from TITABET * SOURCETYPE = TITABET * END IF * END IF * 3. If SPORT=TENNIS THEN * IF NO DATA from PINACLE THEN * Get from TITABET * SOURCETYPE = TITABET * // ELSE * // Get data from PINACLE * END IF * END IF * 3.1 IF SOURCETYPE== TITABET THEN * * * EXIT LOOP * END IF * 4.Get each LEAGUE of SPORT */ // if (feedContentSport > 0) // { ISport _sport = new Sport(); Constant.SportType _sportType = Constant.SportType.EMPTY;; if (sportID == (int)Constant.SportType.BOXING) { if (feedContentSport == 0) // No data from Pinacle { _sport = SportTitabetParse(Constant.SportType.BOXING); _sportType = Constant.SportType.BOXING; } } if (sportID == (int)Constant.SportType.CRICKET) { if (feedContentSport == 0) // No data from Pinacle { _sport = SportTitabetParse(Constant.SportType.CRICKET); _sportType = Constant.SportType.CRICKET; } } //if (sportID == (int)Constant.SportType.SOCCER) //{ // _sport = SportTitabetParse(Constant.SportType.SOCCER); // if (_sport != null) // { // _sportType = Constant.SportType.SOCCER; // } //} if (sportID == (int)Constant.SportType.TENNIS) { if (feedContentSport == 0) // No data from Pinacle { _sport = SportTitabetParse(Constant.SportType.TENNIS); _sportType = Constant.SportType.TENNIS; } } // Check to see if gets data from TITABET if (_sportType != Constant.SportType.EMPTY) { _sport.SportFeedType = Constant.SourceFeedType.TITANBET; _sports.Add(_sport); } else { _sport = SportPinnacleParse(urlPathLeague, urlPathFeed, iteratorSport); _sport.SportFeedType = Constant.SourceFeedType.PINNACLESPORTS; _sports.Add(_sport); } //{ // get data from Pinacle // ISport _sport = SportPinnacleParse(urlPathLeague, urlPathFeed, iteratorSport); // _sports.Add(_sport); // } //else // Get from Titabet // { //} // } } return(_sports); }
/// <summary> /// Get Sport /// </summary> /// <param name="type">Sport type</param> /// <returns>Sport</returns> public ISport GetSport(Constant.SportType type) { return(obj.Sport(type)); }