public async Task <City> GetCity(int CityId, string apiKey, Expression <Func <City, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <City> cache; if (expression != null) { cache = (await _cacheEngine.FindAsync(expression)).Where(x => x._id == CityId); } else { cache = await _cacheEngine.FindAsync(x => x._id == CityId); } if (cache.Any()) { return(cache.FirstOrDefault()); } } var result = await this.service.Get <City>($"/city/id={CityId}&key={apiKey}"); if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result); } return(result); }
public async Task <TradePrice> GetTradePrice(Resources resource, string apiKey, Expression <Func <TradePrice, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <TradePrice> cache; if (expression != null) { cache = (await _cacheEngine.FindAsync(expression)).Where(x => x.resource == resource.ToString()); } else { cache = await _cacheEngine.FindAsync(x => x.resource == resource.ToString()); } if (cache.Any()) { return(cache.OrderByDescending(x => x.CreatedDate).FirstOrDefault()); } } var result = await this.service.Get <TradePrice>($"/tradeprice/resource={resource.ToString("g")}&key={apiKey}"); if (_cacheEngine != null && result != null) { await _cacheEngine.Build(result); } return(result); }
public async Task <WarResponse> GetWar(int id, string apiKey, Expression <Func <War, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <War> cache; if (expression != null) { cache = (await _cacheEngine.FindAsync(expression)).Where(x => x._id == id); } else { cache = await _cacheEngine.FindAsync(x => x._id == id); } if (cache.Any()) { return new WarResponse() { success = true, war = cache.ToList() } } ; } var result = await this.service.Get <WarResponse>($"/war/{id}&key={apiKey}"); if (result.success) { result.war.First().war_id = id; } if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result.war); } return(result); } }
public async Task <Alliance> GetAlliance(int id, string apikey, Expression <Func <Alliance, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <Alliance> cache; if (expression != null) { cache = (await _cacheEngine.FindAsync(expression)).Where(x => x._id == id); } else { cache = (await _cacheEngine.FindAsync(x => x._id == id)); } if (cache.Any()) { return(cache.FirstOrDefault()); } } var result = await this.service.Get <Alliance>($"/alliance/id={id}&key={apikey}"); if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result); } return(result); }
public async Task <WarsResponse> GetWars(int?limit, string apiKey, Expression <Func <Wars, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <Wars> cache; if (expression != null) { cache = await _cacheEngine.FindAsync(expression); } else { cache = await _cacheEngine.GetAllAsync(); } if (limit.HasValue) { cache = cache.Take(limit.Value); } if (cache.Any()) { return new WarsResponse() { success = true, wars = cache.ToList() } } ; } Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("key", apiKey); if (limit != null && limit.HasValue) { parameters.Add("limit", limit.Value.ToString()); } var result = await this.service.Get <WarsResponse>($"/wars/", parameters); if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result.wars); } if (expression != null) { var compExpr = expression.Compile(); result.wars = result.wars.Where(x => compExpr(x)).ToList(); } return(result); } }
public async Task <ApplicantResponse> GetApplicant(int AllianceId, string apiKey, Expression <Func <Applicant, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <Applicant> cache; if (expression != null) { cache = (await _cacheEngine.FindAsync(expression)).Where(x => x.AllianceId == AllianceId); } else { cache = await _cacheEngine.GetAllAsync(); } if (cache.Any()) { return new ApplicantResponse() { success = true, nations = cache.ToList() } } ; } var result = await this.service.Get <ApplicantResponse>($"/applicants/{AllianceId}&key={apiKey}"); if (result.success) { foreach (var nation in result.nations) { nation.AllianceId = AllianceId; } } if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result.nations); } if (expression != null) { var compExpr = expression.Compile(); result.nations = result.nations.Where(x => compExpr(x)).ToList(); } return(result); } }
public async Task <AllCityResponse> GetAllCities(string apiKey, Expression <Func <AllCity, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <AllCity> cache; if (expression != null) { cache = await _cacheEngine.FindAsync(expression); } else { cache = await _cacheEngine.GetAllAsync(); } if (cache.Any()) { return new AllCityResponse() { success = true, all_cities = cache.ToList() } } ; } var result = await this.service.Get <AllCityResponse>($"/all-cities/key={apiKey}"); if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result.all_cities); } if (expression != null) { var compExpr = expression.Compile(); result.all_cities = result.all_cities.Where(x => compExpr(x)).ToList(); } return(result); } }
public async Task <TradeHistoryResponse> GetTradeHistory(string apiKey, Resources[] resources, int records = 10000, Expression <Func <TradeHistory, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <TradeHistory> cache; if (expression != null) { cache = (await _cacheEngine.FindAsync(expression)).Where(x => resources.Any(y => y.ToString() == x.resource)).Take(records); } else { cache = (await _cacheEngine.GetAllAsync()).Where(x => resources.Any(y => y.ToString() == x.resource)).Take(records); } if (cache.Any()) { return new TradeHistoryResponse() { success = true, trades = cache.ToList() } } ; } var result = await this.service.Get <TradeHistoryResponse>($"/trade-history/key={apiKey}&resources={string.Join(",", resources.Select(x => x.ToString("g")))}&records={records}"); if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result.trades); } if (expression != null) { var compExpr = expression.Compile(); result.trades = result.trades.Where(x => compExpr(x)).ToList(); } return(result); } }
public async Task <NationsResponse> GetNations(string apiKey, bool?vm = null, int?allianceId = null, int?min_score = null, int?max_score = null, Expression <Func <Nations, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <Nations> cache; if (expression != null) { cache = (await _cacheEngine.FindAsync(expression)); } else { cache = (await _cacheEngine.GetAllAsync()); } if (cache.Any()) { if (vm != null && vm.HasValue) { cache = cache.Where(x => (x.vacmode == "0") == vm.Value); } if (allianceId != null && allianceId.HasValue) { cache = cache.Where(x => x.allianceid == allianceId.Value); } if (min_score != null && min_score.HasValue) { cache = cache.Where(x => x.score >= min_score.Value); } if (max_score != null && max_score.HasValue) { cache = cache.Where(x => x.score <= max_score.Value); } return(new NationsResponse() { success = true, nations = cache.ToList() }); } } Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("key", apiKey); if (vm != null && vm.HasValue) { parameters.Add("vm", vm.Value.ToString().ToLower()); } if (allianceId != null && allianceId.HasValue) { parameters.Add("alliance_id", allianceId.Value.ToString()); } if (min_score != null && min_score.HasValue) { parameters.Add("min_score", min_score.Value.ToString()); } if (max_score != null && max_score.HasValue) { parameters.Add("max_score", max_score.Value.ToString()); } var result = await this.service.Get <NationsResponse>($"/nations/", parameters); if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result.nations); } if (expression != null) { var compExpr = expression.Compile(); result.nations = result.nations.Where(x => compExpr(x)).ToList(); } return(result); }
public async Task <WarAttackResponse> GetWarAttack(string key, int warId = 0, int minWarAttackId = 0, int maxWarAttackId = 0, Expression <Func <WarAttack, bool> > expression = null, bool UseCache = true) { if (_cacheEngine != null && UseCache) { IEnumerable <WarAttack> cache; if (expression != null) { cache = (await _cacheEngine.FindAsync(expression)); } else { cache = (await _cacheEngine.GetAllAsync()); } if (warId > 0) { cache = cache.Where(x => int.Parse(x.war_id) == warId); } else { if (minWarAttackId > 0) { cache = cache.Where(x => minWarAttackId >= int.Parse(x.war_attack_id)); } if (maxWarAttackId > 0) { cache = cache.Where(x => maxWarAttackId <= int.Parse(x.war_attack_id)); } } if (cache.Any()) { return new WarAttackResponse() { success = true, war_attacks = cache.ToList() } } ; } string path = $"/war-attacks/key={key}"; if (warId > 0) { path += $"&war_id={warId}"; } else { if (minWarAttackId > 0) { path += $"&min_war_attack_id={minWarAttackId}"; } if (maxWarAttackId > 0) { path += $"&max_war_attack_id={maxWarAttackId}"; } } var result = await this.service.Get <WarAttackResponse>(path); if (_cacheEngine != null && result.success) { await _cacheEngine.Build(result.war_attacks); } if (expression != null) { var compExpr = expression.Compile(); result.war_attacks = result.war_attacks.Where(x => compExpr(x)).ToList(); } return(result); } }