public async Task <ObservableCollection <Beer> > GetBeersAsync(string ID) { byte KeyNumber = 0; byte Condicion = 0; try { if (Connectivity.NetworkAccess != NetworkAccess.Internet && !Barrel.Current.IsExpired(key: Config.ApiUrl + Config.ApiKey)) { await Task.Yield(); UserDialogs.Instance.Toast("Please check your internet connection", TimeSpan.FromSeconds(5)); do { string KeyString; KeyString = KeyNumber.ToString(); var result = Barrel.Current.Get <Data>(key: KeyString); if (result != null) { GetData.Add(result.Beer); } else { Condicion++; } KeyNumber++; } while (Condicion != 1); return(GetData); } var client = new HttpClient(); var json = await client.GetStringAsync(Config.ApiUrl + ID + Config.ApiKey); var Beers = JsonConvert.DeserializeObject <Data>(json); do { string KeyString; KeyString = KeyNumber.ToString(); var data = Barrel.Current.Get <Data>(key: KeyString); if (data == null) { Barrel.Current.Add(key: KeyString, data: Beers, expireIn: TimeSpan.FromDays(1)); Condicion++; } KeyNumber++; } while (Condicion != 1); return(null); } catch (Exception ex) { Debug.WriteLine($"API EXCEPTION {ex}"); } return(null); }
public void Process() { FullRequest = StringBuilder.ToString(); var lines = new List <string>(Regex.Split(FullRequest, "\r\n")); if (lines != null && lines.Count > 2) { var requestLine = lines[0].Split(' '); if (requestLine.Length == 3) { Method = requestLine[0]; var requestedPage = requestLine[1].Split('?'); if (requestedPage.Length == 2) { var getData = requestedPage[1].Split('&'); foreach (var kvp in getData) { var _kvp = kvp.Split('='); if (_kvp.Length == 2 && !GetData.ContainsKey(_kvp[0])) { GetData.Add(_kvp[0], _kvp[1]); } } } RequestedPage = requestedPage[0]; } int contentIndex = lines.IndexOf(string.Empty) + 1; if (contentIndex > 0 && contentIndex < lines.Count) { for (int i = contentIndex; i < lines.Count; i++) { var line = lines[i].Split('='); if (line.Length == 2 && !PostData.ContainsKey(line[0])) { PostData.Add(line[0], line[1]); } } } } }
public async Task <ObservableCollection <Beer> > ShowDataAsync() { byte Condicion = 0; byte KeyNumber = 0; do { string KeyString; KeyString = KeyNumber.ToString(); var result = Barrel.Current.Get <Data>(key: KeyString); if (result != null) { GetData.Add(result.Beer); } else { Condicion++; } KeyNumber++; } while (Condicion != 1); return(GetData); }