public AthleteSummary ConsolidateWithCache(AthleteMeta athlete) { object entry; if (_cachedAthleteTasks.TryGetValue(athlete.Id.ToString(), out entry)) { //The cache has an entry, so lets see which is newer and has more data AthleteSummary c_summary = entry as AthleteSummary; AthleteSummary n_summary = athlete as AthleteSummary; if (c_summary == null || (n_summary != null && n_summary.UpdatedAt > c_summary.UpdatedAt && n_summary.ResourceState >= c_summary.ResourceState)) { _cachedAthleteTasks[athlete.Id.ToString()] = n_summary; return(n_summary); } return(c_summary); } else { if (athlete.ResourceState > 1) // meta only { _cachedAthleteTasks[athlete.Id.ToString()] = athlete; return((AthleteSummary)athlete); } return(null); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { AthleteMeta athleteMeta; // Load JObject from stream JObject jObject = JObject.Load(reader); if (FieldExists("athlete_type", jObject)) { athleteMeta = new Athlete(); } else if (FieldExists("firstname", jObject)) { athleteMeta = new AthleteSummary(); } else { athleteMeta = new AthleteMeta(); } // Populate the object properties serializer.Populate(jObject.CreateReader(), athleteMeta); return(athleteMeta); }
public AthleteSummary ConsolidateWithCache(AthleteMeta athlete) { return(StravaAthleteService.ConsolidateWithCache(athlete)); }