示例#1
0
        public List <Triathlete> GetAthletesFromSource(IRaceCriteria criteria)
        {
            List <Triathlete> allAthletes = new List <Triathlete>();

            //create a requestContext for each combination.
            foreach (string raceId in criteria.SelectedRaceIds)
            {
                foreach (int ageId in criteria.SelectedAgeGroupIds)
                {
                    foreach (int genderId in criteria.SelectedGenderIds)
                    {
                        RequestContext    reqContext           = GetRequestContext(raceId, ageId, genderId);
                        List <Triathlete> athletesInReqContext = new List <Triathlete>();
                        if (reqContext == null)
                        {
                            //don't do anything. We have not stored these athletes
                        }
                        else
                        {
                            athletesInReqContext = GetAthletesFromSource(reqContext);
                        }

                        if (athletesInReqContext.Count > 0)
                        {
                            allAthletes.AddRange(athletesInReqContext);
                        }
                    }
                }
            }

            return(allAthletes.OrderBy(t => t.Finish).ToList());
        }
示例#2
0
        /***************************************
         * GetAthletes()
         * Retrieve the athletes with the given request values
         * ****************************************/
        public List <Triathlete> GetAthletes(IRaceCriteria criteria, IDurationFilter filter)
        {
            var allAthletes = GetAthletes(criteria);

            //filter these athletes
            //in the future we may inject the Provider, but for now create it ...
            return(new BasicFilterProvider(allAthletes, filter).GetAthletes());
        }
示例#3
0
        public void PopulateAthletes(IRaceCriteria crit, List <Triathlete> athletes)
        {
            IDatabase cache = Connection.GetDatabase();
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            };

            cache.StringSet(crit.ToString(), JsonConvert.SerializeObject(athletes, settings));
        }
示例#4
0
        public List <Triathlete> GetAthletes(IRaceCriteria crit)
        {
            List <Triathlete> athletes;

            IDatabase cache = Connection.GetDatabase();
            string    key   = cache.StringGet(crit.ToString());

            if (!String.IsNullOrEmpty(key))
            {
                athletes = JsonConvert.DeserializeObject <List <Triathlete> >(key);
            }
            else
            {
                athletes = new List <Triathlete>();
            }

            return(athletes);
        }
示例#5
0
 public BasicRaceCriteriaDiagnostics(IRaceCriteria raceCriteria)
 {
     _RaceCriteria = raceCriteria;
 }
示例#6
0
        /// <summary>
        /// get athletes given the criteria
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public List <Triathlete> GetAthletes(IRaceCriteria criteria, bool useCache = true)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            List <Triathlete> cachedAtheletes = null;

            if (useCache)
            {
                cachedAtheletes = CacheService.Instance.GetAthletes(criteria);
            }
            if (cachedAtheletes != null && cachedAtheletes.Count > 0)
            {
                stopwatch.Stop();

                Trace.TraceInformation(String.Format("GetAthletsFromCache took: {0} ", stopwatch.Elapsed.ToString()));

                return(cachedAtheletes);
            }


            List <Triathlete> allAthletes = new List <Triathlete>();

            //create a requestContext for each combination.
            foreach (string raceId in criteria.SelectedRaceIds)
            {
                foreach (int ageId in criteria.SelectedAgeGroupIds)
                {
                    foreach (int genderId in criteria.SelectedGenderIds)
                    {
                        RequestContext    reqContext           = GetRequestContext(raceId, ageId, genderId);
                        List <Triathlete> athletesInReqContext = new List <Triathlete>();
                        if (reqContext == null ||
                            reqContext.Instruction == RequestInstruction.ForceSource ||
                            useCache == false  //force getting from source

                            )
                        {
                            if (reqContext == null)
                            {
                                reqContext = CreateRequestContext(raceId, ageId, genderId);
                            }
                            else
                            { //we need to remove any athletes that might be there under that context to avoid dupes
                              // DeleteAthletes(reqContext.RequestContextId);
                            }
                            //get from source
                            athletesInReqContext = GetAthletesFromSource(reqContext);
                        }
                        else
                        {
                            athletesInReqContext = GetAthletesFromDb(reqContext);
                        }

                        if (athletesInReqContext.Count > 0)
                        {
                            allAthletes.AddRange(athletesInReqContext);
                        }
                    }
                }
            }

            var athletes = allAthletes.OrderBy(t => t.Finish).ToList();

            stopwatch.Stop();
            Trace.TraceInformation(String.Format("GetAthletes without cache took: {0} ", stopwatch.Elapsed.ToString()));

            CacheService.Instance.PopulateAthletes(criteria, athletes);

            return(athletes);
        }