public void CreateTextAnalyticsClient()
        {
            string endpoint        = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT");
            string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY");

            #region Snippet:CreateTextAnalyticsClient
            //@@ string endpoint = "<endpoint>";
            //@@ string subscriptionKey = "<subscriptionKey>";
            var credential = new TextAnalyticsSubscriptionKeyCredential(subscriptionKey);
            var client     = new TextAnalyticsClient(new Uri(endpoint), credential);
            #endregion
        }
예제 #2
0
        public TextAnalyticsClient GetClient(TextAnalyticsSubscriptionKeyCredential credential = default)
        {
            string subscriptionKey = Recording.GetVariableFromEnvironment(SubscriptionKeyEnvironmentVariable);

            credential ??= new TextAnalyticsSubscriptionKeyCredential(subscriptionKey);
            return(InstrumentClient(
                       new TextAnalyticsClient(
                           new Uri(Recording.GetVariableFromEnvironment(EndpointEnvironmentVariable)),
                           credential,
                           Recording.InstrumentClientOptions(new TextAnalyticsClientOptions()))
                       ));
        }
        public void BadRequestSnippet()
        {
            string endpoint        = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT");
            string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY");

            var    credentials = new TextAnalyticsSubscriptionKeyCredential(subscriptionKey);
            var    client      = new TextAnalyticsClient(new Uri(endpoint), credentials);
            string input       = "Este documento está en español.";

            #region Snippet:BadRequest
            try
            {
                DetectLanguageResult result = client.DetectLanguage(input);
            }
            catch (RequestFailedException e)
            {
                Console.WriteLine(e.ToString());
            }
            #endregion
        }
예제 #4
0
        public async Task RotateSubscriptionKey()
        {
            // Instantiate a client that will be used to call the service.
            string subscriptionKey     = Recording.GetVariableFromEnvironment(SubscriptionKeyEnvironmentVariable);
            var    credential          = new TextAnalyticsSubscriptionKeyCredential(subscriptionKey);
            TextAnalyticsClient client = GetClient(credential);

            string input = "Este documento está en español.";

            // Verify the credential works (i.e., doesn't throw)
            await client.DetectLanguageAsync(input);

            // Rotate the subscription key to an invalid value and make sure it fails
            credential.UpdateCredential("Invalid");
            Assert.ThrowsAsync <RequestFailedException>(
                async() => await client.DetectLanguageAsync(input));

            // Re-rotate the subscription key and make sure it succeeds again
            credential.UpdateCredential(subscriptionKey);
            await client.DetectLanguageAsync(input);
        }
        public async Task RotateSubscriptionKey()
        {
            string endpoint        = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT");
            string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY");

            // Instantiate a client that will be used to call the service.
            var credential = new TextAnalyticsSubscriptionKeyCredential(subscriptionKey);
            var client     = new TextAnalyticsClient(new Uri(endpoint), credential);

            string input = "Este documento está en español.";

            // Verify the credential works (i.e., doesn't throw)
            await client.DetectLanguageAsync(input);

            // Rotate the subscription key to an invalid value and make sure it fails
            credential.UpdateCredential("Invalid");
            Assert.ThrowsAsync <RequestFailedException>(
                async() => await client.DetectLanguageAsync(input));

            // Re-rotate the subscription key and make sure it succeeds again
            credential.UpdateCredential(subscriptionKey);
            await client.DetectLanguageAsync(input);
        }