protected virtual void RenderTagsActionsTabs() { BingSearchResponse bsr = this.SearchResponse as BingSearchResponse; KapiResponse ksr = this.SearchResponse as KapiResponse; if (ksr != null && ksr.Tags != null) { foreach (var t in ksr.Tags) { var vm = new TagViewModel(t); this.Tags.Add(vm); this.FlattendTagsAndActions.Add(vm); foreach (var a in vm.FilteredActions) { this.FlattendTagsAndActions.Add(a); } } this.ResponseItemsTabs.Add(new KeyValuePair <string, object>("Tags", this.FlattendTagsAndActions)); this.ResponseItemsTabs.Add(new KeyValuePair <string, object>("Response", new MyJToken() { JToken = ksr.KapiResponseJson })); this.ResponseItemsTabs.Add(new KeyValuePair <string, object>("Request", new MyJToken() { JToken = ksr.KapiRequestJson })); if (ksr.MiscInfo != null) { foreach (var kvp in ksr.MiscInfo) { this.ResponseItemsTabs.Add(new KeyValuePair <string, object>(kvp.Key, new MyJToken() { JToken = kvp.Value })); } } } }
public async Task <BingSearchResponse> GetBingApiArticles(string searchTerm) { try { string subscriptionKey = _configuration.GetValue <string>("BingSubscriptionKey"); string customConfigId = _configuration.GetValue <string>("BingCustomConfigId"); string bingURI = _configuration.GetValue <string>("BingURI"); string url = bingURI + "q=" + searchTerm + "&customconfig=" + customConfigId; client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey); HttpResponseMessage httpResponseMessage = await Task <HttpResponseMessage> .FromResult(client.GetAsync(url).Result); string responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result; BingSearchResponse response = JsonConvert.DeserializeObject <BingSearchResponse>(responseContent); return(response); } catch (Exception ex) { return(null); } }
protected virtual void RenderDefaultTagsResults() { BingSearchResponse bsr = this.SearchResponse as VSPing.Models.BingSearchResponse; KapiResponse ksr = this.SearchResponse as VSPing.Models.KapiResponse; if (bsr != null) // Signals we got a correct response -> Need to update all of our containers { foreach (var r in bsr.VisualSearchResults) { this.VisualSearchResults.Add(new SearchResultViewModel(r)); } foreach (var r in bsr.ProductSearchResults) { this.ProductSearchResults.Add(new SearchResultViewModel(r)); } foreach (var r in bsr.PagesIncludingSearchResults) { this.PagesIncludingSearchResults.Add(new SearchResultViewModel(r)); } } }
public async Task <List <ArticleDto> > GetBingApiArticles(string searchTerm) { List <ArticleDto> bingArticleList = new List <ArticleDto>(); BingSearchResponse bingResponse = await _articleAccessor.GetBingApiArticles(searchTerm); if (bingResponse?.WebPages != null) { foreach (BingWebPage bingArticle in bingResponse?.WebPages?.Value) { ArticleDto article = new ArticleDto() { Description = bingArticle.Snippet, PublishedAt = bingArticle.DateLastCrawled, Title = bingArticle.Name, Url = bingArticle.DisplayUrl, UrlToImage = bingArticle.OpenGraphImage?.ContentUrl, Likes = 0, }; bingArticleList.Add(article); } } return(bingArticleList); }