/// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private List<ISport> XMLParse1()
        {
            List<ISport> sport = 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
                while (iteratorSport.MoveNext())
                {
                    XPathNavigator _sportNameNavigator = iteratorSport.Current.Clone();
                    int feedContentSport = Convert.ToInt32(_sportNameNavigator.GetAttribute("feedContents", ""));
                    if (feedContentSport > 0)
                    {
                        ISport _sport = new Sport();
                        _sport.ID = Convert.ToInt32(_sportNameNavigator.GetAttribute("id", ""));
                        _sport.Name = _sportNameNavigator.Value;
                        //Add sport to List
                        // sports.Add(_sport);
                        //league- event
                        XmlTextReader readerLeague = new XmlTextReader(string.Format(urlPathLeague, _sport.ID));
                        readerLeague.WhitespaceHandling = WhitespaceHandling.Significant;
                        XPathDocument docLeague = new XPathDocument(readerLeague, XmlSpace.Preserve);
                        XPathNavigator navLeague = docLeague.CreateNavigator();

                        XPathExpression exprLeague;
                        exprLeague = navLeague.Compile("/rsp/leagues/league");
                        XPathNodeIterator iteratorLeague = navLeague.Select(exprLeague);
                        // Loop all Leagues in each sport
                        while (iteratorLeague.MoveNext())
                        {
                            XPathNavigator _eventNameNavigator = iteratorLeague.Current.Clone();
                            int feedContentLeague = Convert.ToInt32(_sportNameNavigator.GetAttribute("feedContents", ""));
                            if (feedContentLeague > 0)
                            {
                                ILeague _league = new League();
                                _league.ID = Convert.ToInt32(_eventNameNavigator.GetAttribute("id", ""));
                                _league.Name = _eventNameNavigator.Value;
                                //Add the current League to the latest sport
                                sports[sports.Count - 1].Leagues.Add(_league);

                                //match - home team - awayteam
                                XmlTextReader readerMatch = new XmlTextReader(string.Format(urlPathFeed, _sport.ID, _league.ID));
                                readerMatch.WhitespaceHandling = WhitespaceHandling.Significant;
                                XPathDocument docMatch = new XPathDocument(readerMatch, XmlSpace.Preserve);
                                XPathNavigator navMatch = docMatch.CreateNavigator();

                                XPathExpression exprematch;
                                exprematch = navMatch.Compile("/rsp/fd/sports/sport/leagues/league");
                                XPathNodeIterator iteratorMatch = navMatch.Select(exprematch);
                                // Loop in each League
                                while (iteratorMatch.MoveNext())
                                {
                                    XPathNavigator _matchNameNavigator = iteratorMatch.Current.Clone();

                                    XPathExpression exprematchEvent;
                                    exprematchEvent = _matchNameNavigator.Compile("events/event");
                                    XPathNodeIterator iteratorMatchEvent = _matchNameNavigator.Select(exprematchEvent);
                                    while (iteratorMatchEvent.MoveNext())
                                    {
                                        //  _matchId++;
                                        XPathNavigator _matchEventNameNavigator = iteratorMatchEvent.Current.Clone();
                                        IMatch _match = new Match();
                                        _match.ID = Convert.ToInt32(_matchEventNameNavigator.GetAttribute("id", "")); ;
                                        //_match.eventId = _eventId;
                                        //_match.nameMatch = _matchNameNavigator.GetAttribute("name", "");
                                        _match.HomeTeam = _matchEventNameNavigator.SelectSingleNode("homeTeam").SelectSingleNode("name").Value;
                                        _match.AwayTeam = _matchEventNameNavigator.SelectSingleNode("awayTeam").SelectSingleNode("name").Value;
                                        _match.StartDateTime = Convert.ToDateTime(_matchEventNameNavigator.SelectSingleNode("startDateTime").Value);
                                        // Add the match into current League

                                        // Loop all in Periods
                                        if (_matchEventNameNavigator.HasChildren)
                                        {
                                            XPathExpression exprebet;
                                            exprebet = _matchEventNameNavigator.Compile("periods/period");
                                            XPathNodeIterator iteratorBet = _matchEventNameNavigator.Select(exprebet);
                                            //Loop each period
                                            while (iteratorBet.MoveNext())
                                            {
                                                //  _betId++;
                                                XPathNavigator _betNameNavigator = iteratorBet.Current.Clone();
                                                IPeriod _period = new Period();
                                                _period.Description = _betNameNavigator.SelectSingleNode("description").Value; ;

                                                // Add period to Match

                                                //handicap
                                                XPathExpression exprehandicap;
                                                exprehandicap = _matchEventNameNavigator.Compile("spreads/spread");
                                                XPathNodeIterator iteratorHandicap = _matchEventNameNavigator.Select(exprehandicap);
                                                //total
                                                XPathExpression expretotal;
                                                expretotal = _matchEventNameNavigator.Compile("totals/total");
                                                XPathNodeIterator iteratorTotal = _matchEventNameNavigator.Select(expretotal);
                                                //moneyline
                                                XPathExpression expremoneyline;
                                                expremoneyline = _matchEventNameNavigator.Compile("moneyLine");
                                                XPathNodeIterator iteratorMoneyLine = _matchEventNameNavigator.Select(expremoneyline);

                                                while (iteratorHandicap.MoveNext())
                                                {
                                                    XPathNavigator _choiceNameNavigator = iteratorHandicap.Current.Clone();
                                                    ISpread _spread = new Spread();
                                                    _spread.AwaySpread = float.Parse(_choiceNameNavigator.SelectSingleNode("awaySpread").Value);
                                                    _spread.AwayPrice = float.Parse(_choiceNameNavigator.SelectSingleNode("awayPrice").Value);
                                                    _spread.HomeSpread = float.Parse(_choiceNameNavigator.SelectSingleNode("homeSpread").Value);
                                                    _spread.HomePrice = float.Parse(_choiceNameNavigator.SelectSingleNode("homePrice").Value);
                                                    _period.Spreads.Add(_spread);
                                                }

                                                while (iteratorTotal.MoveNext())
                                                {
                                                    XPathNavigator _choiceNameNavigator = iteratorTotal.Current.Clone();
                                                    ITotal _total = new Total();
                                                    _total.Point = float.Parse(_choiceNameNavigator.SelectSingleNode("points").Value);
                                                    _total.OverPrice = float.Parse(_choiceNameNavigator.SelectSingleNode("overPrice").Value);
                                                    _total.UnderPrice = float.Parse(_choiceNameNavigator.SelectSingleNode("underPrice").Value);
                                                    _period.Totals.Add(_total);

                                                }

                                                while (iteratorMoneyLine.MoveNext())
                                                {
                                                    XPathNavigator _choiceNameNavigator = iteratorMoneyLine.Current.Clone();
                                                    IMoneyLine _moneyline = new MoneyLine();

                                                    _moneyline.AwayPrice = float.Parse(_choiceNameNavigator.SelectSingleNode("awayPrice").Value);
                                                    _moneyline.HomePrice = float.Parse(_choiceNameNavigator.SelectSingleNode("homePrice").Value);
                                                    _moneyline.DrawPrice = float.Parse(_choiceNameNavigator.SelectSingleNode("drawPrice").Value);
                                                    _period.MoneyLines.Add(_moneyline);
                                                }

                                                _match.Periods.Add(_period);
                                            }

                                            _league.Matches.Add(_match);

                                        }

                                    }

                                }

                                _sport.Leagues.Add(_league);
                            }

                        }
                        sport.Add(_sport);

                    }

                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                sports = null;
            }
            return sport;
        }
        /// <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>
        /// 
        /// </summary>
        /// <param name="iteratorSport"></param>
        /// <returns></returns>
        private ISport SportPinnacleParse(String urlPathLeague, String urlPathFeed, XPathNodeIterator iteratorSport)
        {
            ISport _sport = new Sport();
            XPathNavigator _sportNameNavigator = iteratorSport.Current.Clone();
            int feedContentSport = Convert.ToInt32(_sportNameNavigator.GetAttribute("feedContents", ""));
            if (feedContentSport > 0)
            {
                // ISport _sport = new Sport();
                _sport.ID = Convert.ToInt32(_sportNameNavigator.GetAttribute("id", ""));
                _sport.Name = _sportNameNavigator.Value;

                //Add sport to List
                // sports.Add(_sport);
                //league- event
                XmlTextReader readerLeague = new XmlTextReader(string.Format(urlPathLeague, _sport.ID));
                readerLeague.WhitespaceHandling = WhitespaceHandling.Significant;
                XPathDocument docLeague = new XPathDocument(readerLeague, XmlSpace.Preserve);
                XPathNavigator navLeague = docLeague.CreateNavigator();

                XPathExpression exprLeague;
                exprLeague = navLeague.Compile("/rsp/leagues/league");
                XPathNodeIterator iteratorLeague = navLeague.Select(exprLeague);
                // Loop all Leagues in each sport
                while (iteratorLeague.MoveNext())
                {
                    ILeague _league = LeaguePinnacleParse(urlPathFeed, _sport.ID, _sportNameNavigator, iteratorLeague);
                    if (_sport.Leagues == null)
                    {
                        _sport.Leagues = new List<ILeague>();
                    }
                    //check league not null
                    if (_league != null)
                        _sport.Leagues.Add(_league);
                }
            }
            return _sport;
        }