コード例 #1
0
        public IResourceMatch GetMatch(string resourcePath)
        {
            foreach (ResourceMatchElement element in this)
            {
                var match = element.GetMatch(resourcePath);
                if (match.IsMatch())
                {
                    return(match);
                }
            }

            return(ResourceMatches.False(resourcePath));
        }
コード例 #2
0
        public bool SyncMatchesTierOne()
        {
            DALMatches      dalMatches      = new DALMatches(connectionString);                                     // Object to comunicate with Database.
            ResourceMatches resourceMatches = new ResourceMatches(apiToken);                                        // Object to comunicate with API football-data.org.

            foreach (Competition competition in TierOneCompetitions())                                              // Foreach tier_one competition.
            {
                List <Match> lstInsertMatches = new List <Match>();                                                 // Temporary list to hold insertable matches.
                List <Match> lstUpdateMatches = new List <Match>();                                                 // Temporary list to hold updatable  matches.

                List <Match> lstApiMatches = resourceMatches.GetByCompetition(competition.Id.ToString());           // Get a list of matches by competition from the Api.

                foreach (Match apiMatch in lstApiMatches)                                                           // Foreach match in lstApiMatches.
                {
                    if (apiMatch.HomeTeam.Id == 0 || apiMatch.AwayTeam.Id == 0)                                     // 0 == null. Do not insert or update.
                    {
                        continue;
                    }

                    Match dbMatch = dalMatches.GetById(apiMatch.Id.ToString());                                     // Tries to get the same match from db.

                    if (dbMatch is null)                                                                            // If no match then add match to insertable matches list.
                    {
                        lstInsertMatches.Add(apiMatch);
                    }
                    else                                                                                            // Otherwise
                    {
                        DateTime?apiLastUpdated = NormalizeApiDateTime(apiMatch.LastUpdated);                       // First normalize the datetime that came from the api to our standard.

                        if (dbMatch.LastUpdated != apiLastUpdated.ToString())                                       // if Api Last Update is diferent from the corresponding db value.
                        {
                            lstUpdateMatches.Add(apiMatch);                                                         // Add match to updatable matches list.
                        }
                    }
                }

                if (lstInsertMatches.Count != 0)
                {
                    dalMatches.Insert(lstInsertMatches);
                }
                if (lstUpdateMatches.Count != 0)
                {
                    dalMatches.Update(lstUpdateMatches);
                }
            }

            return(true);
        }
コード例 #3
0
        private IResourceMatch GetMatch(string resourceUrl)
        {
            if (Include.Count == 0)
            {
                return(Exclude.GetMatch(resourceUrl).Inverse());
            }

            var includeMatch = Include.GetMatch(resourceUrl);
            var excludeMatch = Exclude.GetMatch(resourceUrl);

            if (includeMatch.IsMatch() && !excludeMatch.IsMatch())
            {
                return(includeMatch);
            }

            return(ResourceMatches.False(resourceUrl));
        }