示例#1
0
        public FootballScore GetLatestFootballScore(string team1Name, string team2Name)
        {
            FootballScore latestFootballScore = new FootballScore()
            {
                PublishedDateTime = DateTime.MinValue
            };
            //= new FootballScore();
            // 1. load all aliases for the two runners (team1 and team2). will need to add the
            //      method to do that in utilities project.
            NameAliases team1NameAliases = RunnerAliasesHelper.GetNameAliasesForRunner(team1Name);
            NameAliases team2NameAliases = RunnerAliasesHelper.GetNameAliasesForRunner(team2Name);

            // 2. get scorespro rss
            _feed = SyndicationFeed.Load(_xmlReader);
            if (_feed == null)
            {
                return(latestFootballScore);
            }
            foreach (SyndicationItem item in _feed.Items)
            {
                // 3. for each feed:
                //      a. parse into football score object
                //      b. check if it contains both home and away alias
                //      c. if yes then cache it if latest. (same score could appear twice)
                Console.WriteLine(item.Title.Text);
                FootballScore parsedScore = Parser.ParseScoresProFootballScore(item);
                // set parsed score team names according to the caller of this method
                if (team1NameAliases.Aliases.Contains(parsedScore.HomeName) && team2NameAliases.Aliases.Contains(parsedScore.AwayName))
                {
                    parsedScore.HomeName = team1Name;
                    parsedScore.AwayName = team2Name;
                    if (parsedScore.PublishedDateTime > latestFootballScore.PublishedDateTime)
                    {
                        latestFootballScore = parsedScore;
                    }
                }
                if (team2NameAliases.Aliases.Contains(parsedScore.HomeName) && team1NameAliases.Aliases.Contains(parsedScore.AwayName))
                {
                    parsedScore.HomeName = team2Name;
                    parsedScore.AwayName = team1Name;
                    if (parsedScore.PublishedDateTime > latestFootballScore.PublishedDateTime)
                    {
                        latestFootballScore = parsedScore;
                    }
                }
            }
            // 4. return the latest score
            return(latestFootballScore);
        }
示例#2
0
        private void InitialiseData()
        {
            InitialiseBettingExchangeService();

            List <Runner> runners = _provider.GetRunnersForMarket(ProviderName, MarketId);

            _runnersIndexedById = new Dictionary <string, Runner>();

            // the loop does three things: 1. creates the dictionary 2. initialises alt1RunnerId and alt2RunnerId 3. composes match name
            _alt1RunnerId = _alt2RunnerId = string.Empty;
            _matchName    = string.Empty;
            string alt1Name = string.Empty, alt2Name = string.Empty;

            foreach (Runner runner in runners)
            {
                _runnersIndexedById.Add(runner.Id, runner);
                if (runner.Id != ChosenRunnerId)
                {
                    if (string.IsNullOrEmpty(_alt1RunnerId))
                    {
                        _alt1RunnerId = runner.Id;
                        alt1Name      = runner.Title;
                        if (alt1Name != "The Draw")
                        {
                            _opponentRunnerName = RunnerAliasesHelper.GetNameAliasesForAlias(alt1Name).RunnerName;
                        }
                    }
                    else
                    {
                        _alt2RunnerId = runner.Id;
                        alt2Name      = runner.Title;
                        if (alt2Name != "The Draw")
                        {
                            _opponentRunnerName = alt2Name;
                        }
                    }
                }
                else
                {
                    _chosenRunnerName = RunnerAliasesHelper.GetNameAliasesForAlias(runner.Title).RunnerName;
                }
                _matchName += runner.Title + "-";
            }
            _matchName = _matchName.Substring(0, _matchName.Length - 1);
            Logger.Write(Resources.ProjectName, _matchName, "Initialising.");
            Logger.Write(Resources.ProjectName, _matchName, "Alt1: " + alt1Name + "; Alt2: " + alt2Name);
            Logger.Write(Resources.ProjectName, _matchName, "Chosen Odds: " + ChosenOdds);
        }