diff --git a/Finished/ImageProcessing/ProcessingLibrary/ServiceHelpers/FaceServiceHelper.cs b/Finished/ImageProcessing/ProcessingLibrary/ServiceHelpers/FaceServiceHelper.cs index 0244284..d8264bf 100644 --- a/Finished/ImageProcessing/ProcessingLibrary/ServiceHelpers/FaceServiceHelper.cs +++ b/Finished/ImageProcessing/ProcessingLibrary/ServiceHelpers/FaceServiceHelper.cs @@ -31,6 +31,21 @@ public static string ApiKey } } + private static string apiKeyRegion; + public static string ApiKeyRegion + { + get { return apiKeyRegion; } + set + { + var changed = apiKeyRegion != value; + apiKeyRegion = value; + if (changed) + { + InitializeFaceServiceClient(); + } + } + } + static FaceServiceHelper() { InitializeFaceServiceClient(); @@ -38,7 +53,9 @@ static FaceServiceHelper() private static void InitializeFaceServiceClient() { - faceClient = new FaceServiceClient(apiKey); + faceClient = !string.IsNullOrEmpty(ApiKeyRegion) ? + new FaceServiceClient(ApiKey, string.Format("https://{0}.api.cognitive.microsoft.com/face/v1.0", ApiKeyRegion)) : + new FaceServiceClient(ApiKey); } private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func> action) diff --git a/Finished/ImageProcessing/ProcessingLibrary/ServiceHelpers/VisionServiceHelper.cs b/Finished/ImageProcessing/ProcessingLibrary/ServiceHelpers/VisionServiceHelper.cs index 66dabb8..5637596 100644 --- a/Finished/ImageProcessing/ProcessingLibrary/ServiceHelpers/VisionServiceHelper.cs +++ b/Finished/ImageProcessing/ProcessingLibrary/ServiceHelpers/VisionServiceHelper.cs @@ -40,9 +40,26 @@ public static string ApiKey } } + private static string apiKeyRegion; + public static string ApiKeyRegion + { + get { return apiKeyRegion; } + set + { + var changed = apiKeyRegion != value; + apiKeyRegion = value; + if (changed) + { + InitializeVisionService(); + } + } + } + private static void InitializeVisionService() { - visionClient = new VisionServiceClient(apiKey); + visionClient = !string.IsNullOrEmpty(ApiKeyRegion) ? + new VisionServiceClient(ApiKey, string.Format("https://{0}.api.cognitive.microsoft.com/vision/v1.0", ApiKeyRegion)) : + new VisionServiceClient(ApiKey); } private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func> action) diff --git a/Finished/ImageProcessing/TestApp/MainPage.xaml.cs b/Finished/ImageProcessing/TestApp/MainPage.xaml.cs index d8fda1b..23bd02d 100644 --- a/Finished/ImageProcessing/TestApp/MainPage.xaml.cs +++ b/Finished/ImageProcessing/TestApp/MainPage.xaml.cs @@ -55,8 +55,10 @@ private static void InitializeServiceHelpers() dynamic settings = new JsonSerializer().Deserialize(textReader); FaceServiceHelper.ApiKey = settings.CognitiveServicesKeys.Face; + FaceServiceHelper.ApiKeyRegion = settings.CognitiveServicesKeys.FaceRegion; EmotionServiceHelper.ApiKey = settings.CognitiveServicesKeys.Emotion; VisionServiceHelper.ApiKey = settings.CognitiveServicesKeys.Vision; + VisionServiceHelper.ApiKeyRegion = settings.CognitiveServicesKeys.VisionRegion; } } diff --git a/Finished/ImageProcessing/TestApp/settings.json b/Finished/ImageProcessing/TestApp/settings.json index c99b9df..822900f 100644 --- a/Finished/ImageProcessing/TestApp/settings.json +++ b/Finished/ImageProcessing/TestApp/settings.json @@ -1,8 +1,10 @@ { "CognitiveServicesKeys": { "Face": "", + "FaceRegion": "", "Emotion": "", - "Vision": "" + "Vision": "", + "VisionRegion": "" }, "AzureStorage": { "ConnectionString": "", diff --git a/Finished/ImageProcessing/TestCLI/Program.cs b/Finished/ImageProcessing/TestCLI/Program.cs index 4ffa18b..aba43dc 100644 --- a/Finished/ImageProcessing/TestCLI/Program.cs +++ b/Finished/ImageProcessing/TestCLI/Program.cs @@ -68,8 +68,10 @@ private static async Task InitializeAsync(string settingsFile = null) dynamic settings = new JsonSerializer().Deserialize(textReader); FaceServiceHelper.ApiKey = settings.CognitiveServicesKeys.Face; + FaceServiceHelper.ApiKeyRegion = settings.CognitiveServicesKeys.FaceRegion; EmotionServiceHelper.ApiKey = settings.CognitiveServicesKeys.Emotion; VisionServiceHelper.ApiKey = settings.CognitiveServicesKeys.Vision; + VisionServiceHelper.ApiKeyRegion = settings.CognitiveServicesKeys.VisionRegion; BlobStorageHelper.ConnectionString = settings.AzureStorage.ConnectionString; BlobStorageHelper.ContainerName = settings.AzureStorage.BlobContainer; diff --git a/Finished/ImageProcessing/TestCLI/settings.json b/Finished/ImageProcessing/TestCLI/settings.json index c99b9df..226c311 100644 --- a/Finished/ImageProcessing/TestCLI/settings.json +++ b/Finished/ImageProcessing/TestCLI/settings.json @@ -1,8 +1,10 @@ { "CognitiveServicesKeys": { "Face": "", + "FaceRegion": "", "Emotion": "", - "Vision": "" + "Vision": "", + "VisionRegion": "" }, "AzureStorage": { "ConnectionString": "", diff --git a/LabManual.md b/LabManual.md index 93a862e..85c0c9c 100644 --- a/LabManual.md +++ b/LabManual.md @@ -46,7 +46,9 @@ Once you have created your new API subscription, you can grab the keys from the ![Cognitive API Key](./assets/cognitive-keys.PNG) -We'll also be using other APIs within the Computer Vision family, so take this opportunity to create API keys for the _Emotion_ and _Face_ APIs as well. They are created in the same fashion as above, and should re-use the same Resource Group you've created. _Pin to Dashboard_, and then add those keys to your `settings.json` files. +We'll also be using other APIs within the Computer Vision family, so take this opportunity to create API keys for the _Emotion_ and _Face_ APIs as well. They are created in the same fashion as above, and should re-use the same Resource Group you've created. _Pin to Dashboard_, and then add those keys to your `settings.json` files. + +As you will notice in the previous steps, the _Face_ and _Vision_ APIs have support for multiple Azure Regions. Since each region has a different end point, once you select the region for your keys you will need to enter the region in the `settings.json` files as well. The region value should go in the _FaceRegion_ and _VisionRegion_ fields in the `settings.json` file (the possible values are "eastus2", "southeastasia", "westcentralus", "westeurope" and "westus"). Since we'll be using [LUIS](https://www.microsoft.com/cognitive-services/en-us/language-understanding-intelligent-service-luis) later in the tutorial, let's take this opportunity to create our LUIS subscription here as well. It's created in the exact same fashion as above, but choose Language Understanding Intelligent Service from the API drop-down, and re-use the same Resource Group you created above. Once again, _Pin to Dashboard_ so once we get to that stage of the tutorial you'll find it easy to get access. diff --git a/Starting/ImageProcessing/ProcessingLibrary/ServiceHelpers/FaceServiceHelper.cs b/Starting/ImageProcessing/ProcessingLibrary/ServiceHelpers/FaceServiceHelper.cs index 0244284..d8264bf 100644 --- a/Starting/ImageProcessing/ProcessingLibrary/ServiceHelpers/FaceServiceHelper.cs +++ b/Starting/ImageProcessing/ProcessingLibrary/ServiceHelpers/FaceServiceHelper.cs @@ -31,6 +31,21 @@ public static string ApiKey } } + private static string apiKeyRegion; + public static string ApiKeyRegion + { + get { return apiKeyRegion; } + set + { + var changed = apiKeyRegion != value; + apiKeyRegion = value; + if (changed) + { + InitializeFaceServiceClient(); + } + } + } + static FaceServiceHelper() { InitializeFaceServiceClient(); @@ -38,7 +53,9 @@ static FaceServiceHelper() private static void InitializeFaceServiceClient() { - faceClient = new FaceServiceClient(apiKey); + faceClient = !string.IsNullOrEmpty(ApiKeyRegion) ? + new FaceServiceClient(ApiKey, string.Format("https://{0}.api.cognitive.microsoft.com/face/v1.0", ApiKeyRegion)) : + new FaceServiceClient(ApiKey); } private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func> action) diff --git a/Starting/ImageProcessing/ProcessingLibrary/ServiceHelpers/VisionServiceHelper.cs b/Starting/ImageProcessing/ProcessingLibrary/ServiceHelpers/VisionServiceHelper.cs index 66dabb8..5637596 100644 --- a/Starting/ImageProcessing/ProcessingLibrary/ServiceHelpers/VisionServiceHelper.cs +++ b/Starting/ImageProcessing/ProcessingLibrary/ServiceHelpers/VisionServiceHelper.cs @@ -40,9 +40,26 @@ public static string ApiKey } } + private static string apiKeyRegion; + public static string ApiKeyRegion + { + get { return apiKeyRegion; } + set + { + var changed = apiKeyRegion != value; + apiKeyRegion = value; + if (changed) + { + InitializeVisionService(); + } + } + } + private static void InitializeVisionService() { - visionClient = new VisionServiceClient(apiKey); + visionClient = !string.IsNullOrEmpty(ApiKeyRegion) ? + new VisionServiceClient(ApiKey, string.Format("https://{0}.api.cognitive.microsoft.com/vision/v1.0", ApiKeyRegion)) : + new VisionServiceClient(ApiKey); } private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func> action) diff --git a/Starting/ImageProcessing/TestApp/MainPage.xaml.cs b/Starting/ImageProcessing/TestApp/MainPage.xaml.cs index 5cc5898..5f36254 100644 --- a/Starting/ImageProcessing/TestApp/MainPage.xaml.cs +++ b/Starting/ImageProcessing/TestApp/MainPage.xaml.cs @@ -55,8 +55,10 @@ private static void InitializeServiceHelpers() dynamic settings = new JsonSerializer().Deserialize(textReader); FaceServiceHelper.ApiKey = settings.CognitiveServicesKeys.Face; + FaceServiceHelper.ApiKeyRegion = settings.CognitiveServicesKeys.FaceRegion; EmotionServiceHelper.ApiKey = settings.CognitiveServicesKeys.Emotion; VisionServiceHelper.ApiKey = settings.CognitiveServicesKeys.Vision; + VisionServiceHelper.ApiKeyRegion = settings.CognitiveServicesKeys.VisionRegion; } } private async void ProcessImagesClicked(object sender, RoutedEventArgs e) diff --git a/Starting/ImageProcessing/TestApp/settings.json b/Starting/ImageProcessing/TestApp/settings.json index c99b9df..822900f 100644 --- a/Starting/ImageProcessing/TestApp/settings.json +++ b/Starting/ImageProcessing/TestApp/settings.json @@ -1,8 +1,10 @@ { "CognitiveServicesKeys": { "Face": "", + "FaceRegion": "", "Emotion": "", - "Vision": "" + "Vision": "", + "VisionRegion": "" }, "AzureStorage": { "ConnectionString": "", diff --git a/Starting/ImageProcessing/TestCLI/Program.cs b/Starting/ImageProcessing/TestCLI/Program.cs index abca2f8..0104e99 100644 --- a/Starting/ImageProcessing/TestCLI/Program.cs +++ b/Starting/ImageProcessing/TestCLI/Program.cs @@ -68,8 +68,10 @@ private static async Task InitializeAsync(string settingsFile = null) dynamic settings = new JsonSerializer().Deserialize(textReader); FaceServiceHelper.ApiKey = settings.CognitiveServicesKeys.Face; + FaceServiceHelper.ApiKeyRegion = settings.CognitiveServicesKeys.FaceRegion; EmotionServiceHelper.ApiKey = settings.CognitiveServicesKeys.Emotion; VisionServiceHelper.ApiKey = settings.CognitiveServicesKeys.Vision; + VisionServiceHelper.ApiKeyRegion = settings.CognitiveServicesKeys.VisionRegion; BlobStorageHelper.ConnectionString = settings.AzureStorage.ConnectionString; BlobStorageHelper.ContainerName = settings.AzureStorage.BlobContainer; diff --git a/Starting/ImageProcessing/TestCLI/settings.json b/Starting/ImageProcessing/TestCLI/settings.json index c99b9df..226c311 100644 --- a/Starting/ImageProcessing/TestCLI/settings.json +++ b/Starting/ImageProcessing/TestCLI/settings.json @@ -1,8 +1,10 @@ { "CognitiveServicesKeys": { "Face": "", + "FaceRegion": "", "Emotion": "", - "Vision": "" + "Vision": "", + "VisionRegion": "" }, "AzureStorage": { "ConnectionString": "",