Пример #1
0
        private async Task <JObject> ExecuteAutocompleteServiceQueryAsync(List <string> endpoints, Func <string, string> query, CancellationToken cancellationToken)
        {
            for (int i = 0; i < endpoints.Count; ++i)
            {
                string endpoint = endpoints[0];

                try
                {
                    string location = query(endpoint);
                    return(await _webRequestFactory.GetJsonAsync(location, cancellationToken).ConfigureAwait(false) as JObject);
                }
                catch (Exception)
                {
                    if (endpoints.Count > 1)
                    {
                        endpoints.RemoveAt(0);
                        endpoints.Add(endpoint);
                    }

                    //TODO: Possibly log the failure to get the document
                }
            }

            return(null);
        }
        public static async Task <T> GetDeserializedJsonAsync <T>(this IWebRequestFactory factory, string endpoint, CancellationToken cancellationToken)
        {
            JToken token = await factory.GetJsonAsync(endpoint, cancellationToken).ConfigureAwait(false);

            if (token == null)
            {
                return(default(T));
            }

            return(token.ToObject <T>());
        }