| | 1 | | // <auto-generated> |
| | 2 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 3 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 4 | | // regenerated. |
| | 5 | | // </auto-generated> |
| | 6 | |
|
| | 7 | | namespace Microsoft.Azure.CognitiveServices.Search.ImageSearch |
| | 8 | | { |
| | 9 | | using Microsoft.Rest; |
| | 10 | | using Models; |
| | 11 | | using Newtonsoft.Json; |
| | 12 | | using System.Collections; |
| | 13 | | using System.Collections.Generic; |
| | 14 | | using System.IO; |
| | 15 | | using System.Linq; |
| | 16 | | using System.Net; |
| | 17 | | using System.Net.Http; |
| | 18 | | using System.Threading; |
| | 19 | | using System.Threading.Tasks; |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// ImagesOperations operations. |
| | 23 | | /// </summary> |
| | 24 | | public partial class ImagesOperations : IServiceOperations<ImageSearchClient>, IImagesOperations |
| | 25 | | { |
| | 26 | | /// <summary> |
| | 27 | | /// Initializes a new instance of the ImagesOperations class. |
| | 28 | | /// </summary> |
| | 29 | | /// <param name='client'> |
| | 30 | | /// Reference to the service client. |
| | 31 | | /// </param> |
| | 32 | | /// <exception cref="System.ArgumentNullException"> |
| | 33 | | /// Thrown when a required parameter is null |
| | 34 | | /// </exception> |
| 6 | 35 | | public ImagesOperations(ImageSearchClient client) |
| | 36 | | { |
| 6 | 37 | | if (client == null) |
| | 38 | | { |
| 0 | 39 | | throw new System.ArgumentNullException("client"); |
| | 40 | | } |
| 6 | 41 | | Client = client; |
| 6 | 42 | | } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Gets a reference to the ImageSearchClient |
| | 46 | | /// </summary> |
| 48 | 47 | | public ImageSearchClient Client { get; private set; } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// The Image Search API lets you send a search query to Bing and get back a |
| | 51 | | /// list of relevant images. This section provides technical details about the |
| | 52 | | /// query parameters and headers that you use to request images and the JSON |
| | 53 | | /// response objects that contain them. For examples that show how to make |
| | 54 | | /// requests, see [Searching the Web for |
| | 55 | | /// Images](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/search-the-web). |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='query'> |
| | 58 | | /// The user's search query term. The term cannot be empty. The term may |
| | 59 | | /// contain [Bing Advanced |
| | 60 | | /// Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, |
| | 61 | | /// to limit images to a specific domain, use the |
| | 62 | | /// [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. To help |
| | 63 | | /// improve relevance of an insights query (see |
| | 64 | | /// [insightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#ins |
| | 65 | | /// you should always include the user's query term. Use this parameter only |
| | 66 | | /// with the Image Search API.Do not specify this parameter when calling the |
| | 67 | | /// Trending Images API. |
| | 68 | | /// </param> |
| | 69 | | /// <param name='acceptLanguage'> |
| | 70 | | /// A comma-delimited list of one or more languages to use for user interface |
| | 71 | | /// strings. The list is in decreasing order of preference. For additional |
| | 72 | | /// information, including expected format, see |
| | 73 | | /// [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This |
| | 74 | | /// header and the |
| | 75 | | /// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) |
| | 76 | | /// query parameter are mutually exclusive; do not specify both. If you set |
| | 77 | | /// this header, you must also specify the |
| | 78 | | /// [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) |
| | 79 | | /// query parameter. To determine the market to return results for, Bing uses |
| | 80 | | /// the first supported language it finds from the list and combines it with |
| | 81 | | /// the cc parameter value. If the list does not include a supported language, |
| | 82 | | /// Bing finds the closest language and market that supports the request or it |
| | 83 | | /// uses an aggregated or default market for the results. To determine the |
| | 84 | | /// market that Bing used, see the BingAPIs-Market header. Use this header and |
| | 85 | | /// the cc query parameter only if you specify multiple languages. Otherwise, |
| | 86 | | /// use the |
| | 87 | | /// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) |
| | 88 | | /// and |
| | 89 | | /// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) |
| | 90 | | /// query parameters. A user interface string is a string that's used as a |
| | 91 | | /// label in a user interface. There are few user interface strings in the JSON |
| | 92 | | /// response objects. Any links to Bing.com properties in the response objects |
| | 93 | | /// apply the specified language. |
| | 94 | | /// </param> |
| | 95 | | /// <param name='userAgent'> |
| | 96 | | /// The user agent originating the request. Bing uses the user agent to provide |
| | 97 | | /// mobile users with an optimized experience. Although optional, you are |
| | 98 | | /// encouraged to always specify this header. The user-agent should be the same |
| | 99 | | /// string that any commonly used browser sends. For information about user |
| | 100 | | /// agents, see [RFC |
| | 101 | | /// 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The |
| | 102 | | /// following are examples of user-agent strings. Windows Phone: Mozilla/5.0 |
| | 103 | | /// (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; |
| | 104 | | /// Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; |
| | 105 | | /// en - us; SCH - I500 Build / GINGERBREAD) AppleWebKit / 533.1 (KHTML; like |
| | 106 | | /// Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 5.0 (iPhone; |
| | 107 | | /// CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) |
| | 108 | | /// Mobile / 10B142 iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 |
| | 109 | | /// (Windows NT 6.3; WOW64; Trident / 7.0; Touch; rv:11.0) like Gecko. iPad: |
| | 110 | | /// Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 |
| | 111 | | /// (KHTML, like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 |
| | 112 | | /// </param> |
| | 113 | | /// <param name='clientId'> |
| | 114 | | /// Bing uses this header to provide users with consistent behavior across Bing |
| | 115 | | /// API calls. Bing often flights new features and improvements, and it uses |
| | 116 | | /// the client ID as a key for assigning traffic on different flights. If you |
| | 117 | | /// do not use the same client ID for a user across multiple requests, then |
| | 118 | | /// Bing may assign the user to multiple conflicting flights. Being assigned to |
| | 119 | | /// multiple conflicting flights can lead to an inconsistent user experience. |
| | 120 | | /// For example, if the second request has a different flight assignment than |
| | 121 | | /// the first, the experience may be unexpected. Also, Bing can use the client |
| | 122 | | /// ID to tailor web results to that client ID’s search history, providing a |
| | 123 | | /// richer experience for the user. Bing also uses this header to help improve |
| | 124 | | /// result rankings by analyzing the activity generated by a client ID. The |
| | 125 | | /// relevance improvements help with better quality of results delivered by |
| | 126 | | /// Bing APIs and in turn enables higher click-through rates for the API |
| | 127 | | /// consumer. IMPORTANT: Although optional, you should consider this header |
| | 128 | | /// required. Persisting the client ID across multiple requests for the same |
| | 129 | | /// end user and device combination enables 1) the API consumer to receive a |
| | 130 | | /// consistent user experience, and 2) higher click-through rates via better |
| | 131 | | /// quality of results from the Bing APIs. Each user that uses your application |
| | 132 | | /// on the device must have a unique, Bing generated client ID. If you do not |
| | 133 | | /// include this header in the request, Bing generates an ID and returns it in |
| | 134 | | /// the X-MSEdge-ClientID response header. The only time that you should NOT |
| | 135 | | /// include this header in a request is the first time the user uses your app |
| | 136 | | /// on that device. Use the client ID for each Bing API request that your app |
| | 137 | | /// makes for this user on the device. Persist the client ID. To persist the ID |
| | 138 | | /// in a browser app, use a persistent HTTP cookie to ensure the ID is used |
| | 139 | | /// across all sessions. Do not use a session cookie. For other apps such as |
| | 140 | | /// mobile apps, use the device's persistent storage to persist the ID. The |
| | 141 | | /// next time the user uses your app on that device, get the client ID that you |
| | 142 | | /// persisted. Bing responses may or may not include this header. If the |
| | 143 | | /// response includes this header, capture the client ID and use it for all |
| | 144 | | /// subsequent Bing requests for the user on that device. If you include the |
| | 145 | | /// X-MSEdge-ClientID, you must not include cookies in the request. |
| | 146 | | /// </param> |
| | 147 | | /// <param name='clientIp'> |
| | 148 | | /// The IPv4 or IPv6 address of the client device. The IP address is used to |
| | 149 | | /// discover the user's location. Bing uses the location information to |
| | 150 | | /// determine safe search behavior. Although optional, you are encouraged to |
| | 151 | | /// always specify this header and the X-Search-Location header. Do not |
| | 152 | | /// obfuscate the address (for example, by changing the last octet to 0). |
| | 153 | | /// Obfuscating the address results in the location not being anywhere near the |
| | 154 | | /// device's actual location, which may result in Bing serving erroneous |
| | 155 | | /// results. |
| | 156 | | /// </param> |
| | 157 | | /// <param name='location'> |
| | 158 | | /// A semicolon-delimited list of key/value pairs that describe the client's |
| | 159 | | /// geographical location. Bing uses the location information to determine safe |
| | 160 | | /// search behavior and to return relevant local content. Specify the key/value |
| | 161 | | /// pair as <key>:<value>. The following are the keys that you use |
| | 162 | | /// to specify the user's location. lat (required): The latitude of the |
| | 163 | | /// client's location, in degrees. The latitude must be greater than or equal |
| | 164 | | /// to -90.0 and less than or equal to +90.0. Negative values indicate southern |
| | 165 | | /// latitudes and positive values indicate northern latitudes. long (required): |
| | 166 | | /// The longitude of the client's location, in degrees. The longitude must be |
| | 167 | | /// greater than or equal to -180.0 and less than or equal to +180.0. Negative |
| | 168 | | /// values indicate western longitudes and positive values indicate eastern |
| | 169 | | /// longitudes. re (required): The radius, in meters, which specifies the |
| | 170 | | /// horizontal accuracy of the coordinates. Pass the value returned by the |
| | 171 | | /// device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m |
| | 172 | | /// for cell tower triangulation, and 18,000m for reverse IP lookup. ts |
| | 173 | | /// (optional): The UTC UNIX timestamp of when the client was at the location. |
| | 174 | | /// (The UNIX timestamp is the number of seconds since January 1, 1970.) head |
| | 175 | | /// (optional): The client's relative heading or direction of travel. Specify |
| | 176 | | /// the direction of travel as degrees from 0 through 360, counting clockwise |
| | 177 | | /// relative to true north. Specify this key only if the sp key is nonzero. sp |
| | 178 | | /// (optional): The horizontal velocity (speed), in meters per second, that the |
| | 179 | | /// client device is traveling. alt (optional): The altitude of the client |
| | 180 | | /// device, in meters. are (optional): The radius, in meters, that specifies |
| | 181 | | /// the vertical accuracy of the coordinates. Specify this key only if you |
| | 182 | | /// specify the alt key. Although many of the keys are optional, the more |
| | 183 | | /// information that you provide, the more accurate the location results are. |
| | 184 | | /// Although optional, you are encouraged to always specify the user's |
| | 185 | | /// geographical location. Providing the location is especially important if |
| | 186 | | /// the client's IP address does not accurately reflect the user's physical |
| | 187 | | /// location (for example, if the client uses VPN). For optimal results, you |
| | 188 | | /// should include this header and the X-MSEdge-ClientIP header, but at a |
| | 189 | | /// minimum, you should include this header. |
| | 190 | | /// </param> |
| | 191 | | /// <param name='aspect'> |
| | 192 | | /// Filter images by the following aspect ratios. All: Do not filter by |
| | 193 | | /// aspect.Specifying this value is the same as not specifying the aspect |
| | 194 | | /// parameter. Square: Return images with standard aspect ratio. Wide: Return |
| | 195 | | /// images with wide screen aspect ratio. Tall: Return images with tall aspect |
| | 196 | | /// ratio. Possible values include: 'All', 'Square', 'Wide', 'Tall' |
| | 197 | | /// </param> |
| | 198 | | /// <param name='color'> |
| | 199 | | /// Filter images by the following color options. ColorOnly: Return color |
| | 200 | | /// images. Monochrome: Return black and white images. Return images with one |
| | 201 | | /// of the following dominant colors: Black, Blue, Brown, Gray, Green, Orange, |
| | 202 | | /// Pink, Purple, Red, Teal, White, Yellow. Possible values include: |
| | 203 | | /// 'ColorOnly', 'Monochrome', 'Black', 'Blue', 'Brown', 'Gray', 'Green', |
| | 204 | | /// 'Orange', 'Pink', 'Purple', 'Red', 'Teal', 'White', 'Yellow' |
| | 205 | | /// </param> |
| | 206 | | /// <param name='countryCode'> |
| | 207 | | /// A 2-character country code of the country where the results come from. For |
| | 208 | | /// a list of possible values, see [Market |
| | 209 | | /// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes |
| | 210 | | /// If you set this parameter, you must also specify the |
| | 211 | | /// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#a |
| | 212 | | /// header. Bing uses the first supported language it finds from the languages |
| | 213 | | /// list, and combine that language with the country code that you specify to |
| | 214 | | /// determine the market to return results for. If the languages list does not |
| | 215 | | /// include a supported language, Bing finds the closest language and market |
| | 216 | | /// that supports the request, or it may use an aggregated or default market |
| | 217 | | /// for the results instead of a specified one. You should use this query |
| | 218 | | /// parameter and the Accept-Language query parameter only if you specify |
| | 219 | | /// multiple languages; otherwise, you should use the mkt and setLang query |
| | 220 | | /// parameters. This parameter and the |
| | 221 | | /// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) |
| | 222 | | /// query parameter are mutually exclusive—do not specify both. |
| | 223 | | /// </param> |
| | 224 | | /// <param name='count'> |
| | 225 | | /// The number of images to return in the response. The actual number delivered |
| | 226 | | /// may be less than requested. The default is 35. The maximum value is 150. |
| | 227 | | /// You use this parameter along with the offset parameter to page results.For |
| | 228 | | /// example, if your user interface displays 20 images per page, set count to |
| | 229 | | /// 20 and offset to 0 to get the first page of results.For each subsequent |
| | 230 | | /// page, increment offset by 20 (for example, 0, 20, 40). Use this parameter |
| | 231 | | /// only with the Image Search API.Do not specify this parameter when calling |
| | 232 | | /// the Insights, Trending Images, or Web Search APIs. |
| | 233 | | /// </param> |
| | 234 | | /// <param name='freshness'> |
| | 235 | | /// Filter images by the following discovery options. Day: Return images |
| | 236 | | /// discovered by Bing within the last 24 hours. Week: Return images discovered |
| | 237 | | /// by Bing within the last 7 days. Month: Return images discovered by Bing |
| | 238 | | /// within the last 30 days. Possible values include: 'Day', 'Week', 'Month' |
| | 239 | | /// </param> |
| | 240 | | /// <param name='height'> |
| | 241 | | /// Filter images that have the specified height, in pixels. You may use this |
| | 242 | | /// filter with the size filter to return small images that have a height of |
| | 243 | | /// 150 pixels. |
| | 244 | | /// </param> |
| | 245 | | /// <param name='id'> |
| | 246 | | /// An ID that uniquely identifies an image. Use this parameter to ensure that |
| | 247 | | /// the specified image is the first image in the list of images that Bing |
| | 248 | | /// returns. The |
| | 249 | | /// [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) |
| | 250 | | /// object's imageId field contains the ID that you set this parameter to. |
| | 251 | | /// </param> |
| | 252 | | /// <param name='imageContent'> |
| | 253 | | /// Filter images by the following content types. Face: Return images that show |
| | 254 | | /// only a person's face. Portrait: Return images that show only a person's |
| | 255 | | /// head and shoulders. Possible values include: 'Face', 'Portrait' |
| | 256 | | /// </param> |
| | 257 | | /// <param name='imageType'> |
| | 258 | | /// Filter images by the following image types. AnimatedGif: Return only |
| | 259 | | /// animated GIFs. Clipart: Return only clip art images. Line: Return only line |
| | 260 | | /// drawings. Photo: Return only photographs(excluding line drawings, animated |
| | 261 | | /// Gifs, and clip art). Shopping: Return only images that contain items where |
| | 262 | | /// Bing knows of a merchant that is selling the items. This option is valid in |
| | 263 | | /// the en - US market only.Transparent: Return only images with a transparent |
| | 264 | | /// background. Possible values include: 'AnimatedGif', 'Clipart', 'Line', |
| | 265 | | /// 'Photo', 'Shopping', 'Transparent' |
| | 266 | | /// </param> |
| | 267 | | /// <param name='license'> |
| | 268 | | /// Filter images by the following license types. All: Do not filter by license |
| | 269 | | /// type.Specifying this value is the same as not specifying the license |
| | 270 | | /// parameter. Any: Return images that are under any license type. The response |
| | 271 | | /// doesn't include images that do not specify a license or the license is |
| | 272 | | /// unknown. Public: Return images where the creator has waived their exclusive |
| | 273 | | /// rights, to the fullest extent allowed by law. Share: Return images that may |
| | 274 | | /// be shared with others. Changing or editing the image might not be allowed. |
| | 275 | | /// Also, modifying, sharing, and using the image for commercial purposes might |
| | 276 | | /// not be allowed. Typically, this option returns the most images. |
| | 277 | | /// ShareCommercially: Return images that may be shared with others for |
| | 278 | | /// personal or commercial purposes. Changing or editing the image might not be |
| | 279 | | /// allowed. Modify: Return images that may be modified, shared, and used. |
| | 280 | | /// Changing or editing the image might not be allowed. Modifying, sharing, and |
| | 281 | | /// using the image for commercial purposes might not be allowed. |
| | 282 | | /// ModifyCommercially: Return images that may be modified, shared, and used |
| | 283 | | /// for personal or commercial purposes. Typically, this option returns the |
| | 284 | | /// fewest images. For more information about these license types, see [Filter |
| | 285 | | /// Images By License Type](http://go.microsoft.com/fwlink/?LinkId=309768). |
| | 286 | | /// Possible values include: 'All', 'Any', 'Public', 'Share', |
| | 287 | | /// 'ShareCommercially', 'Modify', 'ModifyCommercially' |
| | 288 | | /// </param> |
| | 289 | | /// <param name='market'> |
| | 290 | | /// The market where the results come from. Typically, mkt is the country where |
| | 291 | | /// the user is making the request from. However, it could be a different |
| | 292 | | /// country if the user is not located in a country where Bing delivers |
| | 293 | | /// results. The market must be in the form <language code>-<country |
| | 294 | | /// code>. For example, en-US. The string is case insensitive. For a list of |
| | 295 | | /// possible market values, see [Market |
| | 296 | | /// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes |
| | 297 | | /// NOTE: If known, you are encouraged to always specify the market. Specifying |
| | 298 | | /// the market helps Bing route the request and return an appropriate and |
| | 299 | | /// optimal response. If you specify a market that is not listed in [Market |
| | 300 | | /// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes |
| | 301 | | /// Bing uses a best fit market code based on an internal mapping that is |
| | 302 | | /// subject to change. This parameter and the |
| | 303 | | /// [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) |
| | 304 | | /// query parameter are mutually exclusive—do not specify both. |
| | 305 | | /// </param> |
| | 306 | | /// <param name='maxFileSize'> |
| | 307 | | /// Filter images that are less than or equal to the specified file size. The |
| | 308 | | /// maximum file size that you may specify is 520,192 bytes. If you specify a |
| | 309 | | /// larger value, the API uses 520,192. It is possible that the response may |
| | 310 | | /// include images that are slightly larger than the specified maximum. You may |
| | 311 | | /// specify this filter and minFileSize to filter images within a range of file |
| | 312 | | /// sizes. |
| | 313 | | /// </param> |
| | 314 | | /// <param name='maxHeight'> |
| | 315 | | /// Filter images that have a height that is less than or equal to the |
| | 316 | | /// specified height. Specify the height in pixels. You may specify this filter |
| | 317 | | /// and minHeight to filter images within a range of heights. This filter and |
| | 318 | | /// the height filter are mutually exclusive. |
| | 319 | | /// </param> |
| | 320 | | /// <param name='maxWidth'> |
| | 321 | | /// Filter images that have a width that is less than or equal to the specified |
| | 322 | | /// width. Specify the width in pixels. You may specify this filter and |
| | 323 | | /// maxWidth to filter images within a range of widths. This filter and the |
| | 324 | | /// width filter are mutually exclusive. |
| | 325 | | /// </param> |
| | 326 | | /// <param name='minFileSize'> |
| | 327 | | /// Filter images that are greater than or equal to the specified file size. |
| | 328 | | /// The maximum file size that you may specify is 520,192 bytes. If you specify |
| | 329 | | /// a larger value, the API uses 520,192. It is possible that the response may |
| | 330 | | /// include images that are slightly smaller than the specified minimum. You |
| | 331 | | /// may specify this filter and maxFileSize to filter images within a range of |
| | 332 | | /// file sizes. |
| | 333 | | /// </param> |
| | 334 | | /// <param name='minHeight'> |
| | 335 | | /// Filter images that have a height that is greater than or equal to the |
| | 336 | | /// specified height. Specify the height in pixels. You may specify this filter |
| | 337 | | /// and maxHeight to filter images within a range of heights. This filter and |
| | 338 | | /// the height filter are mutually exclusive. |
| | 339 | | /// </param> |
| | 340 | | /// <param name='minWidth'> |
| | 341 | | /// Filter images that have a width that is greater than or equal to the |
| | 342 | | /// specified width. Specify the width in pixels. You may specify this filter |
| | 343 | | /// and maxWidth to filter images within a range of widths. This filter and the |
| | 344 | | /// width filter are mutually exclusive. |
| | 345 | | /// </param> |
| | 346 | | /// <param name='offset'> |
| | 347 | | /// The zero-based offset that indicates the number of images to skip before |
| | 348 | | /// returning images. The default is 0. The offset should be less than |
| | 349 | | /// ([totalEstimatedMatches](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-refe |
| | 350 | | /// - count). Use this parameter along with the count parameter to page |
| | 351 | | /// results. For example, if your user interface displays 20 images per page, |
| | 352 | | /// set count to 20 and offset to 0 to get the first page of results. For each |
| | 353 | | /// subsequent page, increment offset by 20 (for example, 0, 20, 40). It is |
| | 354 | | /// possible for multiple pages to include some overlap in results. To prevent |
| | 355 | | /// duplicates, see |
| | 356 | | /// [nextOffset](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#nextof |
| | 357 | | /// Use this parameter only with the Image API. Do not specify this parameter |
| | 358 | | /// when calling the Trending Images API or the Web Search API. |
| | 359 | | /// </param> |
| | 360 | | /// <param name='safeSearch'> |
| | 361 | | /// Filter images for adult content. The following are the possible filter |
| | 362 | | /// values. Off: May return images with adult content. If the request is |
| | 363 | | /// through the Image Search API, the response includes thumbnail images that |
| | 364 | | /// are clear (non-fuzzy). However, if the request is through the Web Search |
| | 365 | | /// API, the response includes thumbnail images that are pixelated (fuzzy). |
| | 366 | | /// Moderate: If the request is through the Image Search API, the response |
| | 367 | | /// doesn't include images with adult content. If the request is through the |
| | 368 | | /// Web Search API, the response may include images with adult content (the |
| | 369 | | /// thumbnail images are pixelated (fuzzy)). Strict: Do not return images with |
| | 370 | | /// adult content. The default is Moderate. If the request comes from a market |
| | 371 | | /// that Bing's adult policy requires that safeSearch is set to Strict, Bing |
| | 372 | | /// ignores the safeSearch value and uses Strict. If you use the site: query |
| | 373 | | /// operator, there is the chance that the response may contain adult content |
| | 374 | | /// regardless of what the safeSearch query parameter is set to. Use site: only |
| | 375 | | /// if you are aware of the content on the site and your scenario supports the |
| | 376 | | /// possibility of adult content. Possible values include: 'Off', 'Moderate', |
| | 377 | | /// 'Strict' |
| | 378 | | /// </param> |
| | 379 | | /// <param name='size'> |
| | 380 | | /// Filter images by the following sizes. All: Do not filter by size. |
| | 381 | | /// Specifying this value is the same as not specifying the size parameter. |
| | 382 | | /// Small: Return images that are less than 200x200 pixels. Medium: Return |
| | 383 | | /// images that are greater than or equal to 200x200 pixels but less than |
| | 384 | | /// 500x500 pixels. Large: Return images that are 500x500 pixels or larger. |
| | 385 | | /// Wallpaper: Return wallpaper images. You may use this parameter along with |
| | 386 | | /// the height or width parameters. For example, you may use height and size to |
| | 387 | | /// request small images that are 150 pixels tall. Possible values include: |
| | 388 | | /// 'All', 'Small', 'Medium', 'Large', 'Wallpaper' |
| | 389 | | /// </param> |
| | 390 | | /// <param name='setLang'> |
| | 391 | | /// The language to use for user interface strings. Specify the language using |
| | 392 | | /// the ISO 639-1 2-letter language code. For example, the language code for |
| | 393 | | /// English is EN. The default is EN (English). Although optional, you should |
| | 394 | | /// always specify the language. Typically, you set setLang to the same |
| | 395 | | /// language specified by mkt unless the user wants the user interface strings |
| | 396 | | /// displayed in a different language. This parameter and the |
| | 397 | | /// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#a |
| | 398 | | /// header are mutually exclusive; do not specify both. A user interface string |
| | 399 | | /// is a string that's used as a label in a user interface. There are few user |
| | 400 | | /// interface strings in the JSON response objects. Also, any links to Bing.com |
| | 401 | | /// properties in the response objects apply the specified language. |
| | 402 | | /// </param> |
| | 403 | | /// <param name='width'> |
| | 404 | | /// Filter images that have the specified width, in pixels. You may use this |
| | 405 | | /// filter with the size filter to return small images that have a width of 150 |
| | 406 | | /// pixels. |
| | 407 | | /// </param> |
| | 408 | | /// <param name='customHeaders'> |
| | 409 | | /// Headers that will be added to request. |
| | 410 | | /// </param> |
| | 411 | | /// <param name='cancellationToken'> |
| | 412 | | /// The cancellation token. |
| | 413 | | /// </param> |
| | 414 | | /// <exception cref="ErrorResponseException"> |
| | 415 | | /// Thrown when the operation returned an invalid status code |
| | 416 | | /// </exception> |
| | 417 | | /// <exception cref="SerializationException"> |
| | 418 | | /// Thrown when unable to deserialize the response |
| | 419 | | /// </exception> |
| | 420 | | /// <exception cref="ValidationException"> |
| | 421 | | /// Thrown when a required parameter is null |
| | 422 | | /// </exception> |
| | 423 | | /// <exception cref="System.ArgumentNullException"> |
| | 424 | | /// Thrown when a required parameter is null |
| | 425 | | /// </exception> |
| | 426 | | /// <return> |
| | 427 | | /// A response object containing the response body and response headers. |
| | 428 | | /// </return> |
| | 429 | | public async Task<HttpOperationResponse<Images>> SearchWithHttpMessagesAsync(string query, string acceptLanguage |
| | 430 | | { |
| 2 | 431 | | if (Client.Endpoint == null) |
| | 432 | | { |
| 0 | 433 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 434 | | } |
| 2 | 435 | | if (query == null) |
| | 436 | | { |
| 0 | 437 | | throw new ValidationException(ValidationRules.CannotBeNull, "query"); |
| | 438 | | } |
| 2 | 439 | | string xBingApisSDK = "true"; |
| | 440 | | // Tracing |
| 2 | 441 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 442 | | string _invocationId = null; |
| 2 | 443 | | if (_shouldTrace) |
| | 444 | | { |
| 0 | 445 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 446 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 447 | | tracingParameters.Add("xBingApisSDK", xBingApisSDK); |
| 0 | 448 | | tracingParameters.Add("acceptLanguage", acceptLanguage); |
| 0 | 449 | | tracingParameters.Add("userAgent", userAgent); |
| 0 | 450 | | tracingParameters.Add("clientId", clientId); |
| 0 | 451 | | tracingParameters.Add("clientIp", clientIp); |
| 0 | 452 | | tracingParameters.Add("location", location); |
| 0 | 453 | | tracingParameters.Add("aspect", aspect); |
| 0 | 454 | | tracingParameters.Add("color", color); |
| 0 | 455 | | tracingParameters.Add("countryCode", countryCode); |
| 0 | 456 | | tracingParameters.Add("count", count); |
| 0 | 457 | | tracingParameters.Add("freshness", freshness); |
| 0 | 458 | | tracingParameters.Add("height", height); |
| 0 | 459 | | tracingParameters.Add("id", id); |
| 0 | 460 | | tracingParameters.Add("imageContent", imageContent); |
| 0 | 461 | | tracingParameters.Add("imageType", imageType); |
| 0 | 462 | | tracingParameters.Add("license", license); |
| 0 | 463 | | tracingParameters.Add("market", market); |
| 0 | 464 | | tracingParameters.Add("maxFileSize", maxFileSize); |
| 0 | 465 | | tracingParameters.Add("maxHeight", maxHeight); |
| 0 | 466 | | tracingParameters.Add("maxWidth", maxWidth); |
| 0 | 467 | | tracingParameters.Add("minFileSize", minFileSize); |
| 0 | 468 | | tracingParameters.Add("minHeight", minHeight); |
| 0 | 469 | | tracingParameters.Add("minWidth", minWidth); |
| 0 | 470 | | tracingParameters.Add("offset", offset); |
| 0 | 471 | | tracingParameters.Add("query", query); |
| 0 | 472 | | tracingParameters.Add("safeSearch", safeSearch); |
| 0 | 473 | | tracingParameters.Add("size", size); |
| 0 | 474 | | tracingParameters.Add("setLang", setLang); |
| 0 | 475 | | tracingParameters.Add("width", width); |
| 0 | 476 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 477 | | ServiceClientTracing.Enter(_invocationId, this, "Search", tracingParameters); |
| | 478 | | } |
| | 479 | | // Construct URL |
| 2 | 480 | | var _baseUrl = Client.BaseUri; |
| 2 | 481 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "images/search"; |
| 2 | 482 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 483 | | List<string> _queryParameters = new List<string>(); |
| 2 | 484 | | if (aspect != null) |
| | 485 | | { |
| 0 | 486 | | _queryParameters.Add(string.Format("aspect={0}", System.Uri.EscapeDataString(aspect))); |
| | 487 | | } |
| 2 | 488 | | if (color != null) |
| | 489 | | { |
| 0 | 490 | | _queryParameters.Add(string.Format("color={0}", System.Uri.EscapeDataString(color))); |
| | 491 | | } |
| 2 | 492 | | if (countryCode != null) |
| | 493 | | { |
| 0 | 494 | | _queryParameters.Add(string.Format("cc={0}", System.Uri.EscapeDataString(countryCode))); |
| | 495 | | } |
| 2 | 496 | | if (count != null) |
| | 497 | | { |
| 0 | 498 | | _queryParameters.Add(string.Format("count={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonC |
| | 499 | | } |
| 2 | 500 | | if (freshness != null) |
| | 501 | | { |
| 0 | 502 | | _queryParameters.Add(string.Format("freshness={0}", System.Uri.EscapeDataString(freshness))); |
| | 503 | | } |
| 2 | 504 | | if (height != null) |
| | 505 | | { |
| 0 | 506 | | _queryParameters.Add(string.Format("height={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJson |
| | 507 | | } |
| 2 | 508 | | if (id != null) |
| | 509 | | { |
| 0 | 510 | | _queryParameters.Add(string.Format("id={0}", System.Uri.EscapeDataString(id))); |
| | 511 | | } |
| 2 | 512 | | if (imageContent != null) |
| | 513 | | { |
| 0 | 514 | | _queryParameters.Add(string.Format("imageContent={0}", System.Uri.EscapeDataString(imageContent))); |
| | 515 | | } |
| 2 | 516 | | if (imageType != null) |
| | 517 | | { |
| 0 | 518 | | _queryParameters.Add(string.Format("imageType={0}", System.Uri.EscapeDataString(imageType))); |
| | 519 | | } |
| 2 | 520 | | if (license != null) |
| | 521 | | { |
| 0 | 522 | | _queryParameters.Add(string.Format("license={0}", System.Uri.EscapeDataString(license))); |
| | 523 | | } |
| 2 | 524 | | if (market != null) |
| | 525 | | { |
| 0 | 526 | | _queryParameters.Add(string.Format("mkt={0}", System.Uri.EscapeDataString(market))); |
| | 527 | | } |
| 2 | 528 | | if (maxFileSize != null) |
| | 529 | | { |
| 0 | 530 | | _queryParameters.Add(string.Format("maxFileSize={0}", System.Uri.EscapeDataString(Rest.Serialization.Saf |
| | 531 | | } |
| 2 | 532 | | if (maxHeight != null) |
| | 533 | | { |
| 0 | 534 | | _queryParameters.Add(string.Format("maxHeight={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJ |
| | 535 | | } |
| 2 | 536 | | if (maxWidth != null) |
| | 537 | | { |
| 0 | 538 | | _queryParameters.Add(string.Format("maxWidth={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJs |
| | 539 | | } |
| 2 | 540 | | if (minFileSize != null) |
| | 541 | | { |
| 0 | 542 | | _queryParameters.Add(string.Format("minFileSize={0}", System.Uri.EscapeDataString(Rest.Serialization.Saf |
| | 543 | | } |
| 2 | 544 | | if (minHeight != null) |
| | 545 | | { |
| 0 | 546 | | _queryParameters.Add(string.Format("minHeight={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJ |
| | 547 | | } |
| 2 | 548 | | if (minWidth != null) |
| | 549 | | { |
| 0 | 550 | | _queryParameters.Add(string.Format("minWidth={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJs |
| | 551 | | } |
| 2 | 552 | | if (offset != null) |
| | 553 | | { |
| 0 | 554 | | _queryParameters.Add(string.Format("offset={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJson |
| | 555 | | } |
| 2 | 556 | | if (query != null) |
| | 557 | | { |
| 2 | 558 | | _queryParameters.Add(string.Format("q={0}", System.Uri.EscapeDataString(query))); |
| | 559 | | } |
| 2 | 560 | | if (safeSearch != null) |
| | 561 | | { |
| 0 | 562 | | _queryParameters.Add(string.Format("safeSearch={0}", System.Uri.EscapeDataString(safeSearch))); |
| | 563 | | } |
| 2 | 564 | | if (size != null) |
| | 565 | | { |
| 0 | 566 | | _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(size))); |
| | 567 | | } |
| 2 | 568 | | if (setLang != null) |
| | 569 | | { |
| 0 | 570 | | _queryParameters.Add(string.Format("setLang={0}", System.Uri.EscapeDataString(setLang))); |
| | 571 | | } |
| 2 | 572 | | if (width != null) |
| | 573 | | { |
| 0 | 574 | | _queryParameters.Add(string.Format("width={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonC |
| | 575 | | } |
| 2 | 576 | | if (_queryParameters.Count > 0) |
| | 577 | | { |
| 2 | 578 | | _url += "?" + string.Join("&", _queryParameters); |
| | 579 | | } |
| | 580 | | // Create HTTP transport objects |
| 2 | 581 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 582 | | HttpResponseMessage _httpResponse = null; |
| 2 | 583 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 584 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 585 | | // Set Headers |
| 2 | 586 | | if (xBingApisSDK != null) |
| | 587 | | { |
| 2 | 588 | | if (_httpRequest.Headers.Contains("X-BingApis-SDK")) |
| | 589 | | { |
| 0 | 590 | | _httpRequest.Headers.Remove("X-BingApis-SDK"); |
| | 591 | | } |
| 2 | 592 | | _httpRequest.Headers.TryAddWithoutValidation("X-BingApis-SDK", xBingApisSDK); |
| | 593 | | } |
| 2 | 594 | | if (acceptLanguage != null) |
| | 595 | | { |
| 0 | 596 | | if (_httpRequest.Headers.Contains("Accept-Language")) |
| | 597 | | { |
| 0 | 598 | | _httpRequest.Headers.Remove("Accept-Language"); |
| | 599 | | } |
| 0 | 600 | | _httpRequest.Headers.TryAddWithoutValidation("Accept-Language", acceptLanguage); |
| | 601 | | } |
| 2 | 602 | | if (userAgent != null) |
| | 603 | | { |
| 0 | 604 | | if (_httpRequest.Headers.Contains("User-Agent")) |
| | 605 | | { |
| 0 | 606 | | _httpRequest.Headers.Remove("User-Agent"); |
| | 607 | | } |
| 0 | 608 | | _httpRequest.Headers.TryAddWithoutValidation("User-Agent", userAgent); |
| | 609 | | } |
| 2 | 610 | | if (clientId != null) |
| | 611 | | { |
| 0 | 612 | | if (_httpRequest.Headers.Contains("X-MSEdge-ClientID")) |
| | 613 | | { |
| 0 | 614 | | _httpRequest.Headers.Remove("X-MSEdge-ClientID"); |
| | 615 | | } |
| 0 | 616 | | _httpRequest.Headers.TryAddWithoutValidation("X-MSEdge-ClientID", clientId); |
| | 617 | | } |
| 2 | 618 | | if (clientIp != null) |
| | 619 | | { |
| 0 | 620 | | if (_httpRequest.Headers.Contains("X-MSEdge-ClientIP")) |
| | 621 | | { |
| 0 | 622 | | _httpRequest.Headers.Remove("X-MSEdge-ClientIP"); |
| | 623 | | } |
| 0 | 624 | | _httpRequest.Headers.TryAddWithoutValidation("X-MSEdge-ClientIP", clientIp); |
| | 625 | | } |
| 2 | 626 | | if (location != null) |
| | 627 | | { |
| 0 | 628 | | if (_httpRequest.Headers.Contains("X-Search-Location")) |
| | 629 | | { |
| 0 | 630 | | _httpRequest.Headers.Remove("X-Search-Location"); |
| | 631 | | } |
| 0 | 632 | | _httpRequest.Headers.TryAddWithoutValidation("X-Search-Location", location); |
| | 633 | | } |
| | 634 | |
|
| | 635 | |
|
| 2 | 636 | | if (customHeaders != null) |
| | 637 | | { |
| 0 | 638 | | foreach(var _header in customHeaders) |
| | 639 | | { |
| 0 | 640 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 641 | | { |
| 0 | 642 | | _httpRequest.Headers.Remove(_header.Key); |
| | 643 | | } |
| 0 | 644 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 645 | | } |
| | 646 | | } |
| | 647 | |
|
| | 648 | | // Serialize Request |
| 2 | 649 | | string _requestContent = null; |
| | 650 | | // Set Credentials |
| 2 | 651 | | if (Client.Credentials != null) |
| | 652 | | { |
| 2 | 653 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 654 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 655 | | } |
| | 656 | | // Send Request |
| 2 | 657 | | if (_shouldTrace) |
| | 658 | | { |
| 0 | 659 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 660 | | } |
| 2 | 661 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 662 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 663 | | if (_shouldTrace) |
| | 664 | | { |
| 0 | 665 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 666 | | } |
| 2 | 667 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 668 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 669 | | string _responseContent = null; |
| 2 | 670 | | if ((int)_statusCode != 200) |
| | 671 | | { |
| 0 | 672 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 673 | | try |
| | 674 | | { |
| 0 | 675 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 676 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 677 | | if (_errorBody != null) |
| | 678 | | { |
| 0 | 679 | | ex.Body = _errorBody; |
| | 680 | | } |
| 0 | 681 | | } |
| 0 | 682 | | catch (JsonException) |
| | 683 | | { |
| | 684 | | // Ignore the exception |
| 0 | 685 | | } |
| 0 | 686 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 687 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 688 | | if (_shouldTrace) |
| | 689 | | { |
| 0 | 690 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 691 | | } |
| 0 | 692 | | _httpRequest.Dispose(); |
| 0 | 693 | | if (_httpResponse != null) |
| | 694 | | { |
| 0 | 695 | | _httpResponse.Dispose(); |
| | 696 | | } |
| 0 | 697 | | throw ex; |
| | 698 | | } |
| | 699 | | // Create Result |
| 2 | 700 | | var _result = new HttpOperationResponse<Images>(); |
| 2 | 701 | | _result.Request = _httpRequest; |
| 2 | 702 | | _result.Response = _httpResponse; |
| | 703 | | // Deserialize Response |
| 2 | 704 | | if ((int)_statusCode == 200) |
| | 705 | | { |
| 2 | 706 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 707 | | try |
| | 708 | | { |
| 2 | 709 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Images>(_responseContent, Client |
| 2 | 710 | | } |
| 0 | 711 | | catch (JsonException ex) |
| | 712 | | { |
| 0 | 713 | | _httpRequest.Dispose(); |
| 0 | 714 | | if (_httpResponse != null) |
| | 715 | | { |
| 0 | 716 | | _httpResponse.Dispose(); |
| | 717 | | } |
| 0 | 718 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 719 | | } |
| | 720 | | } |
| 2 | 721 | | if (_shouldTrace) |
| | 722 | | { |
| 0 | 723 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 724 | | } |
| 2 | 725 | | return _result; |
| 2 | 726 | | } |
| | 727 | |
|
| | 728 | | /// <summary> |
| | 729 | | /// The Image Detail Search API lets you search on Bing and get back insights |
| | 730 | | /// about an image, such as webpages that include the image. This section |
| | 731 | | /// provides technical details about the query parameters and headers that you |
| | 732 | | /// use to request insights of images and the JSON response objects that |
| | 733 | | /// contain them. For examples that show how to make requests, see [Searching |
| | 734 | | /// the Web for |
| | 735 | | /// Images](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/search-the-web). |
| | 736 | | /// </summary> |
| | 737 | | /// <param name='query'> |
| | 738 | | /// The user's search query term. The term cannot be empty. The term may |
| | 739 | | /// contain [Bing Advanced |
| | 740 | | /// Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, |
| | 741 | | /// to limit images to a specific domain, use the |
| | 742 | | /// [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. To help |
| | 743 | | /// improve relevance of an insights query (see |
| | 744 | | /// [insightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#ins |
| | 745 | | /// you should always include the user's query term. Use this parameter only |
| | 746 | | /// with the Image Search API.Do not specify this parameter when calling the |
| | 747 | | /// Trending Images API. |
| | 748 | | /// </param> |
| | 749 | | /// <param name='acceptLanguage'> |
| | 750 | | /// A comma-delimited list of one or more languages to use for user interface |
| | 751 | | /// strings. The list is in decreasing order of preference. For additional |
| | 752 | | /// information, including expected format, see |
| | 753 | | /// [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This |
| | 754 | | /// header and the |
| | 755 | | /// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) |
| | 756 | | /// query parameter are mutually exclusive; do not specify both. If you set |
| | 757 | | /// this header, you must also specify the |
| | 758 | | /// [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) |
| | 759 | | /// query parameter. To determine the market to return results for, Bing uses |
| | 760 | | /// the first supported language it finds from the list and combines it with |
| | 761 | | /// the cc parameter value. If the list does not include a supported language, |
| | 762 | | /// Bing finds the closest language and market that supports the request or it |
| | 763 | | /// uses an aggregated or default market for the results. To determine the |
| | 764 | | /// market that Bing used, see the BingAPIs-Market header. Use this header and |
| | 765 | | /// the cc query parameter only if you specify multiple languages. Otherwise, |
| | 766 | | /// use the |
| | 767 | | /// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) |
| | 768 | | /// and |
| | 769 | | /// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) |
| | 770 | | /// query parameters. A user interface string is a string that's used as a |
| | 771 | | /// label in a user interface. There are few user interface strings in the JSON |
| | 772 | | /// response objects. Any links to Bing.com properties in the response objects |
| | 773 | | /// apply the specified language. |
| | 774 | | /// </param> |
| | 775 | | /// <param name='contentType'> |
| | 776 | | /// Optional request header. If you set the |
| | 777 | | /// [modules](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#modulesre |
| | 778 | | /// query parameter to RecognizedEntities, you may specify the binary of an |
| | 779 | | /// image in the body of a POST request. If you specify the image in the body |
| | 780 | | /// of a POST request, you must specify this header and set its value to |
| | 781 | | /// multipart/form-data. The maximum image size is 1 MB. |
| | 782 | | /// </param> |
| | 783 | | /// <param name='userAgent'> |
| | 784 | | /// The user agent originating the request. Bing uses the user agent to provide |
| | 785 | | /// mobile users with an optimized experience. Although optional, you are |
| | 786 | | /// encouraged to always specify this header. The user-agent should be the same |
| | 787 | | /// string that any commonly used browser sends. For information about user |
| | 788 | | /// agents, see [RFC |
| | 789 | | /// 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The |
| | 790 | | /// following are examples of user-agent strings. Windows Phone: Mozilla/5.0 |
| | 791 | | /// (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; |
| | 792 | | /// Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; |
| | 793 | | /// en - us; SCH - I500 Build / GINGERBREAD) AppleWebKit / 533.1 (KHTML; like |
| | 794 | | /// Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 5.0 (iPhone; |
| | 795 | | /// CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) |
| | 796 | | /// Mobile / 10B142 iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 |
| | 797 | | /// (Windows NT 6.3; WOW64; Trident / 7.0; Touch; rv:11.0) like Gecko. iPad: |
| | 798 | | /// Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 |
| | 799 | | /// (KHTML, like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 |
| | 800 | | /// </param> |
| | 801 | | /// <param name='clientId'> |
| | 802 | | /// Bing uses this header to provide users with consistent behavior across Bing |
| | 803 | | /// API calls. Bing often flights new features and improvements, and it uses |
| | 804 | | /// the client ID as a key for assigning traffic on different flights. If you |
| | 805 | | /// do not use the same client ID for a user across multiple requests, then |
| | 806 | | /// Bing may assign the user to multiple conflicting flights. Being assigned to |
| | 807 | | /// multiple conflicting flights can lead to an inconsistent user experience. |
| | 808 | | /// For example, if the second request has a different flight assignment than |
| | 809 | | /// the first, the experience may be unexpected. Also, Bing can use the client |
| | 810 | | /// ID to tailor web results to that client ID’s search history, providing a |
| | 811 | | /// richer experience for the user. Bing also uses this header to help improve |
| | 812 | | /// result rankings by analyzing the activity generated by a client ID. The |
| | 813 | | /// relevance improvements help with better quality of results delivered by |
| | 814 | | /// Bing APIs and in turn enables higher click-through rates for the API |
| | 815 | | /// consumer. IMPORTANT: Although optional, you should consider this header |
| | 816 | | /// required. Persisting the client ID across multiple requests for the same |
| | 817 | | /// end user and device combination enables 1) the API consumer to receive a |
| | 818 | | /// consistent user experience, and 2) higher click-through rates via better |
| | 819 | | /// quality of results from the Bing APIs. Each user that uses your application |
| | 820 | | /// on the device must have a unique, Bing generated client ID. If you do not |
| | 821 | | /// include this header in the request, Bing generates an ID and returns it in |
| | 822 | | /// the X-MSEdge-ClientID response header. The only time that you should NOT |
| | 823 | | /// include this header in a request is the first time the user uses your app |
| | 824 | | /// on that device. Use the client ID for each Bing API request that your app |
| | 825 | | /// makes for this user on the device. Persist the client ID. To persist the ID |
| | 826 | | /// in a browser app, use a persistent HTTP cookie to ensure the ID is used |
| | 827 | | /// across all sessions. Do not use a session cookie. For other apps such as |
| | 828 | | /// mobile apps, use the device's persistent storage to persist the ID. The |
| | 829 | | /// next time the user uses your app on that device, get the client ID that you |
| | 830 | | /// persisted. Bing responses may or may not include this header. If the |
| | 831 | | /// response includes this header, capture the client ID and use it for all |
| | 832 | | /// subsequent Bing requests for the user on that device. If you include the |
| | 833 | | /// X-MSEdge-ClientID, you must not include cookies in the request. |
| | 834 | | /// </param> |
| | 835 | | /// <param name='clientIp'> |
| | 836 | | /// The IPv4 or IPv6 address of the client device. The IP address is used to |
| | 837 | | /// discover the user's location. Bing uses the location information to |
| | 838 | | /// determine safe search behavior. Although optional, you are encouraged to |
| | 839 | | /// always specify this header and the X-Search-Location header. Do not |
| | 840 | | /// obfuscate the address (for example, by changing the last octet to 0). |
| | 841 | | /// Obfuscating the address results in the location not being anywhere near the |
| | 842 | | /// device's actual location, which may result in Bing serving erroneous |
| | 843 | | /// results. |
| | 844 | | /// </param> |
| | 845 | | /// <param name='location'> |
| | 846 | | /// A semicolon-delimited list of key/value pairs that describe the client's |
| | 847 | | /// geographical location. Bing uses the location information to determine safe |
| | 848 | | /// search behavior and to return relevant local content. Specify the key/value |
| | 849 | | /// pair as <key>:<value>. The following are the keys that you use |
| | 850 | | /// to specify the user's location. lat (required): The latitude of the |
| | 851 | | /// client's location, in degrees. The latitude must be greater than or equal |
| | 852 | | /// to -90.0 and less than or equal to +90.0. Negative values indicate southern |
| | 853 | | /// latitudes and positive values indicate northern latitudes. long (required): |
| | 854 | | /// The longitude of the client's location, in degrees. The longitude must be |
| | 855 | | /// greater than or equal to -180.0 and less than or equal to +180.0. Negative |
| | 856 | | /// values indicate western longitudes and positive values indicate eastern |
| | 857 | | /// longitudes. re (required): The radius, in meters, which specifies the |
| | 858 | | /// horizontal accuracy of the coordinates. Pass the value returned by the |
| | 859 | | /// device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m |
| | 860 | | /// for cell tower triangulation, and 18,000m for reverse IP lookup. ts |
| | 861 | | /// (optional): The UTC UNIX timestamp of when the client was at the location. |
| | 862 | | /// (The UNIX timestamp is the number of seconds since January 1, 1970.) head |
| | 863 | | /// (optional): The client's relative heading or direction of travel. Specify |
| | 864 | | /// the direction of travel as degrees from 0 through 360, counting clockwise |
| | 865 | | /// relative to true north. Specify this key only if the sp key is nonzero. sp |
| | 866 | | /// (optional): The horizontal velocity (speed), in meters per second, that the |
| | 867 | | /// client device is traveling. alt (optional): The altitude of the client |
| | 868 | | /// device, in meters. are (optional): The radius, in meters, that specifies |
| | 869 | | /// the vertical accuracy of the coordinates. Specify this key only if you |
| | 870 | | /// specify the alt key. Although many of the keys are optional, the more |
| | 871 | | /// information that you provide, the more accurate the location results are. |
| | 872 | | /// Although optional, you are encouraged to always specify the user's |
| | 873 | | /// geographical location. Providing the location is especially important if |
| | 874 | | /// the client's IP address does not accurately reflect the user's physical |
| | 875 | | /// location (for example, if the client uses VPN). For optimal results, you |
| | 876 | | /// should include this header and the X-MSEdge-ClientIP header, but at a |
| | 877 | | /// minimum, you should include this header. |
| | 878 | | /// </param> |
| | 879 | | /// <param name='cropBottom'> |
| | 880 | | /// The bottom coordinate of the region to crop. The coordinate is a fractional |
| | 881 | | /// value of the original image's height and is measured from the top, left |
| | 882 | | /// corner of the image. Specify the coordinate as a value from 0.0 through |
| | 883 | | /// 1.0. Use this parameter only with the Insights API. Do not specify this |
| | 884 | | /// parameter when calling the Images, Trending Images, or Web Search APIs. |
| | 885 | | /// </param> |
| | 886 | | /// <param name='cropLeft'> |
| | 887 | | /// The left coordinate of the region to crop. The coordinate is a fractional |
| | 888 | | /// value of the original image's height and is measured from the top, left |
| | 889 | | /// corner of the image. Specify the coordinate as a value from 0.0 through |
| | 890 | | /// 1.0. Use this parameter only with the Insights API. Do not specify this |
| | 891 | | /// parameter when calling the Images, Trending Images, or Web Search APIs. |
| | 892 | | /// </param> |
| | 893 | | /// <param name='cropRight'> |
| | 894 | | /// The right coordinate of the region to crop. The coordinate is a fractional |
| | 895 | | /// value of the original image's height and is measured from the top, left |
| | 896 | | /// corner of the image. Specify the coordinate as a value from 0.0 through |
| | 897 | | /// 1.0. Use this parameter only with the Insights API. Do not specify this |
| | 898 | | /// parameter when calling the Images, Trending Images, or Web Search APIs. |
| | 899 | | /// </param> |
| | 900 | | /// <param name='cropTop'> |
| | 901 | | /// The top coordinate of the region to crop. The coordinate is a fractional |
| | 902 | | /// value of the original image's height and is measured from the top, left |
| | 903 | | /// corner of the image. Specify the coordinate as a value from 0.0 through |
| | 904 | | /// 1.0. Use this parameter only with the Insights API. Do not specify this |
| | 905 | | /// parameter when calling the Images, Trending Images, or Web Search APIs. |
| | 906 | | /// </param> |
| | 907 | | /// <param name='cropType'> |
| | 908 | | /// The crop type to use when cropping the image based on the coordinates |
| | 909 | | /// specified in the cal, cat, car, and cab parameters. The following are the |
| | 910 | | /// possible values. 0: Rectangular (default). Use this parameter only with the |
| | 911 | | /// Insights API. Do not specify this parameter when calling the Images, |
| | 912 | | /// Trending Images, or Web Search APIs. Possible values include: 'Rectangular' |
| | 913 | | /// </param> |
| | 914 | | /// <param name='countryCode'> |
| | 915 | | /// A 2-character country code of the country where the results come from. For |
| | 916 | | /// a list of possible values, see [Market |
| | 917 | | /// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes |
| | 918 | | /// If you set this parameter, you must also specify the |
| | 919 | | /// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#a |
| | 920 | | /// header. Bing uses the first supported language it finds from the languages |
| | 921 | | /// list, and combine that language with the country code that you specify to |
| | 922 | | /// determine the market to return results for. If the languages list does not |
| | 923 | | /// include a supported language, Bing finds the closest language and market |
| | 924 | | /// that supports the request, or it may use an aggregated or default market |
| | 925 | | /// for the results instead of a specified one. You should use this query |
| | 926 | | /// parameter and the Accept-Language query parameter only if you specify |
| | 927 | | /// multiple languages; otherwise, you should use the mkt and setLang query |
| | 928 | | /// parameters. This parameter and the |
| | 929 | | /// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) |
| | 930 | | /// query parameter are mutually exclusive—do not specify both. |
| | 931 | | /// </param> |
| | 932 | | /// <param name='id'> |
| | 933 | | /// An ID that uniquely identifies an image. Use this parameter to ensure that |
| | 934 | | /// the specified image is the first image in the list of images that Bing |
| | 935 | | /// returns. The |
| | 936 | | /// [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) |
| | 937 | | /// object's imageId field contains the ID that you set this parameter to. |
| | 938 | | /// </param> |
| | 939 | | /// <param name='imageUrl'> |
| | 940 | | /// The URL of an image that you want to get insights of. Use this parameter as |
| | 941 | | /// an alternative to using the insightsToken parameter to specify the image. |
| | 942 | | /// You may also specify the image by placing the binary of the image in the |
| | 943 | | /// body of a POST request. If you use the binary option, see the |
| | 944 | | /// [Content-Type](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cont |
| | 945 | | /// header. The maximum supported image size is 1 MB. Use this parameter only |
| | 946 | | /// with the Insights API. Do not specify this parameter when calling the |
| | 947 | | /// Images, Trending Images, or Web Search APIs. |
| | 948 | | /// </param> |
| | 949 | | /// <param name='insightsToken'> |
| | 950 | | /// An image token. The |
| | 951 | | /// [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) |
| | 952 | | /// object's |
| | 953 | | /// [imageInsightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-referenc |
| | 954 | | /// contains the token. Specify this parameter to get additional information |
| | 955 | | /// about an image, such as a caption or shopping source. For a list of the |
| | 956 | | /// additional information about an image that you can get, see the |
| | 957 | | /// [modules](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#modulesre |
| | 958 | | /// query parameter. Use this parameter only with the Insights API. Do not |
| | 959 | | /// specify this parameter when calling the Images, Trending Images, or Web |
| | 960 | | /// Search APIs. |
| | 961 | | /// </param> |
| | 962 | | /// <param name='modules'> |
| | 963 | | /// A comma-delimited list of insights to request. The following are the |
| | 964 | | /// possible case-insensitive values. All: Return all insights, if available, |
| | 965 | | /// except RecognizedEntities. BRQ: Best representative query. The query term |
| | 966 | | /// that best describes the image. Caption: A caption that provides information |
| | 967 | | /// about the image. If the caption contains entities, the response may include |
| | 968 | | /// links to images of those entities. Collections: A list of related images. |
| | 969 | | /// Recipes: A list of recipes for cooking the food shown in the images. |
| | 970 | | /// PagesIncluding: A list of webpages that include the image. |
| | 971 | | /// RecognizedEntities: A list of entities (people) that were recognized in the |
| | 972 | | /// image. NOTE: You may not specify this module with any other module. If you |
| | 973 | | /// specify it with other modules, the response doesn't include recognized |
| | 974 | | /// entities. RelatedSearches: A list of related searches made by others. |
| | 975 | | /// ShoppingSources: A list of merchants where you can buy related offerings. |
| | 976 | | /// SimilarImages: A list of images that are visually similar to the original |
| | 977 | | /// image. SimilarProducts: A list of images that contain a product that is |
| | 978 | | /// similar to a product found in the original image. Tags: Provides |
| | 979 | | /// characteristics of the type of content found in the image. For example, if |
| | 980 | | /// the image is of a person, the tags might indicate the person's gender and |
| | 981 | | /// type of clothes they're wearing. If you specify a module and there is no |
| | 982 | | /// data for the module, the response object doesn't include the related field. |
| | 983 | | /// For example, if you specify Caption and it does not exist, the response |
| | 984 | | /// doesn't include the imageCaption field. To include related searches, the |
| | 985 | | /// request must include the original query string. Although the original query |
| | 986 | | /// string is not required for similar images or products, you should always |
| | 987 | | /// include it because it can help improve relevance and the results. Use this |
| | 988 | | /// parameter only with the Insights API. Do not specify this parameter when |
| | 989 | | /// calling the Images, Trending Images, or Web Search APIs. |
| | 990 | | /// </param> |
| | 991 | | /// <param name='market'> |
| | 992 | | /// The market where the results come from. Typically, mkt is the country where |
| | 993 | | /// the user is making the request from. However, it could be a different |
| | 994 | | /// country if the user is not located in a country where Bing delivers |
| | 995 | | /// results. The market must be in the form <language code>-<country |
| | 996 | | /// code>. For example, en-US. The string is case insensitive. For a list of |
| | 997 | | /// possible market values, see [Market |
| | 998 | | /// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes |
| | 999 | | /// NOTE: If known, you are encouraged to always specify the market. Specifying |
| | 1000 | | /// the market helps Bing route the request and return an appropriate and |
| | 1001 | | /// optimal response. If you specify a market that is not listed in [Market |
| | 1002 | | /// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes |
| | 1003 | | /// Bing uses a best fit market code based on an internal mapping that is |
| | 1004 | | /// subject to change. This parameter and the |
| | 1005 | | /// [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) |
| | 1006 | | /// query parameter are mutually exclusive—do not specify both. |
| | 1007 | | /// </param> |
| | 1008 | | /// <param name='safeSearch'> |
| | 1009 | | /// Filter images for adult content. The following are the possible filter |
| | 1010 | | /// values. Off: May return images with adult content. If the request is |
| | 1011 | | /// through the Image Search API, the response includes thumbnail images that |
| | 1012 | | /// are clear (non-fuzzy). However, if the request is through the Web Search |
| | 1013 | | /// API, the response includes thumbnail images that are pixelated (fuzzy). |
| | 1014 | | /// Moderate: If the request is through the Image Search API, the response |
| | 1015 | | /// doesn't include images with adult content. If the request is through the |
| | 1016 | | /// Web Search API, the response may include images with adult content (the |
| | 1017 | | /// thumbnail images are pixelated (fuzzy)). Strict: Do not return images with |
| | 1018 | | /// adult content. The default is Moderate. If the request comes from a market |
| | 1019 | | /// that Bing's adult policy requires that safeSearch is set to Strict, Bing |
| | 1020 | | /// ignores the safeSearch value and uses Strict. If you use the site: query |
| | 1021 | | /// operator, there is the chance that the response may contain adult content |
| | 1022 | | /// regardless of what the safeSearch query parameter is set to. Use site: only |
| | 1023 | | /// if you are aware of the content on the site and your scenario supports the |
| | 1024 | | /// possibility of adult content. Possible values include: 'Off', 'Moderate', |
| | 1025 | | /// 'Strict' |
| | 1026 | | /// </param> |
| | 1027 | | /// <param name='setLang'> |
| | 1028 | | /// The language to use for user interface strings. Specify the language using |
| | 1029 | | /// the ISO 639-1 2-letter language code. For example, the language code for |
| | 1030 | | /// English is EN. The default is EN (English). Although optional, you should |
| | 1031 | | /// always specify the language. Typically, you set setLang to the same |
| | 1032 | | /// language specified by mkt unless the user wants the user interface strings |
| | 1033 | | /// displayed in a different language. This parameter and the |
| | 1034 | | /// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#a |
| | 1035 | | /// header are mutually exclusive; do not specify both. A user interface string |
| | 1036 | | /// is a string that's used as a label in a user interface. There are few user |
| | 1037 | | /// interface strings in the JSON response objects. Also, any links to Bing.com |
| | 1038 | | /// properties in the response objects apply the specified language. |
| | 1039 | | /// </param> |
| | 1040 | | /// <param name='customHeaders'> |
| | 1041 | | /// Headers that will be added to request. |
| | 1042 | | /// </param> |
| | 1043 | | /// <param name='cancellationToken'> |
| | 1044 | | /// The cancellation token. |
| | 1045 | | /// </param> |
| | 1046 | | /// <exception cref="ErrorResponseException"> |
| | 1047 | | /// Thrown when the operation returned an invalid status code |
| | 1048 | | /// </exception> |
| | 1049 | | /// <exception cref="SerializationException"> |
| | 1050 | | /// Thrown when unable to deserialize the response |
| | 1051 | | /// </exception> |
| | 1052 | | /// <exception cref="ValidationException"> |
| | 1053 | | /// Thrown when a required parameter is null |
| | 1054 | | /// </exception> |
| | 1055 | | /// <exception cref="System.ArgumentNullException"> |
| | 1056 | | /// Thrown when a required parameter is null |
| | 1057 | | /// </exception> |
| | 1058 | | /// <return> |
| | 1059 | | /// A response object containing the response body and response headers. |
| | 1060 | | /// </return> |
| | 1061 | | public async Task<HttpOperationResponse<ImageInsights>> DetailsWithHttpMessagesAsync(string query, string accept |
| | 1062 | | { |
| 2 | 1063 | | if (Client.Endpoint == null) |
| | 1064 | | { |
| 0 | 1065 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1066 | | } |
| 2 | 1067 | | if (query == null) |
| | 1068 | | { |
| 0 | 1069 | | throw new ValidationException(ValidationRules.CannotBeNull, "query"); |
| | 1070 | | } |
| 2 | 1071 | | string xBingApisSDK = "true"; |
| | 1072 | | // Tracing |
| 2 | 1073 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1074 | | string _invocationId = null; |
| 2 | 1075 | | if (_shouldTrace) |
| | 1076 | | { |
| 0 | 1077 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1078 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1079 | | tracingParameters.Add("xBingApisSDK", xBingApisSDK); |
| 0 | 1080 | | tracingParameters.Add("acceptLanguage", acceptLanguage); |
| 0 | 1081 | | tracingParameters.Add("contentType", contentType); |
| 0 | 1082 | | tracingParameters.Add("userAgent", userAgent); |
| 0 | 1083 | | tracingParameters.Add("clientId", clientId); |
| 0 | 1084 | | tracingParameters.Add("clientIp", clientIp); |
| 0 | 1085 | | tracingParameters.Add("location", location); |
| 0 | 1086 | | tracingParameters.Add("cropBottom", cropBottom); |
| 0 | 1087 | | tracingParameters.Add("cropLeft", cropLeft); |
| 0 | 1088 | | tracingParameters.Add("cropRight", cropRight); |
| 0 | 1089 | | tracingParameters.Add("cropTop", cropTop); |
| 0 | 1090 | | tracingParameters.Add("cropType", cropType); |
| 0 | 1091 | | tracingParameters.Add("countryCode", countryCode); |
| 0 | 1092 | | tracingParameters.Add("id", id); |
| 0 | 1093 | | tracingParameters.Add("imageUrl", imageUrl); |
| 0 | 1094 | | tracingParameters.Add("insightsToken", insightsToken); |
| 0 | 1095 | | tracingParameters.Add("modules", modules); |
| 0 | 1096 | | tracingParameters.Add("market", market); |
| 0 | 1097 | | tracingParameters.Add("query", query); |
| 0 | 1098 | | tracingParameters.Add("safeSearch", safeSearch); |
| 0 | 1099 | | tracingParameters.Add("setLang", setLang); |
| 0 | 1100 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1101 | | ServiceClientTracing.Enter(_invocationId, this, "Details", tracingParameters); |
| | 1102 | | } |
| | 1103 | | // Construct URL |
| 2 | 1104 | | var _baseUrl = Client.BaseUri; |
| 2 | 1105 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "images/details"; |
| 2 | 1106 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 1107 | | List<string> _queryParameters = new List<string>(); |
| 2 | 1108 | | if (cropBottom != null) |
| | 1109 | | { |
| 0 | 1110 | | _queryParameters.Add(string.Format("cab={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | 1111 | | } |
| 2 | 1112 | | if (cropLeft != null) |
| | 1113 | | { |
| 0 | 1114 | | _queryParameters.Add(string.Format("cal={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | 1115 | | } |
| 2 | 1116 | | if (cropRight != null) |
| | 1117 | | { |
| 0 | 1118 | | _queryParameters.Add(string.Format("car={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | 1119 | | } |
| 2 | 1120 | | if (cropTop != null) |
| | 1121 | | { |
| 0 | 1122 | | _queryParameters.Add(string.Format("cat={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | 1123 | | } |
| 2 | 1124 | | if (cropType != null) |
| | 1125 | | { |
| 0 | 1126 | | _queryParameters.Add(string.Format("ct={0}", System.Uri.EscapeDataString(cropType))); |
| | 1127 | | } |
| 2 | 1128 | | if (countryCode != null) |
| | 1129 | | { |
| 0 | 1130 | | _queryParameters.Add(string.Format("cc={0}", System.Uri.EscapeDataString(countryCode))); |
| | 1131 | | } |
| 2 | 1132 | | if (id != null) |
| | 1133 | | { |
| 0 | 1134 | | _queryParameters.Add(string.Format("id={0}", System.Uri.EscapeDataString(id))); |
| | 1135 | | } |
| 2 | 1136 | | if (imageUrl != null) |
| | 1137 | | { |
| 0 | 1138 | | _queryParameters.Add(string.Format("imgUrl={0}", System.Uri.EscapeDataString(imageUrl))); |
| | 1139 | | } |
| 2 | 1140 | | if (insightsToken != null) |
| | 1141 | | { |
| 2 | 1142 | | _queryParameters.Add(string.Format("insightsToken={0}", System.Uri.EscapeDataString(insightsToken))); |
| | 1143 | | } |
| 2 | 1144 | | if (modules != null) |
| | 1145 | | { |
| 2 | 1146 | | _queryParameters.Add(string.Format("modules={0}", System.Uri.EscapeDataString(string.Join(",", modules)) |
| | 1147 | | } |
| 2 | 1148 | | if (market != null) |
| | 1149 | | { |
| 0 | 1150 | | _queryParameters.Add(string.Format("mkt={0}", System.Uri.EscapeDataString(market))); |
| | 1151 | | } |
| 2 | 1152 | | if (query != null) |
| | 1153 | | { |
| 2 | 1154 | | _queryParameters.Add(string.Format("q={0}", System.Uri.EscapeDataString(query))); |
| | 1155 | | } |
| 2 | 1156 | | if (safeSearch != null) |
| | 1157 | | { |
| 0 | 1158 | | _queryParameters.Add(string.Format("safeSearch={0}", System.Uri.EscapeDataString(safeSearch))); |
| | 1159 | | } |
| 2 | 1160 | | if (setLang != null) |
| | 1161 | | { |
| 0 | 1162 | | _queryParameters.Add(string.Format("setLang={0}", System.Uri.EscapeDataString(setLang))); |
| | 1163 | | } |
| 2 | 1164 | | if (_queryParameters.Count > 0) |
| | 1165 | | { |
| 2 | 1166 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1167 | | } |
| | 1168 | | // Create HTTP transport objects |
| 2 | 1169 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1170 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1171 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 1172 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1173 | | // Set Headers |
| 2 | 1174 | | if (xBingApisSDK != null) |
| | 1175 | | { |
| 2 | 1176 | | if (_httpRequest.Headers.Contains("X-BingApis-SDK")) |
| | 1177 | | { |
| 0 | 1178 | | _httpRequest.Headers.Remove("X-BingApis-SDK"); |
| | 1179 | | } |
| 2 | 1180 | | _httpRequest.Headers.TryAddWithoutValidation("X-BingApis-SDK", xBingApisSDK); |
| | 1181 | | } |
| 2 | 1182 | | if (acceptLanguage != null) |
| | 1183 | | { |
| 0 | 1184 | | if (_httpRequest.Headers.Contains("Accept-Language")) |
| | 1185 | | { |
| 0 | 1186 | | _httpRequest.Headers.Remove("Accept-Language"); |
| | 1187 | | } |
| 0 | 1188 | | _httpRequest.Headers.TryAddWithoutValidation("Accept-Language", acceptLanguage); |
| | 1189 | | } |
| 2 | 1190 | | if (userAgent != null) |
| | 1191 | | { |
| 0 | 1192 | | if (_httpRequest.Headers.Contains("User-Agent")) |
| | 1193 | | { |
| 0 | 1194 | | _httpRequest.Headers.Remove("User-Agent"); |
| | 1195 | | } |
| 0 | 1196 | | _httpRequest.Headers.TryAddWithoutValidation("User-Agent", userAgent); |
| | 1197 | | } |
| 2 | 1198 | | if (clientId != null) |
| | 1199 | | { |
| 0 | 1200 | | if (_httpRequest.Headers.Contains("X-MSEdge-ClientID")) |
| | 1201 | | { |
| 0 | 1202 | | _httpRequest.Headers.Remove("X-MSEdge-ClientID"); |
| | 1203 | | } |
| 0 | 1204 | | _httpRequest.Headers.TryAddWithoutValidation("X-MSEdge-ClientID", clientId); |
| | 1205 | | } |
| 2 | 1206 | | if (clientIp != null) |
| | 1207 | | { |
| 0 | 1208 | | if (_httpRequest.Headers.Contains("X-MSEdge-ClientIP")) |
| | 1209 | | { |
| 0 | 1210 | | _httpRequest.Headers.Remove("X-MSEdge-ClientIP"); |
| | 1211 | | } |
| 0 | 1212 | | _httpRequest.Headers.TryAddWithoutValidation("X-MSEdge-ClientIP", clientIp); |
| | 1213 | | } |
| 2 | 1214 | | if (location != null) |
| | 1215 | | { |
| 0 | 1216 | | if (_httpRequest.Headers.Contains("X-Search-Location")) |
| | 1217 | | { |
| 0 | 1218 | | _httpRequest.Headers.Remove("X-Search-Location"); |
| | 1219 | | } |
| 0 | 1220 | | _httpRequest.Headers.TryAddWithoutValidation("X-Search-Location", location); |
| | 1221 | | } |
| | 1222 | |
|
| | 1223 | |
|
| 2 | 1224 | | if (customHeaders != null) |
| | 1225 | | { |
| 0 | 1226 | | foreach(var _header in customHeaders) |
| | 1227 | | { |
| 0 | 1228 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1229 | | { |
| 0 | 1230 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1231 | | } |
| 0 | 1232 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1233 | | } |
| | 1234 | | } |
| | 1235 | |
|
| | 1236 | | // Serialize Request |
| 2 | 1237 | | string _requestContent = null; |
| | 1238 | | // Set Credentials |
| 2 | 1239 | | if (Client.Credentials != null) |
| | 1240 | | { |
| 2 | 1241 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1242 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1243 | | } |
| | 1244 | | // Send Request |
| 2 | 1245 | | if (_shouldTrace) |
| | 1246 | | { |
| 0 | 1247 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1248 | | } |
| 2 | 1249 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1250 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 1251 | | if (_shouldTrace) |
| | 1252 | | { |
| 0 | 1253 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1254 | | } |
| 2 | 1255 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 1256 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1257 | | string _responseContent = null; |
| 2 | 1258 | | if ((int)_statusCode != 200) |
| | 1259 | | { |
| 0 | 1260 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1261 | | try |
| | 1262 | | { |
| 0 | 1263 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1264 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1265 | | if (_errorBody != null) |
| | 1266 | | { |
| 0 | 1267 | | ex.Body = _errorBody; |
| | 1268 | | } |
| 0 | 1269 | | } |
| 0 | 1270 | | catch (JsonException) |
| | 1271 | | { |
| | 1272 | | // Ignore the exception |
| 0 | 1273 | | } |
| 0 | 1274 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1275 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1276 | | if (_shouldTrace) |
| | 1277 | | { |
| 0 | 1278 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1279 | | } |
| 0 | 1280 | | _httpRequest.Dispose(); |
| 0 | 1281 | | if (_httpResponse != null) |
| | 1282 | | { |
| 0 | 1283 | | _httpResponse.Dispose(); |
| | 1284 | | } |
| 0 | 1285 | | throw ex; |
| | 1286 | | } |
| | 1287 | | // Create Result |
| 2 | 1288 | | var _result = new HttpOperationResponse<ImageInsights>(); |
| 2 | 1289 | | _result.Request = _httpRequest; |
| 2 | 1290 | | _result.Response = _httpResponse; |
| | 1291 | | // Deserialize Response |
| 2 | 1292 | | if ((int)_statusCode == 200) |
| | 1293 | | { |
| 2 | 1294 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1295 | | try |
| | 1296 | | { |
| 2 | 1297 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ImageInsights>(_responseContent, |
| 2 | 1298 | | } |
| 0 | 1299 | | catch (JsonException ex) |
| | 1300 | | { |
| 0 | 1301 | | _httpRequest.Dispose(); |
| 0 | 1302 | | if (_httpResponse != null) |
| | 1303 | | { |
| 0 | 1304 | | _httpResponse.Dispose(); |
| | 1305 | | } |
| 0 | 1306 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1307 | | } |
| | 1308 | | } |
| 2 | 1309 | | if (_shouldTrace) |
| | 1310 | | { |
| 0 | 1311 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1312 | | } |
| 2 | 1313 | | return _result; |
| 2 | 1314 | | } |
| | 1315 | |
|
| | 1316 | | /// <summary> |
| | 1317 | | /// The Image Trending Search API lets you search on Bing and get back a list |
| | 1318 | | /// of images that are trending based on search requests made by others. The |
| | 1319 | | /// images are broken out into different categories. For example, Popular |
| | 1320 | | /// People Searches. For a list of markets that support trending images, see |
| | 1321 | | /// [Trending |
| | 1322 | | /// Images](https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/trending-images). |
| | 1323 | | /// </summary> |
| | 1324 | | /// <param name='acceptLanguage'> |
| | 1325 | | /// A comma-delimited list of one or more languages to use for user interface |
| | 1326 | | /// strings. The list is in decreasing order of preference. For additional |
| | 1327 | | /// information, including expected format, see |
| | 1328 | | /// [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This |
| | 1329 | | /// header and the |
| | 1330 | | /// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) |
| | 1331 | | /// query parameter are mutually exclusive; do not specify both. If you set |
| | 1332 | | /// this header, you must also specify the |
| | 1333 | | /// [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) |
| | 1334 | | /// query parameter. To determine the market to return results for, Bing uses |
| | 1335 | | /// the first supported language it finds from the list and combines it with |
| | 1336 | | /// the cc parameter value. If the list does not include a supported language, |
| | 1337 | | /// Bing finds the closest language and market that supports the request or it |
| | 1338 | | /// uses an aggregated or default market for the results. To determine the |
| | 1339 | | /// market that Bing used, see the BingAPIs-Market header. Use this header and |
| | 1340 | | /// the cc query parameter only if you specify multiple languages. Otherwise, |
| | 1341 | | /// use the |
| | 1342 | | /// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) |
| | 1343 | | /// and |
| | 1344 | | /// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) |
| | 1345 | | /// query parameters. A user interface string is a string that's used as a |
| | 1346 | | /// label in a user interface. There are few user interface strings in the JSON |
| | 1347 | | /// response objects. Any links to Bing.com properties in the response objects |
| | 1348 | | /// apply the specified language. |
| | 1349 | | /// </param> |
| | 1350 | | /// <param name='userAgent'> |
| | 1351 | | /// The user agent originating the request. Bing uses the user agent to provide |
| | 1352 | | /// mobile users with an optimized experience. Although optional, you are |
| | 1353 | | /// encouraged to always specify this header. The user-agent should be the same |
| | 1354 | | /// string that any commonly used browser sends. For information about user |
| | 1355 | | /// agents, see [RFC |
| | 1356 | | /// 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The |
| | 1357 | | /// following are examples of user-agent strings. Windows Phone: Mozilla/5.0 |
| | 1358 | | /// (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; |
| | 1359 | | /// Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; |
| | 1360 | | /// en - us; SCH - I500 Build / GINGERBREAD) AppleWebKit / 533.1 (KHTML; like |
| | 1361 | | /// Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 5.0 (iPhone; |
| | 1362 | | /// CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) |
| | 1363 | | /// Mobile / 10B142 iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 |
| | 1364 | | /// (Windows NT 6.3; WOW64; Trident / 7.0; Touch; rv:11.0) like Gecko. iPad: |
| | 1365 | | /// Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 |
| | 1366 | | /// (KHTML, like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 |
| | 1367 | | /// </param> |
| | 1368 | | /// <param name='clientId'> |
| | 1369 | | /// Bing uses this header to provide users with consistent behavior across Bing |
| | 1370 | | /// API calls. Bing often flights new features and improvements, and it uses |
| | 1371 | | /// the client ID as a key for assigning traffic on different flights. If you |
| | 1372 | | /// do not use the same client ID for a user across multiple requests, then |
| | 1373 | | /// Bing may assign the user to multiple conflicting flights. Being assigned to |
| | 1374 | | /// multiple conflicting flights can lead to an inconsistent user experience. |
| | 1375 | | /// For example, if the second request has a different flight assignment than |
| | 1376 | | /// the first, the experience may be unexpected. Also, Bing can use the client |
| | 1377 | | /// ID to tailor web results to that client ID’s search history, providing a |
| | 1378 | | /// richer experience for the user. Bing also uses this header to help improve |
| | 1379 | | /// result rankings by analyzing the activity generated by a client ID. The |
| | 1380 | | /// relevance improvements help with better quality of results delivered by |
| | 1381 | | /// Bing APIs and in turn enables higher click-through rates for the API |
| | 1382 | | /// consumer. IMPORTANT: Although optional, you should consider this header |
| | 1383 | | /// required. Persisting the client ID across multiple requests for the same |
| | 1384 | | /// end user and device combination enables 1) the API consumer to receive a |
| | 1385 | | /// consistent user experience, and 2) higher click-through rates via better |
| | 1386 | | /// quality of results from the Bing APIs. Each user that uses your application |
| | 1387 | | /// on the device must have a unique, Bing generated client ID. If you do not |
| | 1388 | | /// include this header in the request, Bing generates an ID and returns it in |
| | 1389 | | /// the X-MSEdge-ClientID response header. The only time that you should NOT |
| | 1390 | | /// include this header in a request is the first time the user uses your app |
| | 1391 | | /// on that device. Use the client ID for each Bing API request that your app |
| | 1392 | | /// makes for this user on the device. Persist the client ID. To persist the ID |
| | 1393 | | /// in a browser app, use a persistent HTTP cookie to ensure the ID is used |
| | 1394 | | /// across all sessions. Do not use a session cookie. For other apps such as |
| | 1395 | | /// mobile apps, use the device's persistent storage to persist the ID. The |
| | 1396 | | /// next time the user uses your app on that device, get the client ID that you |
| | 1397 | | /// persisted. Bing responses may or may not include this header. If the |
| | 1398 | | /// response includes this header, capture the client ID and use it for all |
| | 1399 | | /// subsequent Bing requests for the user on that device. If you include the |
| | 1400 | | /// X-MSEdge-ClientID, you must not include cookies in the request. |
| | 1401 | | /// </param> |
| | 1402 | | /// <param name='clientIp'> |
| | 1403 | | /// The IPv4 or IPv6 address of the client device. The IP address is used to |
| | 1404 | | /// discover the user's location. Bing uses the location information to |
| | 1405 | | /// determine safe search behavior. Although optional, you are encouraged to |
| | 1406 | | /// always specify this header and the X-Search-Location header. Do not |
| | 1407 | | /// obfuscate the address (for example, by changing the last octet to 0). |
| | 1408 | | /// Obfuscating the address results in the location not being anywhere near the |
| | 1409 | | /// device's actual location, which may result in Bing serving erroneous |
| | 1410 | | /// results. |
| | 1411 | | /// </param> |
| | 1412 | | /// <param name='location'> |
| | 1413 | | /// A semicolon-delimited list of key/value pairs that describe the client's |
| | 1414 | | /// geographical location. Bing uses the location information to determine safe |
| | 1415 | | /// search behavior and to return relevant local content. Specify the key/value |
| | 1416 | | /// pair as <key>:<value>. The following are the keys that you use |
| | 1417 | | /// to specify the user's location. lat (required): The latitude of the |
| | 1418 | | /// client's location, in degrees. The latitude must be greater than or equal |
| | 1419 | | /// to -90.0 and less than or equal to +90.0. Negative values indicate southern |
| | 1420 | | /// latitudes and positive values indicate northern latitudes. long (required): |
| | 1421 | | /// The longitude of the client's location, in degrees. The longitude must be |
| | 1422 | | /// greater than or equal to -180.0 and less than or equal to +180.0. Negative |
| | 1423 | | /// values indicate western longitudes and positive values indicate eastern |
| | 1424 | | /// longitudes. re (required): The radius, in meters, which specifies the |
| | 1425 | | /// horizontal accuracy of the coordinates. Pass the value returned by the |
| | 1426 | | /// device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m |
| | 1427 | | /// for cell tower triangulation, and 18,000m for reverse IP lookup. ts |
| | 1428 | | /// (optional): The UTC UNIX timestamp of when the client was at the location. |
| | 1429 | | /// (The UNIX timestamp is the number of seconds since January 1, 1970.) head |
| | 1430 | | /// (optional): The client's relative heading or direction of travel. Specify |
| | 1431 | | /// the direction of travel as degrees from 0 through 360, counting clockwise |
| | 1432 | | /// relative to true north. Specify this key only if the sp key is nonzero. sp |
| | 1433 | | /// (optional): The horizontal velocity (speed), in meters per second, that the |
| | 1434 | | /// client device is traveling. alt (optional): The altitude of the client |
| | 1435 | | /// device, in meters. are (optional): The radius, in meters, that specifies |
| | 1436 | | /// the vertical accuracy of the coordinates. Specify this key only if you |
| | 1437 | | /// specify the alt key. Although many of the keys are optional, the more |
| | 1438 | | /// information that you provide, the more accurate the location results are. |
| | 1439 | | /// Although optional, you are encouraged to always specify the user's |
| | 1440 | | /// geographical location. Providing the location is especially important if |
| | 1441 | | /// the client's IP address does not accurately reflect the user's physical |
| | 1442 | | /// location (for example, if the client uses VPN). For optimal results, you |
| | 1443 | | /// should include this header and the X-MSEdge-ClientIP header, but at a |
| | 1444 | | /// minimum, you should include this header. |
| | 1445 | | /// </param> |
| | 1446 | | /// <param name='countryCode'> |
| | 1447 | | /// A 2-character country code of the country where the results come from. This |
| | 1448 | | /// API supports only the United States, Canada, Australia, and China markets. |
| | 1449 | | /// If you specify this query parameter, it must be set to us, ca, au, or cn. |
| | 1450 | | /// If you set this parameter, you must also specify the Accept-Language |
| | 1451 | | /// header. Bing uses the first supported language it finds from the languages |
| | 1452 | | /// list, and combine that language with the country code that you specify to |
| | 1453 | | /// determine the market to return results for. If the languages list does not |
| | 1454 | | /// include a supported language, Bing finds the closest language and market |
| | 1455 | | /// that supports the request, or it may use an aggregated or default market |
| | 1456 | | /// for the results instead of a specified one. You should use this query |
| | 1457 | | /// parameter and the Accept-Language query parameter only if you specify |
| | 1458 | | /// multiple languages; otherwise, you should use the mkt and setLang query |
| | 1459 | | /// parameters. This parameter and the mkt query parameter are mutually |
| | 1460 | | /// exclusive—do not specify both. |
| | 1461 | | /// </param> |
| | 1462 | | /// <param name='market'> |
| | 1463 | | /// The market where the results come from. Typically, mkt is the country where |
| | 1464 | | /// the user is making the request from. However, it could be a different |
| | 1465 | | /// country if the user is not located in a country where Bing delivers |
| | 1466 | | /// results. The market must be in the form <language code>-<country |
| | 1467 | | /// code>. For example, en-US. The string is case insensitive. For a list of |
| | 1468 | | /// possible market values, see [Market |
| | 1469 | | /// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes |
| | 1470 | | /// NOTE: If known, you are encouraged to always specify the market. Specifying |
| | 1471 | | /// the market helps Bing route the request and return an appropriate and |
| | 1472 | | /// optimal response. If you specify a market that is not listed in [Market |
| | 1473 | | /// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes |
| | 1474 | | /// Bing uses a best fit market code based on an internal mapping that is |
| | 1475 | | /// subject to change. This parameter and the |
| | 1476 | | /// [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) |
| | 1477 | | /// query parameter are mutually exclusive—do not specify both. |
| | 1478 | | /// </param> |
| | 1479 | | /// <param name='safeSearch'> |
| | 1480 | | /// Filter images for adult content. The following are the possible filter |
| | 1481 | | /// values. Off: May return images with adult content. If the request is |
| | 1482 | | /// through the Image Search API, the response includes thumbnail images that |
| | 1483 | | /// are clear (non-fuzzy). However, if the request is through the Web Search |
| | 1484 | | /// API, the response includes thumbnail images that are pixelated (fuzzy). |
| | 1485 | | /// Moderate: If the request is through the Image Search API, the response |
| | 1486 | | /// doesn't include images with adult content. If the request is through the |
| | 1487 | | /// Web Search API, the response may include images with adult content (the |
| | 1488 | | /// thumbnail images are pixelated (fuzzy)). Strict: Do not return images with |
| | 1489 | | /// adult content. The default is Moderate. If the request comes from a market |
| | 1490 | | /// that Bing's adult policy requires that safeSearch is set to Strict, Bing |
| | 1491 | | /// ignores the safeSearch value and uses Strict. If you use the site: query |
| | 1492 | | /// operator, there is the chance that the response may contain adult content |
| | 1493 | | /// regardless of what the safeSearch query parameter is set to. Use site: only |
| | 1494 | | /// if you are aware of the content on the site and your scenario supports the |
| | 1495 | | /// possibility of adult content. Possible values include: 'Off', 'Moderate', |
| | 1496 | | /// 'Strict' |
| | 1497 | | /// </param> |
| | 1498 | | /// <param name='setLang'> |
| | 1499 | | /// The language to use for user interface strings. Specify the language using |
| | 1500 | | /// the ISO 639-1 2-letter language code. For example, the language code for |
| | 1501 | | /// English is EN. The default is EN (English). Although optional, you should |
| | 1502 | | /// always specify the language. Typically, you set setLang to the same |
| | 1503 | | /// language specified by mkt unless the user wants the user interface strings |
| | 1504 | | /// displayed in a different language. This parameter and the |
| | 1505 | | /// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#a |
| | 1506 | | /// header are mutually exclusive; do not specify both. A user interface string |
| | 1507 | | /// is a string that's used as a label in a user interface. There are few user |
| | 1508 | | /// interface strings in the JSON response objects. Also, any links to Bing.com |
| | 1509 | | /// properties in the response objects apply the specified language. |
| | 1510 | | /// </param> |
| | 1511 | | /// <param name='customHeaders'> |
| | 1512 | | /// Headers that will be added to request. |
| | 1513 | | /// </param> |
| | 1514 | | /// <param name='cancellationToken'> |
| | 1515 | | /// The cancellation token. |
| | 1516 | | /// </param> |
| | 1517 | | /// <exception cref="ErrorResponseException"> |
| | 1518 | | /// Thrown when the operation returned an invalid status code |
| | 1519 | | /// </exception> |
| | 1520 | | /// <exception cref="SerializationException"> |
| | 1521 | | /// Thrown when unable to deserialize the response |
| | 1522 | | /// </exception> |
| | 1523 | | /// <exception cref="ValidationException"> |
| | 1524 | | /// Thrown when a required parameter is null |
| | 1525 | | /// </exception> |
| | 1526 | | /// <exception cref="System.ArgumentNullException"> |
| | 1527 | | /// Thrown when a required parameter is null |
| | 1528 | | /// </exception> |
| | 1529 | | /// <return> |
| | 1530 | | /// A response object containing the response body and response headers. |
| | 1531 | | /// </return> |
| | 1532 | | public async Task<HttpOperationResponse<TrendingImages>> TrendingWithHttpMessagesAsync(string acceptLanguage = d |
| | 1533 | | { |
| 2 | 1534 | | if (Client.Endpoint == null) |
| | 1535 | | { |
| 0 | 1536 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1537 | | } |
| 2 | 1538 | | string xBingApisSDK = "true"; |
| | 1539 | | // Tracing |
| 2 | 1540 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1541 | | string _invocationId = null; |
| 2 | 1542 | | if (_shouldTrace) |
| | 1543 | | { |
| 0 | 1544 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1545 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1546 | | tracingParameters.Add("xBingApisSDK", xBingApisSDK); |
| 0 | 1547 | | tracingParameters.Add("acceptLanguage", acceptLanguage); |
| 0 | 1548 | | tracingParameters.Add("userAgent", userAgent); |
| 0 | 1549 | | tracingParameters.Add("clientId", clientId); |
| 0 | 1550 | | tracingParameters.Add("clientIp", clientIp); |
| 0 | 1551 | | tracingParameters.Add("location", location); |
| 0 | 1552 | | tracingParameters.Add("countryCode", countryCode); |
| 0 | 1553 | | tracingParameters.Add("market", market); |
| 0 | 1554 | | tracingParameters.Add("safeSearch", safeSearch); |
| 0 | 1555 | | tracingParameters.Add("setLang", setLang); |
| 0 | 1556 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1557 | | ServiceClientTracing.Enter(_invocationId, this, "Trending", tracingParameters); |
| | 1558 | | } |
| | 1559 | | // Construct URL |
| 2 | 1560 | | var _baseUrl = Client.BaseUri; |
| 2 | 1561 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "images/trending"; |
| 2 | 1562 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 1563 | | List<string> _queryParameters = new List<string>(); |
| 2 | 1564 | | if (countryCode != null) |
| | 1565 | | { |
| 0 | 1566 | | _queryParameters.Add(string.Format("cc={0}", System.Uri.EscapeDataString(countryCode))); |
| | 1567 | | } |
| 2 | 1568 | | if (market != null) |
| | 1569 | | { |
| 0 | 1570 | | _queryParameters.Add(string.Format("mkt={0}", System.Uri.EscapeDataString(market))); |
| | 1571 | | } |
| 2 | 1572 | | if (safeSearch != null) |
| | 1573 | | { |
| 0 | 1574 | | _queryParameters.Add(string.Format("safeSearch={0}", System.Uri.EscapeDataString(safeSearch))); |
| | 1575 | | } |
| 2 | 1576 | | if (setLang != null) |
| | 1577 | | { |
| 0 | 1578 | | _queryParameters.Add(string.Format("setLang={0}", System.Uri.EscapeDataString(setLang))); |
| | 1579 | | } |
| 2 | 1580 | | if (_queryParameters.Count > 0) |
| | 1581 | | { |
| 0 | 1582 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1583 | | } |
| | 1584 | | // Create HTTP transport objects |
| 2 | 1585 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1586 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1587 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 1588 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1589 | | // Set Headers |
| 2 | 1590 | | if (xBingApisSDK != null) |
| | 1591 | | { |
| 2 | 1592 | | if (_httpRequest.Headers.Contains("X-BingApis-SDK")) |
| | 1593 | | { |
| 0 | 1594 | | _httpRequest.Headers.Remove("X-BingApis-SDK"); |
| | 1595 | | } |
| 2 | 1596 | | _httpRequest.Headers.TryAddWithoutValidation("X-BingApis-SDK", xBingApisSDK); |
| | 1597 | | } |
| 2 | 1598 | | if (acceptLanguage != null) |
| | 1599 | | { |
| 0 | 1600 | | if (_httpRequest.Headers.Contains("Accept-Language")) |
| | 1601 | | { |
| 0 | 1602 | | _httpRequest.Headers.Remove("Accept-Language"); |
| | 1603 | | } |
| 0 | 1604 | | _httpRequest.Headers.TryAddWithoutValidation("Accept-Language", acceptLanguage); |
| | 1605 | | } |
| 2 | 1606 | | if (userAgent != null) |
| | 1607 | | { |
| 0 | 1608 | | if (_httpRequest.Headers.Contains("User-Agent")) |
| | 1609 | | { |
| 0 | 1610 | | _httpRequest.Headers.Remove("User-Agent"); |
| | 1611 | | } |
| 0 | 1612 | | _httpRequest.Headers.TryAddWithoutValidation("User-Agent", userAgent); |
| | 1613 | | } |
| 2 | 1614 | | if (clientId != null) |
| | 1615 | | { |
| 0 | 1616 | | if (_httpRequest.Headers.Contains("X-MSEdge-ClientID")) |
| | 1617 | | { |
| 0 | 1618 | | _httpRequest.Headers.Remove("X-MSEdge-ClientID"); |
| | 1619 | | } |
| 0 | 1620 | | _httpRequest.Headers.TryAddWithoutValidation("X-MSEdge-ClientID", clientId); |
| | 1621 | | } |
| 2 | 1622 | | if (clientIp != null) |
| | 1623 | | { |
| 0 | 1624 | | if (_httpRequest.Headers.Contains("X-MSEdge-ClientIP")) |
| | 1625 | | { |
| 0 | 1626 | | _httpRequest.Headers.Remove("X-MSEdge-ClientIP"); |
| | 1627 | | } |
| 0 | 1628 | | _httpRequest.Headers.TryAddWithoutValidation("X-MSEdge-ClientIP", clientIp); |
| | 1629 | | } |
| 2 | 1630 | | if (location != null) |
| | 1631 | | { |
| 0 | 1632 | | if (_httpRequest.Headers.Contains("X-Search-Location")) |
| | 1633 | | { |
| 0 | 1634 | | _httpRequest.Headers.Remove("X-Search-Location"); |
| | 1635 | | } |
| 0 | 1636 | | _httpRequest.Headers.TryAddWithoutValidation("X-Search-Location", location); |
| | 1637 | | } |
| | 1638 | |
|
| | 1639 | |
|
| 2 | 1640 | | if (customHeaders != null) |
| | 1641 | | { |
| 0 | 1642 | | foreach(var _header in customHeaders) |
| | 1643 | | { |
| 0 | 1644 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1645 | | { |
| 0 | 1646 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1647 | | } |
| 0 | 1648 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1649 | | } |
| | 1650 | | } |
| | 1651 | |
|
| | 1652 | | // Serialize Request |
| 2 | 1653 | | string _requestContent = null; |
| | 1654 | | // Set Credentials |
| 2 | 1655 | | if (Client.Credentials != null) |
| | 1656 | | { |
| 2 | 1657 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1658 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1659 | | } |
| | 1660 | | // Send Request |
| 2 | 1661 | | if (_shouldTrace) |
| | 1662 | | { |
| 0 | 1663 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1664 | | } |
| 2 | 1665 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1666 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 1667 | | if (_shouldTrace) |
| | 1668 | | { |
| 0 | 1669 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1670 | | } |
| 2 | 1671 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 1672 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1673 | | string _responseContent = null; |
| 2 | 1674 | | if ((int)_statusCode != 200) |
| | 1675 | | { |
| 0 | 1676 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1677 | | try |
| | 1678 | | { |
| 0 | 1679 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1680 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1681 | | if (_errorBody != null) |
| | 1682 | | { |
| 0 | 1683 | | ex.Body = _errorBody; |
| | 1684 | | } |
| 0 | 1685 | | } |
| 0 | 1686 | | catch (JsonException) |
| | 1687 | | { |
| | 1688 | | // Ignore the exception |
| 0 | 1689 | | } |
| 0 | 1690 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1691 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1692 | | if (_shouldTrace) |
| | 1693 | | { |
| 0 | 1694 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1695 | | } |
| 0 | 1696 | | _httpRequest.Dispose(); |
| 0 | 1697 | | if (_httpResponse != null) |
| | 1698 | | { |
| 0 | 1699 | | _httpResponse.Dispose(); |
| | 1700 | | } |
| 0 | 1701 | | throw ex; |
| | 1702 | | } |
| | 1703 | | // Create Result |
| 2 | 1704 | | var _result = new HttpOperationResponse<TrendingImages>(); |
| 2 | 1705 | | _result.Request = _httpRequest; |
| 2 | 1706 | | _result.Response = _httpResponse; |
| | 1707 | | // Deserialize Response |
| 2 | 1708 | | if ((int)_statusCode == 200) |
| | 1709 | | { |
| 2 | 1710 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1711 | | try |
| | 1712 | | { |
| 2 | 1713 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<TrendingImages>(_responseContent |
| 2 | 1714 | | } |
| 0 | 1715 | | catch (JsonException ex) |
| | 1716 | | { |
| 0 | 1717 | | _httpRequest.Dispose(); |
| 0 | 1718 | | if (_httpResponse != null) |
| | 1719 | | { |
| 0 | 1720 | | _httpResponse.Dispose(); |
| | 1721 | | } |
| 0 | 1722 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1723 | | } |
| | 1724 | | } |
| 2 | 1725 | | if (_shouldTrace) |
| | 1726 | | { |
| 0 | 1727 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1728 | | } |
| 2 | 1729 | | return _result; |
| 2 | 1730 | | } |
| | 1731 | |
|
| | 1732 | | } |
| | 1733 | | } |