public virtual ImageInsightResponse GetImageInsights( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { return(Task.Run(async() => await GetImageInsightsAsync(query, height, width, count, offset, languageCode, aspect, color, freshness, imageContent, imageType, license, size, safeSearch, modulesRequested, cab, cal, car, cat, ct, cc, id, imgUrl, insightsToken)).Result); }
public virtual async Task <ImageInsightResponse> GetImageInsightsAsync( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { var url = GetImageInsightUrl(query, height, width, count, offset, languageCode, aspect, color, freshness, imageContent, imageType, license, size, safeSearch, modulesRequested, cab, cal, car, cat, ct, cc, id, imgUrl, insightsToken); var response = await RepositoryClient.SendPostMultiPartAsync(ApiKeys.BingSearch, url, "{}"); return(JsonConvert.DeserializeObject <ImageInsightResponse>(response)); }
public virtual ImageInsightResponse GetImageInsights( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { try { var result = ImageSearchRepository.GetImageInsights(query, height, width, count, offset, languageCode, aspect, color, freshness, imageContent, imageType, license, size, safeSearch, modulesRequested, cab, cal, car, cat, ct, cc, id, imgUrl, insightsToken); return(result); } catch (Exception ex) { Logger.Error("ImageSearchService.GetImageInsights failed", this, ex); } return(null); }
public virtual ImageInsightResponse GetImageInsights( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { return(PolicyService.ExecuteRetryAndCapture400Errors( "ImageSearchService.GetImageInsights", ApiKeys.BingSearchRetryInSeconds, () => { var result = ImageSearchRepository.GetImageInsights(query, height, width, count, offset, languageCode, aspect, color, freshness, imageContent, imageType, license, size, safeSearch, modulesRequested, cab, cal, car, cat, ct, cc, id, imgUrl, insightsToken); return result; }, null)); }
public WebSearchResponse WebSearch(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { return(Task.Run(async() => await WebSearchAsync(text, countOffset, languageCode, safeSearch)).Result); }
public SearchRequest() { this.safeSearchField = SafeSearchOptions.Moderate; this.flagsField = SearchFlags.None; }
public virtual ImageSearchResponse GetImages(string query, int count = 10, int offset = 0, string languageCode = "en-us", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { return(Task.Run(async() => await GetImagesAsync(query, count, offset, languageCode, safeSearch)).Result); }
public virtual async Task <WebSearchResponse> WebSearchAsync(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { var qs = GetWebSearchQuerystring(countOffset, languageCode, safeSearch); var response = await RepositoryClient.SendGetAsync(ApiKeys.BingSearch, $"{ApiKeys.BingSearchEndpoint}{webSearchUrl}?q={text}{qs}"); return(JsonConvert.DeserializeObject <WebSearchResponse>(response)); }
public virtual NewsSearchResponse NewsSearch(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { return(PolicyService.ExecuteRetryAndCapture400Errors( "NewsSearchService.NewsSearch", ApiKeys.BingSearchRetryInSeconds, () => { var result = NewsSearchRepository.NewsSearch(text, countOffset, languageCode, safeSearch); return result; }, null)); }
public virtual ImageSearchResponse GetImages(string query, int count = 10, int offset = 0, string languageCode = "en-us", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { return(PolicyService.ExecuteRetryAndCapture400Errors( "ImageSearchService.GetImages", ApiKeys.BingSearchRetryInSeconds, () => { var result = ImageSearchRepository.GetImages(query, count, offset, languageCode, safeSearch); return result; }, null)); }
protected virtual string GetWebSearchQuerystring(int countOffset, string languageCode, SafeSearchOptions safeSearch) { StringBuilder sb = new StringBuilder(); if (countOffset > 0) { sb.Append($"?countoffset={countOffset}"); } if (!string.IsNullOrEmpty(languageCode)) { var concat = (sb.Length > 0) ? "?" : "&"; sb.Append($"{concat}mkt={languageCode}"); } if (safeSearch != SafeSearchOptions.Off) { var concat = (sb.Length > 0) ? "?" : "&"; sb.Append($"{concat}safeSearch={Enum.GetName(typeof(SafeSearchOptions), safeSearch)}"); } return(sb.ToString()); }
public virtual VideoSearchResponse VideoSearch(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { var qs = GetVideoSearchQuerystring(countOffset, languageCode, safeSearch); var response = RepositoryClient.SendGet(ApiKeys.BingSearch, $"{ApiKeys.BingSearchEndpoint}{videoUrl}?q={text}{qs}"); return(JsonConvert.DeserializeObject <VideoSearchResponse>(response)); }
public virtual async Task <ImageSearchResponse> GetImagesAsync(string query, int count = 10, int offset = 0, string languageCode = "en-us", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { string searchUrl = $"{imageSearchUrl}?q={query}&count={count}&offset={offset}&mkt={languageCode}&safeSearch={Enum.GetName(typeof(SafeSearchOptions), safeSearch)}"; var response = await RepositoryClient.SendGetAsync(ApiKeys.BingSearch, searchUrl); return(JsonConvert.DeserializeObject <ImageSearchResponse>(response)); }
public virtual WebSearchResponse WebSearch(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { try { var result = Task.Run(async() => await WebSearchRepository.WebSearchAsync(text, countOffset, languageCode, safeSearch)).Result; return(result); } catch (Exception ex) { Logger.Error("WebSearchService.WebSearch failed", this, ex); } return(null); }
public VideoSearchResponse VideoSearch(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { try { var result = VideoSearchRepository.VideoSearch(text, countOffset, languageCode, safeSearch); return(result); } catch (Exception ex) { Logger.Error("VideoSearchService.VideoSearch failed", this, ex); } return(null); }
public virtual NewsSearchResponse NewsSearch(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { try { var result = NewsSearchRepository.NewsSearch(text, countOffset, languageCode, safeSearch); return(result); } catch (Exception ex) { Logger.Error("AutoSuggestService.CategorySearch failed", this, ex); } return(null); }
public virtual ImageSearchResponse GetImages(string query, int count = 10, int offset = 0, string languageCode = "en-us", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { try { var result = Task.Run(async() => await ImageSearchRepository.GetImagesAsync(query, count, offset, languageCode, safeSearch)).Result; return(result); } catch (Exception ex) { Logger.Error("ImageSearchService.GetImages failed", this, ex); } return(null); }
protected virtual string GetImageInsightUrl( string query = "", int height = 0, int width = 0, int count = 0, int offset = 0, string languageCode = "", AspectOptions aspect = AspectOptions.All, ColorOptions color = ColorOptions.All, FreshnessOptions freshness = FreshnessOptions.All, ImageContentOptions imageContent = ImageContentOptions.All, ImageTypeOptions imageType = ImageTypeOptions.All, LicenseOptions license = LicenseOptions.All, SizeOptions size = SizeOptions.All, SafeSearchOptions safeSearch = SafeSearchOptions.Off, List <ModulesRequestedOptions> modulesRequested = null, float cab = 0f, float cal = 0f, float car = 0f, float cat = 0f, int ct = 0, string cc = "", string id = "", string imgUrl = "", string insightsToken = "") { StringBuilder sb = new StringBuilder(); sb.Append($"{imageSearchUrl}?q={query}"); if (height > 0) { sb.Append($"&height={height}"); } if (width > 0) { sb.Append($"&width={width}"); } if (count > 0) { sb.Append($"&count={count}"); } if (offset > 0) { sb.Append($"&offset={offset}"); } if (!string.IsNullOrEmpty(languageCode)) { sb.Append($"&mkt={languageCode}"); } var aspectName = Enum.GetName(typeof(AspectOptions), aspect); if (aspectName != null && !aspectName.Equals("All")) { sb.Append($"&aspect={aspectName}"); } var colorName = Enum.GetName(typeof(ColorOptions), color); if (colorName != null && !colorName.Equals("All")) { sb.Append($"&color={colorName}"); } var freshnessName = Enum.GetName(typeof(FreshnessOptions), freshness); if (freshnessName != null && !freshnessName.Equals("All")) { sb.Append($"&freshness={freshnessName}"); } var imageContentName = Enum.GetName(typeof(ImageContentOptions), imageContent); if (imageContentName != null && !imageContentName.Equals("All")) { sb.Append($"&imageContent={imageContentName}"); } var imageTypeName = Enum.GetName(typeof(ImageTypeOptions), imageType); if (imageTypeName != null && !imageTypeName.Equals("All")) { sb.Append($"&imageType={imageTypeName}"); } var licenseName = Enum.GetName(typeof(LicenseOptions), license); if (licenseName != null && !licenseName.Equals("All")) { sb.Append($"&license={licenseName}"); } var sizeName = Enum.GetName(typeof(SizeOptions), size); if (sizeName != null && !sizeName.Equals("All")) { sb.Append($"&size={sizeName}"); } var safeSearchName = Enum.GetName(typeof(SafeSearchOptions), safeSearch); if (safeSearchName != null && !safeSearchName.Equals("All")) { sb.Append($"&safeSearch={safeSearchName}"); } StringBuilder mod = new StringBuilder(); if (modulesRequested != null) { foreach (var m in modulesRequested) { if (mod.Length > 0) { mod.Append(","); } mod.Append(Enum.GetName(typeof(ModulesRequestedOptions), m)); } sb.Append($"&modulesRequested={mod}"); } if (cab > 0f) { sb.Append($"&cab={cab}"); } if (cal > 0f) { sb.Append($"&cal={cal}"); } if (car > 0f) { sb.Append($"&car={car}"); } if (cat > 0f) { sb.Append($"&cat={cat}"); } if (ct > 0) { sb.Append($"&ct={ct}"); } if (!string.IsNullOrEmpty(cc)) { sb.Append($"&cc={cc}"); } if (!string.IsNullOrEmpty(id)) { sb.Append($"&id={id}"); } if (!string.IsNullOrEmpty(imgUrl)) { sb.Append($"&imgUrl={HttpUtility.UrlEncode(imgUrl)}"); } if (!string.IsNullOrEmpty(insightsToken)) { sb.Append($"&insightsToken={insightsToken}"); } return(sb.ToString()); }
public async Task <WebSearchResponse> WebSearchAsync(string text, int countOffset = 0, string languageCode = "", SafeSearchOptions safeSearch = SafeSearchOptions.Off) { StringBuilder sb = new StringBuilder(); if (countOffset > 0) { sb.Append($"?countoffset={countOffset}"); } if (!string.IsNullOrEmpty(languageCode)) { var concat = (sb.Length > 0) ? "?" : "&"; sb.Append($"{concat}mkt={languageCode}"); } if (safeSearch != SafeSearchOptions.Off) { var concat = (sb.Length > 0) ? "?" : "&"; sb.Append($"{concat}safeSearch={Enum.GetName(typeof(SafeSearchOptions), safeSearch)}"); } var response = await this.SendGetAsync($"{webSearchUrl}?q={text}{sb}"); return(JsonConvert.DeserializeObject <WebSearchResponse>(response)); }