From 53123d78a980a73d58f1b50566c47c61fbd3b3ce Mon Sep 17 00:00:00 2001 From: Lakshmanan Ramu Meenal Date: Wed, 27 Feb 2019 16:37:58 -0800 Subject: [PATCH] added SDK for version 2.1 --- .../TextAnalytics.Tests/BaseTests.cs | 2 +- .../DetectLanguage.json | 4 +-- .../Entities.json | 4 +-- .../KeyPhrases.json | 4 +-- .../Sentiment.json | 4 +-- .../TextAnalytics/DetectLanguageTests.cs | 2 +- .../TextAnalytics/EntitiesTests.cs | 6 ++-- .../TextAnalytics/KeyPhrasesTests.cs | 2 +- .../TextAnalytics/SentimentTests.cs | 2 +- .../TextAnalytics/TextAnalyticsClient.cs | 35 +++++++------------ ...tiveServices.Language.TextAnalytics.csproj | 4 +-- 11 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/BaseTests.cs b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/BaseTests.cs index 308fd9c4dfe8c..68c13a836d785 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/BaseTests.cs +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/BaseTests.cs @@ -8,7 +8,7 @@ public abstract class BaseTests { public static bool IsTestTenant = false; // BaseEndpoint only contains protocol and hostname - private static string BaseEndpoint = "https://westus.api.cognitive.microsoft.com"; + private static string BaseEndpoint = "https://westcentralus.api.cognitive.microsoft.com"; private static string SubscriptionKey = "000"; protected ITextAnalyticsClient GetClient(DelegatingHandler handler) diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.DetectLanguageTests/DetectLanguage.json b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.DetectLanguageTests/DetectLanguage.json index 6b0070bcf3ac6..bdcb893d066fb 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.DetectLanguageTests/DetectLanguage.json +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.DetectLanguageTests/DetectLanguage.json @@ -1,8 +1,8 @@ { "Entries": [ { - "RequestUri": "/text/analytics/v2.1-preview/languages", - "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEtcHJldmlldy9sYW5ndWFnZXM=", + "RequestUri": "/text/analytics/v2.1/languages", + "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEvbGFuZ3VhZ2Vz", "RequestMethod": "POST", "RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"id\": \"id\",\r\n \"text\": \"I love my team mates\"\r\n }\r\n ]\r\n}", "RequestHeaders": { diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.EntitiesTests/Entities.json b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.EntitiesTests/Entities.json index 31c0ca56688e9..4c64789d5cd9e 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.EntitiesTests/Entities.json +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.EntitiesTests/Entities.json @@ -1,8 +1,8 @@ { "Entries": [ { - "RequestUri": "/text/analytics/v2.1-preview/entities", - "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEtcHJldmlldy9lbnRpdGllcw==", + "RequestUri": "/text/analytics/v2.1/entities", + "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEvZW50aXRpZXM=", "RequestMethod": "POST", "RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"language\": \"en\",\r\n \"id\": \"id\",\r\n \"text\": \"Microsoft released Windows 10\"\r\n }\r\n ]\r\n}", "RequestHeaders": { diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.KeyPhrasesTests/KeyPhrases.json b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.KeyPhrasesTests/KeyPhrases.json index 6e2b117ff3228..4427ae2e56dcb 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.KeyPhrasesTests/KeyPhrases.json +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.KeyPhrasesTests/KeyPhrases.json @@ -1,8 +1,8 @@ { "Entries": [ { - "RequestUri": "/text/analytics/v2.1-preview/keyPhrases", - "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEtcHJldmlldy9rZXlQaHJhc2Vz", + "RequestUri": "/text/analytics/v2.1/keyPhrases", + "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEva2V5UGhyYXNlcw==", "RequestMethod": "POST", "RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"language\": \"en\",\r\n \"id\": \"id\",\r\n \"text\": \"I love my team mates\"\r\n }\r\n ]\r\n}", "RequestHeaders": { diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.SentimentTests/Sentiment.json b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.SentimentTests/Sentiment.json index 0763200f6e6a0..685c108482dd0 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.SentimentTests/Sentiment.json +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/SessionRecords/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.SentimentTests/Sentiment.json @@ -1,8 +1,8 @@ { "Entries": [ { - "RequestUri": "/text/analytics/v2.1-preview/sentiment", - "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEtcHJldmlldy9zZW50aW1lbnQ=", + "RequestUri": "/text/analytics/v2.1/sentiment", + "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEvc2VudGltZW50", "RequestMethod": "POST", "RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"language\": \"en\",\r\n \"id\": \"id\",\r\n \"text\": \"I love my team mates\"\r\n }\r\n ]\r\n}", "RequestHeaders": { diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/DetectLanguageTests.cs b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/DetectLanguageTests.cs index 84ac4b9096a1b..d37987fca1ab5 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/DetectLanguageTests.cs +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/DetectLanguageTests.cs @@ -21,7 +21,7 @@ public async Task DetectLanguage() HttpMockServer.Initialize(this.GetType().FullName, "DetectLanguage"); ITextAnalyticsClient client = GetClient(HttpMockServer.CreateInstance()); LanguageBatchResult result = await client.DetectLanguageAsync( - true, + null, new LanguageBatchInput( new List() { diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/EntitiesTests.cs b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/EntitiesTests.cs index c2ff28e3f4308..52a27c7106fd5 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/EntitiesTests.cs +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/EntitiesTests.cs @@ -18,7 +18,7 @@ public async Task Entities() HttpMockServer.Initialize(this.GetType().FullName, "Entities"); ITextAnalyticsClient client = GetClient(HttpMockServer.CreateInstance()); EntitiesBatchResult result = await client.EntitiesAsync( - true, + null, new MultiLanguageBatchInput( new List() { @@ -30,8 +30,8 @@ public async Task Entities() } })); - Assert.Equal("Windows 10", result.Documents[0].Entities[0].Name); - Assert.Equal("5f9fbd03-49c4-39ef-cc95-de83ab897b94", result.Documents[0].Entities[0].BingId); + Assert.Equal("Microsoft", result.Documents[0].Entities[0].Name); + Assert.Equal("a093e9b9-90f5-a3d5-c4b8-5855e1b01f85", result.Documents[0].Entities[0].BingId); Assert.Equal("Microsoft", result.Documents[0].Entities[0].Matches[0].Text); Assert.Equal(0.12508682244047509, result.Documents[0].Entities[0].Matches[0].WikipediaScore); Assert.Equal(0.99999618530273438, result.Documents[0].Entities[0].Matches[0].EntityTypeScore); diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/KeyPhrasesTests.cs b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/KeyPhrasesTests.cs index 0adbd3c4aba92..26350ca5f658b 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/KeyPhrasesTests.cs +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/KeyPhrasesTests.cs @@ -21,7 +21,7 @@ public async Task KeyPhrases() HttpMockServer.Initialize(this.GetType().FullName, "KeyPhrases"); ITextAnalyticsClient client = GetClient(HttpMockServer.CreateInstance()); KeyPhraseBatchResult result = await client.KeyPhrasesAsync( - true, + null, new MultiLanguageBatchInput( new List() { diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/SentimentTests.cs b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/SentimentTests.cs index e502e6c802880..96375f9630516 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/SentimentTests.cs +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics.Tests/TextAnalytics/SentimentTests.cs @@ -21,7 +21,7 @@ public async Task Sentiment() HttpMockServer.Initialize(this.GetType().FullName, "Sentiment"); ITextAnalyticsClient client = GetClient(HttpMockServer.CreateInstance()); SentimentBatchResult result = await client.SentimentAsync( - true, + null, new MultiLanguageBatchInput( new List() { diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics/Generated/TextAnalytics/TextAnalyticsClient.cs b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics/Generated/TextAnalytics/TextAnalyticsClient.cs index 554b263c1dc3a..2a7650e70df1d 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics/Generated/TextAnalytics/TextAnalyticsClient.cs +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics/Generated/TextAnalytics/TextAnalyticsClient.cs @@ -856,14 +856,21 @@ private void Initialize() HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; - if ((int)_statusCode != 200 && (int)_statusCode != 500) + if ((int)_statusCode != 200) { - var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); - if (_httpResponse.Content != null) { + var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } } - else { - _responseContent = string.Empty; + catch (JsonException) + { + // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); @@ -900,24 +907,6 @@ private void Initialize() throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } - // Deserialize Response - if ((int)_statusCode == 500) - { - _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); - try - { - _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); - } - catch (JsonException ex) - { - _httpRequest.Dispose(); - if (_httpResponse != null) - { - _httpResponse.Dispose(); - } - throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); - } - } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); diff --git a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.csproj b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.csproj index d492d9022d863..9b0565af5858c 100644 --- a/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.csproj +++ b/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics/TextAnalytics/Microsoft.Azure.CognitiveServices.Language.TextAnalytics.csproj @@ -18,10 +18,10 @@