示例#1
0
        private void UpdateMatchup(db.NFL_Matchup matchup, KeyValuePair <string, API.NFL.Matchup> node)
        {
            matchup.status = node.Value.qtr;
            matchup.eid    = Convert.ToInt64(node.Key);
            //matchup.scheduled = node.Attributes["d"].Value + " " + DateTime.Parse(node.Attributes["t"] == null ? "1:00 AM" : node.Attributes["t"].Value).AddHours(-1).ToShortTimeString().Split(' ')[0];
            matchup.scheduled = node.Key;
            matchup.channel   = node.Value.media.tv;
            matchup.stadium   = node.Value.stadium;

            int  statusInt;
            bool live = int.TryParse(node.Value.qtr, out statusInt);

            matchup.live_update = live ?
                                  matchup.live_update = node.Value.posteam + "'s ball. " + NumberToPosition(node.Value.down) + " and " + node.Value.togo + " on " + node.Value.yl + ". Clock: " + node.Value.clock :
                                                        null;

            if (live)
            {
                _changesMade = true;
            }

            if (matchup.status != null)
            {
                int?oldHome = matchup.home_score;
                int?oldAway = matchup.away_score;

                matchup.home_score = node.Value.home.score["T"];
                matchup.away_score = node.Value.away.score["T"];

                if (matchup.home_score.HasValue && matchup.away_score.HasValue &&
                    (oldAway != matchup.away_score.Value || oldHome != matchup.home_score.Value))
                {
                    _changesMade = true;
                }
            }

            if (matchup.status != null && matchup.status.ToLower().StartsWith("f"))
            {
                string oldWinner = matchup.winner;

                if (matchup.home_score > matchup.away_score)
                {
                    matchup.winner = matchup.home;
                }
                else if (matchup.away_score > matchup.home_score)
                {
                    matchup.winner = matchup.away;
                }
                else
                {
                    matchup.winner = "TIE";
                }

                if (!string.IsNullOrEmpty(matchup.winner) && oldWinner != matchup.winner)
                {
                    _changesMade = true;
                }
            }
        }
示例#2
0
        private void UpdateMatchup(db.NFL_Matchup matchup, System.Xml.XmlNode node)
        {
            matchup.status    = node.Attributes["q"].Value;
            matchup.eid       = Convert.ToInt64(node.Attributes["eid"].Value);
            matchup.scheduled = node.Attributes["d"].Value + " " + DateTime.Parse(node.Attributes["t"] == null ? "1:00 AM" : node.Attributes["t"].Value).AddHours(-1).ToShortTimeString().Split(' ')[0];

            if (matchup.status != "P")
            {
                int?oldHome = matchup.home_score;
                int?oldAway = matchup.away_score;

                matchup.home_score = Convert.ToInt32(node.Attributes["hs"].Value);
                matchup.away_score = Convert.ToInt32(node.Attributes["vs"].Value);

                if (matchup.home_score.HasValue && matchup.away_score.HasValue &&
                    (oldAway != matchup.away_score.Value || oldHome != matchup.home_score.Value))
                {
                    _changesMade = true;
                }
            }

            if (matchup.status == "F" || matchup.status == "FO")
            {
                string oldWinner = matchup.winner;

                if (matchup.home_score > matchup.away_score)
                {
                    matchup.winner = matchup.home;
                }
                else if (matchup.away_score > matchup.home_score)
                {
                    matchup.winner = matchup.away;
                }
                else
                {
                    matchup.winner = "TIE";
                }

                if (!string.IsNullOrEmpty(matchup.winner) && oldWinner != matchup.winner)
                {
                    _changesMade = true;
                }
            }
        }
示例#3
0
        private void UpdateMatchup(db.NFL_Matchup matchup, API.ESPN.Event node)
        {
            matchup.status    = node.status.type.state;
            matchup.eid       = Convert.ToInt64(node.id);
            matchup.scheduled = node.date.ToLocalTime().ToShortDateString();

            List <string> channels = new List <string>();

            node.competitions.ToList().ForEach(c => c.broadcasts.ToList().ForEach(b => b.names.ToList().ForEach(n => channels.Add(n))));
            matchup.channel = string.Join(", ", channels.Distinct().ToArray());

            List <string> venues = new List <string>();

            node.competitions.ToList().ForEach(c => venues.Add(c.venue.fullName));
            matchup.stadium = string.Join(", ", venues.Distinct().ToArray());

            //int statusInt;
            bool live = node.status.type.state != "pre" && node.status.type.state != "post";

            matchup.live_update = live ?
                                  matchup.live_update = $"Clock: { node.status.displayClock }, Quarter: { node.status.period }" :
                                                        null;

            if (live)
            {
                _changesMade = true;
            }

            if (matchup.status != null)
            {
                int?oldHome = matchup.home_score;
                int?oldAway = matchup.away_score;

                int    homeScore;
                string homeScoreString = node.competitions.First().competitors.First(c => c.homeAway == "home").score;
                if (int.TryParse(homeScoreString, out homeScore))
                {
                    matchup.home_score = homeScore;
                }
                int    awayScore;
                string awayScoreString = node.competitions.First().competitors.First(c => c.homeAway == "away").score;
                if (int.TryParse(awayScoreString, out awayScore))
                {
                    matchup.away_score = awayScore;
                }

                if (matchup.home_score.HasValue && matchup.away_score.HasValue &&
                    (oldAway != matchup.away_score.Value || oldHome != matchup.home_score.Value))
                {
                    _changesMade = true;
                }
            }

            if (matchup.status != null && node.status.type.shortDetail.ToLower().StartsWith("final"))
            {
                string oldWinner = matchup.winner;

                matchup.status = node.status.type.shortDetail;

                if (matchup.home_score > matchup.away_score)
                {
                    matchup.winner = matchup.home;
                }
                else if (matchup.away_score > matchup.home_score)
                {
                    matchup.winner = matchup.away;
                }
                else
                {
                    matchup.winner = "TIE";
                }

                if (!string.IsNullOrEmpty(matchup.winner) && oldWinner != matchup.winner)
                {
                    _changesMade = true;
                }
            }
        }