| | 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.Language.SpellCheck |
| | 8 | | { |
| | 9 | | using Microsoft.Rest; |
| | 10 | | using Microsoft.Rest.Serialization; |
| | 11 | | using Models; |
| | 12 | | using Newtonsoft.Json; |
| | 13 | | using System.Collections; |
| | 14 | | using System.Collections.Generic; |
| | 15 | | using System.Net; |
| | 16 | | using System.Net.Http; |
| | 17 | | using System.Threading; |
| | 18 | | using System.Threading.Tasks; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// The Spell Check API - V7 lets you check a text string for spelling and |
| | 22 | | /// grammar errors. |
| | 23 | | /// </summary> |
| | 24 | | public partial class SpellCheckClient : ServiceClient<SpellCheckClient>, ISpellCheckClient |
| | 25 | | { |
| | 26 | | /// <summary> |
| | 27 | | /// The base URI of the service. |
| | 28 | | /// </summary> |
| 2 | 29 | | internal string BaseUri {get; set;} |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// Gets or sets json serialization settings. |
| | 33 | | /// </summary> |
| 2 | 34 | | public JsonSerializerSettings SerializationSettings { get; private set; } |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Gets or sets json deserialization settings. |
| | 38 | | /// </summary> |
| 3 | 39 | | public JsonSerializerSettings DeserializationSettings { get; private set; } |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Supported Cognitive Services endpoints (protocol and hostname, for example: |
| | 43 | | /// "https://westus.api.cognitive.microsoft.com", |
| | 44 | | /// "https://api.cognitive.microsoft.com"). |
| | 45 | | /// </summary> |
| 3 | 46 | | public string Endpoint { get; set; } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Subscription credentials which uniquely identify client subscription. |
| | 50 | | /// </summary> |
| 5 | 51 | | public ServiceClientCredentials Credentials { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Initializes a new instance of the SpellCheckClient class. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='httpClient'> |
| | 57 | | /// HttpClient to be used |
| | 58 | | /// </param> |
| | 59 | | /// <param name='disposeHttpClient'> |
| | 60 | | /// True: will dispose the provided httpClient on calling SpellCheckClient.Dispose(). False: will not dispose pr |
| 0 | 61 | | protected SpellCheckClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClient) |
| | 62 | | { |
| 0 | 63 | | Initialize(); |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// Initializes a new instance of the SpellCheckClient class. |
| | 68 | | /// </summary> |
| | 69 | | /// <param name='handlers'> |
| | 70 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 71 | | /// </param> |
| 1 | 72 | | protected SpellCheckClient(params DelegatingHandler[] handlers) : base(handlers) |
| | 73 | | { |
| 1 | 74 | | Initialize(); |
| 1 | 75 | | } |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Initializes a new instance of the SpellCheckClient class. |
| | 79 | | /// </summary> |
| | 80 | | /// <param name='rootHandler'> |
| | 81 | | /// Optional. The http client handler used to handle http transport. |
| | 82 | | /// </param> |
| | 83 | | /// <param name='handlers'> |
| | 84 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 85 | | /// </param> |
| 0 | 86 | | protected SpellCheckClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandle |
| | 87 | | { |
| 0 | 88 | | Initialize(); |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | /// <summary> |
| | 92 | | /// Initializes a new instance of the SpellCheckClient class. |
| | 93 | | /// </summary> |
| | 94 | | /// <param name='credentials'> |
| | 95 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 96 | | /// </param> |
| | 97 | | /// <param name='handlers'> |
| | 98 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 99 | | /// </param> |
| | 100 | | /// <exception cref="System.ArgumentNullException"> |
| | 101 | | /// Thrown when a required parameter is null |
| | 102 | | /// </exception> |
| 1 | 103 | | public SpellCheckClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handle |
| | 104 | | { |
| 1 | 105 | | if (credentials == null) |
| | 106 | | { |
| 0 | 107 | | throw new System.ArgumentNullException("credentials"); |
| | 108 | | } |
| 1 | 109 | | Credentials = credentials; |
| 1 | 110 | | if (Credentials != null) |
| | 111 | | { |
| 1 | 112 | | Credentials.InitializeServiceClient(this); |
| | 113 | | } |
| 1 | 114 | | } |
| | 115 | |
|
| | 116 | | /// <summary> |
| | 117 | | /// Initializes a new instance of the SpellCheckClient class. |
| | 118 | | /// </summary> |
| | 119 | | /// <param name='credentials'> |
| | 120 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 121 | | /// </param> |
| | 122 | | /// <param name='httpClient'> |
| | 123 | | /// HttpClient to be used |
| | 124 | | /// </param> |
| | 125 | | /// <param name='disposeHttpClient'> |
| | 126 | | /// True: will dispose the provided httpClient on calling SpellCheckClient.Dispose(). False: will not dispose pr |
| | 127 | | /// <exception cref="System.ArgumentNullException"> |
| | 128 | | /// Thrown when a required parameter is null |
| | 129 | | /// </exception> |
| 0 | 130 | | public SpellCheckClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) : t |
| | 131 | | { |
| 0 | 132 | | if (credentials == null) |
| | 133 | | { |
| 0 | 134 | | throw new System.ArgumentNullException("credentials"); |
| | 135 | | } |
| 0 | 136 | | Credentials = credentials; |
| 0 | 137 | | if (Credentials != null) |
| | 138 | | { |
| 0 | 139 | | Credentials.InitializeServiceClient(this); |
| | 140 | | } |
| 0 | 141 | | } |
| | 142 | |
|
| | 143 | | /// <summary> |
| | 144 | | /// Initializes a new instance of the SpellCheckClient class. |
| | 145 | | /// </summary> |
| | 146 | | /// <param name='credentials'> |
| | 147 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 148 | | /// </param> |
| | 149 | | /// <param name='rootHandler'> |
| | 150 | | /// Optional. The http client handler used to handle http transport. |
| | 151 | | /// </param> |
| | 152 | | /// <param name='handlers'> |
| | 153 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 154 | | /// </param> |
| | 155 | | /// <exception cref="System.ArgumentNullException"> |
| | 156 | | /// Thrown when a required parameter is null |
| | 157 | | /// </exception> |
| 0 | 158 | | public SpellCheckClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHa |
| | 159 | | { |
| 0 | 160 | | if (credentials == null) |
| | 161 | | { |
| 0 | 162 | | throw new System.ArgumentNullException("credentials"); |
| | 163 | | } |
| 0 | 164 | | Credentials = credentials; |
| 0 | 165 | | if (Credentials != null) |
| | 166 | | { |
| 0 | 167 | | Credentials.InitializeServiceClient(this); |
| | 168 | | } |
| 0 | 169 | | } |
| | 170 | |
|
| | 171 | | /// <summary> |
| | 172 | | /// An optional partial-method to perform custom initialization. |
| | 173 | | ///</summary> |
| | 174 | | partial void CustomInitialize(); |
| | 175 | | /// <summary> |
| | 176 | | /// Initializes client properties. |
| | 177 | | /// </summary> |
| | 178 | | private void Initialize() |
| | 179 | | { |
| 1 | 180 | | BaseUri = "{Endpoint}/bing/v7.0"; |
| 1 | 181 | | Endpoint = "https://api.cognitive.microsoft.com"; |
| 1 | 182 | | SerializationSettings = new JsonSerializerSettings |
| 1 | 183 | | { |
| 1 | 184 | | Formatting = Newtonsoft.Json.Formatting.Indented, |
| 1 | 185 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 1 | 186 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 1 | 187 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 1 | 188 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 1 | 189 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 1 | 190 | | Converters = new List<JsonConverter> |
| 1 | 191 | | { |
| 1 | 192 | | new Iso8601TimeSpanConverter() |
| 1 | 193 | | } |
| 1 | 194 | | }; |
| 1 | 195 | | DeserializationSettings = new JsonSerializerSettings |
| 1 | 196 | | { |
| 1 | 197 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 1 | 198 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 1 | 199 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 1 | 200 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 1 | 201 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 1 | 202 | | Converters = new List<JsonConverter> |
| 1 | 203 | | { |
| 1 | 204 | | new Iso8601TimeSpanConverter() |
| 1 | 205 | | } |
| 1 | 206 | | }; |
| 1 | 207 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<ResponseBase>("_type")); |
| 1 | 208 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<ResponseBase>("_type")); |
| | 209 | | CustomInitialize(); |
| 1 | 210 | | } |
| | 211 | | /// <summary> |
| | 212 | | /// The Bing Spell Check API lets you perform contextual grammar and spell |
| | 213 | | /// checking. Bing has developed a web-based spell-checker that leverages |
| | 214 | | /// machine learning and statistical machine translation to dynamically train a |
| | 215 | | /// constantly evolving and highly contextual algorithm. The spell-checker is |
| | 216 | | /// based on a massive corpus of web searches and documents. |
| | 217 | | /// </summary> |
| | 218 | | /// <param name='text'> |
| | 219 | | /// The text string to check for spelling and grammar errors. The combined |
| | 220 | | /// length of the text string, preContextText string, and postContextText |
| | 221 | | /// string may not exceed 10,000 characters. You may specify this parameter in |
| | 222 | | /// the query string of a GET request or in the body of a POST request. Because |
| | 223 | | /// of the query string length limit, you'll typically use a POST request |
| | 224 | | /// unless you're checking only short strings. |
| | 225 | | /// </param> |
| | 226 | | /// <param name='acceptLanguage'> |
| | 227 | | /// A comma-delimited list of one or more languages to use for user interface |
| | 228 | | /// strings. The list is in decreasing order of preference. For additional |
| | 229 | | /// information, including expected format, see |
| | 230 | | /// [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This |
| | 231 | | /// header and the setLang query parameter are mutually exclusive; do not |
| | 232 | | /// specify both. If you set this header, you must also specify the cc query |
| | 233 | | /// parameter. Bing will use the first supported language it finds from the |
| | 234 | | /// list, and combine that language with the cc parameter value to determine |
| | 235 | | /// the market to return results for. If the list does not include a supported |
| | 236 | | /// language, Bing will find the closest language and market that supports the |
| | 237 | | /// request, and may use an aggregated or default market for the results |
| | 238 | | /// instead of a specified one. You should use this header and the cc query |
| | 239 | | /// parameter only if you specify multiple languages; otherwise, you should use |
| | 240 | | /// the mkt and setLang query parameters. A user interface string is a string |
| | 241 | | /// that's used as a label in a user interface. There are very few user |
| | 242 | | /// interface strings in the JSON response objects. Any links in the response |
| | 243 | | /// objects to Bing.com properties will apply the specified language. |
| | 244 | | /// </param> |
| | 245 | | /// <param name='pragma'> |
| | 246 | | /// By default, Bing returns cached content, if available. To prevent Bing from |
| | 247 | | /// returning cached content, set the Pragma header to no-cache (for example, |
| | 248 | | /// Pragma: no-cache). |
| | 249 | | /// </param> |
| | 250 | | /// <param name='userAgent'> |
| | 251 | | /// The user agent originating the request. Bing uses the user agent to provide |
| | 252 | | /// mobile users with an optimized experience. Although optional, you are |
| | 253 | | /// strongly encouraged to always specify this header. The user-agent should be |
| | 254 | | /// the same string that any commonly used browser would send. For information |
| | 255 | | /// about user agents, see [RFC |
| | 256 | | /// 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). |
| | 257 | | /// </param> |
| | 258 | | /// <param name='clientId'> |
| | 259 | | /// Bing uses this header to provide users with consistent behavior across Bing |
| | 260 | | /// API calls. Bing often flights new features and improvements, and it uses |
| | 261 | | /// the client ID as a key for assigning traffic on different flights. If you |
| | 262 | | /// do not use the same client ID for a user across multiple requests, then |
| | 263 | | /// Bing may assign the user to multiple conflicting flights. Being assigned to |
| | 264 | | /// multiple conflicting flights can lead to an inconsistent user experience. |
| | 265 | | /// For example, if the second request has a different flight assignment than |
| | 266 | | /// the first, the experience may be unexpected. Also, Bing can use the client |
| | 267 | | /// ID to tailor web results to that client ID’s search history, providing a |
| | 268 | | /// richer experience for the user. Bing also uses this header to help improve |
| | 269 | | /// result rankings by analyzing the activity generated by a client ID. The |
| | 270 | | /// relevance improvements help with better quality of results delivered by |
| | 271 | | /// Bing APIs and in turn enables higher click-through rates for the API |
| | 272 | | /// consumer. IMPORTANT: Although optional, you should consider this header |
| | 273 | | /// required. Persisting the client ID across multiple requests for the same |
| | 274 | | /// end user and device combination enables 1) the API consumer to receive a |
| | 275 | | /// consistent user experience, and 2) higher click-through rates via better |
| | 276 | | /// quality of results from the Bing APIs. Each user that uses your application |
| | 277 | | /// on the device must have a unique, Bing generated client ID. If you do not |
| | 278 | | /// include this header in the request, Bing generates an ID and returns it in |
| | 279 | | /// the X-MSEdge-ClientID response header. The only time that you should NOT |
| | 280 | | /// include this header in a request is the first time the user uses your app |
| | 281 | | /// on that device. Use the client ID for each Bing API request that your app |
| | 282 | | /// makes for this user on the device. Persist the client ID. To persist the ID |
| | 283 | | /// in a browser app, use a persistent HTTP cookie to ensure the ID is used |
| | 284 | | /// across all sessions. Do not use a session cookie. For other apps such as |
| | 285 | | /// mobile apps, use the device's persistent storage to persist the ID. The |
| | 286 | | /// next time the user uses your app on that device, get the client ID that you |
| | 287 | | /// persisted. Bing responses may or may not include this header. If the |
| | 288 | | /// response includes this header, capture the client ID and use it for all |
| | 289 | | /// subsequent Bing requests for the user on that device. If you include the |
| | 290 | | /// X-MSEdge-ClientID, you must not include cookies in the request. |
| | 291 | | /// </param> |
| | 292 | | /// <param name='clientIp'> |
| | 293 | | /// The IPv4 or IPv6 address of the client device. The IP address is used to |
| | 294 | | /// discover the user's location. Bing uses the location information to |
| | 295 | | /// determine safe search behavior. Although optional, you are encouraged to |
| | 296 | | /// always specify this header and the X-Search-Location header. Do not |
| | 297 | | /// obfuscate the address (for example, by changing the last octet to 0). |
| | 298 | | /// Obfuscating the address results in the location not being anywhere near the |
| | 299 | | /// device's actual location, which may result in Bing serving erroneous |
| | 300 | | /// results. |
| | 301 | | /// </param> |
| | 302 | | /// <param name='location'> |
| | 303 | | /// A semicolon-delimited list of key/value pairs that describe the client's |
| | 304 | | /// geographical location. Bing uses the location information to determine safe |
| | 305 | | /// search behavior and to return relevant local content. Specify the key/value |
| | 306 | | /// pair as <key>:<value>. The following are the keys that you use |
| | 307 | | /// to specify the user's location. lat (required): The latitude of the |
| | 308 | | /// client's location, in degrees. The latitude must be greater than or equal |
| | 309 | | /// to -90.0 and less than or equal to +90.0. Negative values indicate southern |
| | 310 | | /// latitudes and positive values indicate northern latitudes. long (required): |
| | 311 | | /// The longitude of the client's location, in degrees. The longitude must be |
| | 312 | | /// greater than or equal to -180.0 and less than or equal to +180.0. Negative |
| | 313 | | /// values indicate western longitudes and positive values indicate eastern |
| | 314 | | /// longitudes. re (required): The radius, in meters, which specifies the |
| | 315 | | /// horizontal accuracy of the coordinates. Pass the value returned by the |
| | 316 | | /// device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m |
| | 317 | | /// for cell tower triangulation, and 18,000m for reverse IP lookup. ts |
| | 318 | | /// (optional): The UTC UNIX timestamp of when the client was at the location. |
| | 319 | | /// (The UNIX timestamp is the number of seconds since January 1, 1970.) head |
| | 320 | | /// (optional): The client's relative heading or direction of travel. Specify |
| | 321 | | /// the direction of travel as degrees from 0 through 360, counting clockwise |
| | 322 | | /// relative to true north. Specify this key only if the sp key is nonzero. sp |
| | 323 | | /// (optional): The horizontal velocity (speed), in meters per second, that the |
| | 324 | | /// client device is traveling. alt (optional): The altitude of the client |
| | 325 | | /// device, in meters. are (optional): The radius, in meters, that specifies |
| | 326 | | /// the vertical accuracy of the coordinates. Specify this key only if you |
| | 327 | | /// specify the alt key. Although many of the keys are optional, the more |
| | 328 | | /// information that you provide, the more accurate the location results are. |
| | 329 | | /// Although optional, you are encouraged to always specify the user's |
| | 330 | | /// geographical location. Providing the location is especially important if |
| | 331 | | /// the client's IP address does not accurately reflect the user's physical |
| | 332 | | /// location (for example, if the client uses VPN). For optimal results, you |
| | 333 | | /// should include this header and the X-Search-ClientIP header, but at a |
| | 334 | | /// minimum, you should include this header. |
| | 335 | | /// </param> |
| | 336 | | /// <param name='actionType'> |
| | 337 | | /// A string that's used by logging to determine whether the request is coming |
| | 338 | | /// from an interactive session or a page load. The following are the possible |
| | 339 | | /// values. 1) Edit—The request is from an interactive session 2) Load—The |
| | 340 | | /// request is from a page load. Possible values include: 'Edit', 'Load' |
| | 341 | | /// </param> |
| | 342 | | /// <param name='appName'> |
| | 343 | | /// The unique name of your app. The name must be known by Bing. Do not include |
| | 344 | | /// this parameter unless you have previously contacted Bing to get a unique |
| | 345 | | /// app name. To get a unique name, contact your Bing Business Development |
| | 346 | | /// manager. |
| | 347 | | /// </param> |
| | 348 | | /// <param name='countryCode'> |
| | 349 | | /// A 2-character country code of the country where the results come from. This |
| | 350 | | /// API supports only the United States market. If you specify this query |
| | 351 | | /// parameter, it must be set to us. If you set this parameter, you must also |
| | 352 | | /// specify the Accept-Language header. Bing uses the first supported language |
| | 353 | | /// it finds from the languages list, and combine that language with the |
| | 354 | | /// country code that you specify to determine the market to return results |
| | 355 | | /// for. If the languages list does not include a supported language, Bing |
| | 356 | | /// finds the closest language and market that supports the request, or it may |
| | 357 | | /// use an aggregated or default market for the results instead of a specified |
| | 358 | | /// one. You should use this query parameter and the Accept-Language query |
| | 359 | | /// parameter only if you specify multiple languages; otherwise, you should use |
| | 360 | | /// the mkt and setLang query parameters. This parameter and the mkt query |
| | 361 | | /// parameter are mutually exclusive—do not specify both. |
| | 362 | | /// </param> |
| | 363 | | /// <param name='clientMachineName'> |
| | 364 | | /// A unique name of the device that the request is being made from. Generate a |
| | 365 | | /// unique value for each device (the value is unimportant). The service uses |
| | 366 | | /// the ID to help debug issues and improve the quality of corrections. |
| | 367 | | /// </param> |
| | 368 | | /// <param name='docId'> |
| | 369 | | /// A unique ID that identifies the document that the text belongs to. Generate |
| | 370 | | /// a unique value for each document (the value is unimportant). The service |
| | 371 | | /// uses the ID to help debug issues and improve the quality of corrections. |
| | 372 | | /// </param> |
| | 373 | | /// <param name='market'> |
| | 374 | | /// The market where the results come from. You are strongly encouraged to |
| | 375 | | /// always specify the market, if known. Specifying the market helps Bing route |
| | 376 | | /// the request and return an appropriate and optimal response. This parameter |
| | 377 | | /// and the cc query parameter are mutually exclusive—do not specify both. |
| | 378 | | /// </param> |
| | 379 | | /// <param name='sessionId'> |
| | 380 | | /// A unique ID that identifies this user session. Generate a unique value for |
| | 381 | | /// each user session (the value is unimportant). The service uses the ID to |
| | 382 | | /// help debug issues and improve the quality of corrections |
| | 383 | | /// </param> |
| | 384 | | /// <param name='setLang'> |
| | 385 | | /// The language to use for user interface strings. Specify the language using |
| | 386 | | /// the ISO 639-1 2-letter language code. For example, the language code for |
| | 387 | | /// English is EN. The default is EN (English). Although optional, you should |
| | 388 | | /// always specify the language. Typically, you set setLang to the same |
| | 389 | | /// language specified by mkt unless the user wants the user interface strings |
| | 390 | | /// displayed in a different language. This parameter and the Accept-Language |
| | 391 | | /// header are mutually exclusive—do not specify both. A user interface string |
| | 392 | | /// is a string that's used as a label in a user interface. There are few user |
| | 393 | | /// interface strings in the JSON response objects. Also, any links to Bing.com |
| | 394 | | /// properties in the response objects apply the specified language. |
| | 395 | | /// </param> |
| | 396 | | /// <param name='userId'> |
| | 397 | | /// A unique ID that identifies the user. Generate a unique value for each user |
| | 398 | | /// (the value is unimportant). The service uses the ID to help debug issues |
| | 399 | | /// and improve the quality of corrections. |
| | 400 | | /// </param> |
| | 401 | | /// <param name='mode'> |
| | 402 | | /// The type of spelling and grammar checks to perform. The following are the |
| | 403 | | /// possible values (the values are case insensitive). The default is Proof. 1) |
| | 404 | | /// Proof—Finds most spelling and grammar mistakes. 2) Spell—Finds most |
| | 405 | | /// spelling mistakes but does not find some of the grammar errors that Proof |
| | 406 | | /// catches (for example, capitalization and repeated words). Possible values |
| | 407 | | /// include: 'proof', 'spell' |
| | 408 | | /// </param> |
| | 409 | | /// <param name='preContextText'> |
| | 410 | | /// A string that gives context to the text string. For example, the text |
| | 411 | | /// string petal is valid. However, if you set preContextText to bike, the |
| | 412 | | /// context changes and the text string becomes not valid. In this case, the |
| | 413 | | /// API suggests that you change petal to pedal (as in bike pedal). This text |
| | 414 | | /// is not checked for grammar or spelling errors. The combined length of the |
| | 415 | | /// text string, preContextText string, and postContextText string may not |
| | 416 | | /// exceed 10,000 characters. You may specify this parameter in the query |
| | 417 | | /// string of a GET request or in the body of a POST request. |
| | 418 | | /// </param> |
| | 419 | | /// <param name='postContextText'> |
| | 420 | | /// A string that gives context to the text string. For example, the text |
| | 421 | | /// string read is valid. However, if you set postContextText to carpet, the |
| | 422 | | /// context changes and the text string becomes not valid. In this case, the |
| | 423 | | /// API suggests that you change read to red (as in red carpet). This text is |
| | 424 | | /// not checked for grammar or spelling errors. The combined length of the text |
| | 425 | | /// string, preContextText string, and postContextText string may not exceed |
| | 426 | | /// 10,000 characters. You may specify this parameter in the query string of a |
| | 427 | | /// GET request or in the body of a POST request. |
| | 428 | | /// </param> |
| | 429 | | /// <param name='customHeaders'> |
| | 430 | | /// Headers that will be added to request. |
| | 431 | | /// </param> |
| | 432 | | /// <param name='cancellationToken'> |
| | 433 | | /// The cancellation token. |
| | 434 | | /// </param> |
| | 435 | | /// <exception cref="ErrorResponseException"> |
| | 436 | | /// Thrown when the operation returned an invalid status code |
| | 437 | | /// </exception> |
| | 438 | | /// <exception cref="SerializationException"> |
| | 439 | | /// Thrown when unable to deserialize the response |
| | 440 | | /// </exception> |
| | 441 | | /// <exception cref="ValidationException"> |
| | 442 | | /// Thrown when a required parameter is null |
| | 443 | | /// </exception> |
| | 444 | | /// <exception cref="System.ArgumentNullException"> |
| | 445 | | /// Thrown when a required parameter is null |
| | 446 | | /// </exception> |
| | 447 | | /// <return> |
| | 448 | | /// A response object containing the response body and response headers. |
| | 449 | | /// </return> |
| | 450 | | public async Task<HttpOperationResponse<SpellCheckModel>> SpellCheckerWithHttpMessagesAsync(string text, string |
| | 451 | | { |
| 1 | 452 | | if (Endpoint == null) |
| | 453 | | { |
| 0 | 454 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 455 | | } |
| 1 | 456 | | if (text == null) |
| | 457 | | { |
| 0 | 458 | | throw new ValidationException(ValidationRules.CannotBeNull, "text"); |
| | 459 | | } |
| 1 | 460 | | string xBingApisSDK = "true"; |
| | 461 | | // Tracing |
| 1 | 462 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 463 | | string _invocationId = null; |
| 1 | 464 | | if (_shouldTrace) |
| | 465 | | { |
| 0 | 466 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 467 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 468 | | tracingParameters.Add("xBingApisSDK", xBingApisSDK); |
| 0 | 469 | | tracingParameters.Add("acceptLanguage", acceptLanguage); |
| 0 | 470 | | tracingParameters.Add("pragma", pragma); |
| 0 | 471 | | tracingParameters.Add("userAgent", userAgent); |
| 0 | 472 | | tracingParameters.Add("clientId", clientId); |
| 0 | 473 | | tracingParameters.Add("clientIp", clientIp); |
| 0 | 474 | | tracingParameters.Add("location", location); |
| 0 | 475 | | tracingParameters.Add("actionType", actionType); |
| 0 | 476 | | tracingParameters.Add("appName", appName); |
| 0 | 477 | | tracingParameters.Add("countryCode", countryCode); |
| 0 | 478 | | tracingParameters.Add("clientMachineName", clientMachineName); |
| 0 | 479 | | tracingParameters.Add("docId", docId); |
| 0 | 480 | | tracingParameters.Add("market", market); |
| 0 | 481 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 482 | | tracingParameters.Add("setLang", setLang); |
| 0 | 483 | | tracingParameters.Add("userId", userId); |
| 0 | 484 | | tracingParameters.Add("mode", mode); |
| 0 | 485 | | tracingParameters.Add("preContextText", preContextText); |
| 0 | 486 | | tracingParameters.Add("postContextText", postContextText); |
| 0 | 487 | | tracingParameters.Add("text", text); |
| 0 | 488 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 489 | | ServiceClientTracing.Enter(_invocationId, this, "SpellChecker", tracingParameters); |
| | 490 | | } |
| | 491 | | // Construct URL |
| 1 | 492 | | var _baseUrl = BaseUri; |
| 1 | 493 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "spellcheck"; |
| 1 | 494 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 1 | 495 | | List<string> _queryParameters = new List<string>(); |
| 1 | 496 | | if (actionType != null) |
| | 497 | | { |
| 0 | 498 | | _queryParameters.Add(string.Format("ActionType={0}", System.Uri.EscapeDataString(actionType))); |
| | 499 | | } |
| 1 | 500 | | if (appName != null) |
| | 501 | | { |
| 0 | 502 | | _queryParameters.Add(string.Format("AppName={0}", System.Uri.EscapeDataString(appName))); |
| | 503 | | } |
| 1 | 504 | | if (countryCode != null) |
| | 505 | | { |
| 0 | 506 | | _queryParameters.Add(string.Format("cc={0}", System.Uri.EscapeDataString(countryCode))); |
| | 507 | | } |
| 1 | 508 | | if (clientMachineName != null) |
| | 509 | | { |
| 0 | 510 | | _queryParameters.Add(string.Format("ClientMachineName={0}", System.Uri.EscapeDataString(clientMachineNam |
| | 511 | | } |
| 1 | 512 | | if (docId != null) |
| | 513 | | { |
| 0 | 514 | | _queryParameters.Add(string.Format("DocId={0}", System.Uri.EscapeDataString(docId))); |
| | 515 | | } |
| 1 | 516 | | if (market != null) |
| | 517 | | { |
| 0 | 518 | | _queryParameters.Add(string.Format("mkt={0}", System.Uri.EscapeDataString(market))); |
| | 519 | | } |
| 1 | 520 | | if (sessionId != null) |
| | 521 | | { |
| 0 | 522 | | _queryParameters.Add(string.Format("SessionId={0}", System.Uri.EscapeDataString(sessionId))); |
| | 523 | | } |
| 1 | 524 | | if (setLang != null) |
| | 525 | | { |
| 0 | 526 | | _queryParameters.Add(string.Format("SetLang={0}", System.Uri.EscapeDataString(setLang))); |
| | 527 | | } |
| 1 | 528 | | if (userId != null) |
| | 529 | | { |
| 0 | 530 | | _queryParameters.Add(string.Format("UserId={0}", System.Uri.EscapeDataString(userId))); |
| | 531 | | } |
| 1 | 532 | | if (_queryParameters.Count > 0) |
| | 533 | | { |
| 0 | 534 | | _url += "?" + string.Join("&", _queryParameters); |
| | 535 | | } |
| | 536 | | // Create HTTP transport objects |
| 1 | 537 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 538 | | HttpResponseMessage _httpResponse = null; |
| 1 | 539 | | _httpRequest.Method = new HttpMethod("POST"); |
| 1 | 540 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 541 | | // Set Headers |
| 1 | 542 | | if (xBingApisSDK != null) |
| | 543 | | { |
| 1 | 544 | | if (_httpRequest.Headers.Contains("X-BingApis-SDK")) |
| | 545 | | { |
| 0 | 546 | | _httpRequest.Headers.Remove("X-BingApis-SDK"); |
| | 547 | | } |
| 1 | 548 | | _httpRequest.Headers.TryAddWithoutValidation("X-BingApis-SDK", xBingApisSDK); |
| | 549 | | } |
| 1 | 550 | | if (acceptLanguage != null) |
| | 551 | | { |
| 0 | 552 | | if (_httpRequest.Headers.Contains("Accept-Language")) |
| | 553 | | { |
| 0 | 554 | | _httpRequest.Headers.Remove("Accept-Language"); |
| | 555 | | } |
| 0 | 556 | | _httpRequest.Headers.TryAddWithoutValidation("Accept-Language", acceptLanguage); |
| | 557 | | } |
| 1 | 558 | | if (pragma != null) |
| | 559 | | { |
| 0 | 560 | | if (_httpRequest.Headers.Contains("Pragma")) |
| | 561 | | { |
| 0 | 562 | | _httpRequest.Headers.Remove("Pragma"); |
| | 563 | | } |
| 0 | 564 | | _httpRequest.Headers.TryAddWithoutValidation("Pragma", pragma); |
| | 565 | | } |
| 1 | 566 | | if (userAgent != null) |
| | 567 | | { |
| 0 | 568 | | if (_httpRequest.Headers.Contains("User-Agent")) |
| | 569 | | { |
| 0 | 570 | | _httpRequest.Headers.Remove("User-Agent"); |
| | 571 | | } |
| 0 | 572 | | _httpRequest.Headers.TryAddWithoutValidation("User-Agent", userAgent); |
| | 573 | | } |
| 1 | 574 | | if (clientId != null) |
| | 575 | | { |
| 0 | 576 | | if (_httpRequest.Headers.Contains("X-MSEdge-ClientID")) |
| | 577 | | { |
| 0 | 578 | | _httpRequest.Headers.Remove("X-MSEdge-ClientID"); |
| | 579 | | } |
| 0 | 580 | | _httpRequest.Headers.TryAddWithoutValidation("X-MSEdge-ClientID", clientId); |
| | 581 | | } |
| 1 | 582 | | if (clientIp != null) |
| | 583 | | { |
| 0 | 584 | | if (_httpRequest.Headers.Contains("X-MSEdge-ClientIP")) |
| | 585 | | { |
| 0 | 586 | | _httpRequest.Headers.Remove("X-MSEdge-ClientIP"); |
| | 587 | | } |
| 0 | 588 | | _httpRequest.Headers.TryAddWithoutValidation("X-MSEdge-ClientIP", clientIp); |
| | 589 | | } |
| 1 | 590 | | if (location != null) |
| | 591 | | { |
| 0 | 592 | | if (_httpRequest.Headers.Contains("X-Search-Location")) |
| | 593 | | { |
| 0 | 594 | | _httpRequest.Headers.Remove("X-Search-Location"); |
| | 595 | | } |
| 0 | 596 | | _httpRequest.Headers.TryAddWithoutValidation("X-Search-Location", location); |
| | 597 | | } |
| | 598 | |
|
| | 599 | |
|
| 1 | 600 | | if (customHeaders != null) |
| | 601 | | { |
| 0 | 602 | | foreach(var _header in customHeaders) |
| | 603 | | { |
| 0 | 604 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 605 | | { |
| 0 | 606 | | _httpRequest.Headers.Remove(_header.Key); |
| | 607 | | } |
| 0 | 608 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 609 | | } |
| | 610 | | } |
| | 611 | |
|
| | 612 | | // Serialize Request |
| 1 | 613 | | string _requestContent = null; |
| 1 | 614 | | var values = new List<KeyValuePair<string, string>>(); |
| 1 | 615 | | if(mode != null) |
| | 616 | | { |
| 0 | 617 | | values.Add(new KeyValuePair<string,string>("Mode", mode)); |
| | 618 | | } |
| 1 | 619 | | if(preContextText != null) |
| | 620 | | { |
| 0 | 621 | | values.Add(new KeyValuePair<string,string>("PreContextText", preContextText)); |
| | 622 | | } |
| 1 | 623 | | if(postContextText != null) |
| | 624 | | { |
| 0 | 625 | | values.Add(new KeyValuePair<string,string>("PostContextText", postContextText)); |
| | 626 | | } |
| 1 | 627 | | if(text != null) |
| | 628 | | { |
| 1 | 629 | | values.Add(new KeyValuePair<string,string>("Text", text)); |
| | 630 | | } |
| 1 | 631 | | var _formContent = new FormUrlEncodedContent(values); |
| 1 | 632 | | _httpRequest.Content = _formContent; |
| | 633 | | // Set Credentials |
| 1 | 634 | | if (Credentials != null) |
| | 635 | | { |
| 1 | 636 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 637 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 638 | | } |
| | 639 | | // Send Request |
| 1 | 640 | | if (_shouldTrace) |
| | 641 | | { |
| 0 | 642 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 643 | | } |
| 1 | 644 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 645 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 646 | | if (_shouldTrace) |
| | 647 | | { |
| 0 | 648 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 649 | | } |
| 1 | 650 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 651 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 652 | | string _responseContent = null; |
| 1 | 653 | | if ((int)_statusCode != 200) |
| | 654 | | { |
| 0 | 655 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 656 | | try |
| | 657 | | { |
| 0 | 658 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 659 | | ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser |
| 0 | 660 | | if (_errorBody != null) |
| | 661 | | { |
| 0 | 662 | | ex.Body = _errorBody; |
| | 663 | | } |
| 0 | 664 | | } |
| 0 | 665 | | catch (JsonException) |
| | 666 | | { |
| | 667 | | // Ignore the exception |
| 0 | 668 | | } |
| 0 | 669 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 670 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 671 | | if (_shouldTrace) |
| | 672 | | { |
| 0 | 673 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 674 | | } |
| 0 | 675 | | _httpRequest.Dispose(); |
| 0 | 676 | | if (_httpResponse != null) |
| | 677 | | { |
| 0 | 678 | | _httpResponse.Dispose(); |
| | 679 | | } |
| 0 | 680 | | throw ex; |
| | 681 | | } |
| | 682 | | // Create Result |
| 1 | 683 | | var _result = new HttpOperationResponse<SpellCheckModel>(); |
| 1 | 684 | | _result.Request = _httpRequest; |
| 1 | 685 | | _result.Response = _httpResponse; |
| | 686 | | // Deserialize Response |
| 1 | 687 | | if ((int)_statusCode == 200) |
| | 688 | | { |
| 1 | 689 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 690 | | try |
| | 691 | | { |
| 1 | 692 | | _result.Body = SafeJsonConvert.DeserializeObject<SpellCheckModel>(_responseContent, DeserializationS |
| 1 | 693 | | } |
| 0 | 694 | | catch (JsonException ex) |
| | 695 | | { |
| 0 | 696 | | _httpRequest.Dispose(); |
| 0 | 697 | | if (_httpResponse != null) |
| | 698 | | { |
| 0 | 699 | | _httpResponse.Dispose(); |
| | 700 | | } |
| 0 | 701 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 702 | | } |
| | 703 | | } |
| 1 | 704 | | if (_shouldTrace) |
| | 705 | | { |
| 0 | 706 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 707 | | } |
| 1 | 708 | | return _result; |
| 1 | 709 | | } |
| | 710 | |
|
| | 711 | | } |
| | 712 | | } |