private IList <SelectStore> FindStores(int start, int max) // max -> -1 = ALL (no max), 0 = one page (default size) { List <FindStoresResponse.StoreResult.Store> ret = new List <FindStoresResponse.StoreResult.Store>(); while (true) { // get one page (from start) FindStoresResponse.StoreResult res = FindStores(start); // save (grand) total found (not thread safe) TotalStores = res.Total; if (res.Data.Count() == 0) // strange error? { break; } // add them all ret.AddRange(res.Data); if (max == MaxOnePage) { break; } if (max != MaxNone) // a 'real' max (> 0) { if (ret.Count() >= max) { // remove if too many while (ret.Count() > max) { ret.Remove(ret.Last()); } break; } } if (ret.Count() == res.Total) // no more available { break; } // next: start += res.Data.Count(); } return(ret.Select(s => new SelectStore() { ID = s.ID, Name = s.Name, Address = s.Address, PostalCode = s.PostalCode, City = s.City, Country = s.Country, Latitude = s.Location.Latitude, Longitude = s.Location.Longitude, Created = s.Created.AsDateTime(true).Value }).ToList()); }
private FindStoresResponse.StoreResult FindStores(int start) { const string FunctionAdmin = "findPlaces"; // Admin const string Function = "place"; const string Start = "start"; Parameters parameters = new Parameters() { { Start, start } }; HttpWebRequest webRequest = GetWebRequest("GET", isAdminConnection ? FunctionAdmin : Function, parameters); FindStoresResponse response = GetJSONresponse <FindStoresResponse>(webRequest); if (response == null) { throw new Exception("No response."); } // check the result codes: response.Check(); FindStoresResponse.StoreResult ret = response.Result ?? new FindStoresResponse.StoreResult() { Total = 0 }; if (ret.Data == null) { ret.Data = new FindStoresResponse.StoreResult.Store[] { } } ; return(ret); }