public static async Task <ItemDictionary> GetItemDictionary(int index) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter"); var streamTask = client.GetStreamAsync(urlLemaf + index); // index max: 99999 ItemDictionary item; try { var word = await JsonSerializer.DeserializeAsync <String>(await streamTask); item = new ItemDictionary { Index = index, Word = word }; } catch { item = new ItemDictionary { Index = -1, Word = "Palavra não encontrada no dicionário" }; } return(item); }
public static async Task <ItemDictionary> ProcessDictionary(string word) { ItemDictionary item = null; int deadTrees = 0; ItemDictionary itemList = wordList.Find(el => el.Word == word); if (itemList == null) { do { item = await Rest.GetItemDictionary(wordList.Count); deadTrees += 1; if (item.Index > -1) { wordList.Add(item); if (item.Word == word) { break; } } else { break; } } while (true); } else { item = itemList; // neste ponto verifica-se a posicao real no webservice, e se for necessario zera a lista da memoria e comeca a contar novamente para otimizacao (arores mortas) } item.tree = deadTrees; return(item); }