private async Task AddTrainingImages(IEnumerable <ImageAnalyzer> args, bool dismissImageCollectorFlyout = true)
        {
            this.progressControl.IsActive = true;

            if (dismissImageCollectorFlyout)
            {
                this.trainingImageCollectorFlyout.Hide();
            }

            bool      foundError = false;
            Exception lastError  = null;

            foreach (var item in args)
            {
                try
                {
                    PersistedFace addResult;
                    if (item.GetImageStreamCallback != null)
                    {
                        addResult = await FaceServiceHelper.AddPersonFaceFromStreamAsync(
                            this.CurrentPersonGroup.PersonGroupId,
                            this.SelectedPerson.PersonId,
                            imageStreamCallback : item.GetImageStreamCallback,
                            userData : item.LocalImagePath,
                            targetFaceRect : null);
                    }
                    else
                    {
                        addResult = await FaceServiceHelper.AddPersonFaceFromUrlAsync(
                            this.CurrentPersonGroup.PersonGroupId,
                            this.SelectedPerson.PersonId,
                            imageUrl : item.ImageUrl,
                            userData : item.ImageUrl,
                            targetFaceRect : null);
                    }

                    if (addResult != null)
                    {
                        this.SelectedPersonFaces.Add(new PersistedFace {
                            PersistedFaceId = addResult.PersistedFaceId, UserData = item.GetImageStreamCallback != null ? item.LocalImagePath : item.ImageUrl
                        });
                        this.needsTraining = true;
                    }
                }
                catch (Exception e)
                {
                    foundError = true;
                    lastError  = e;
                }
            }

            if (foundError)
            {
                await Util.GenericApiCallExceptionHandler(lastError, "Failure adding one or more of the faces");
            }

            this.progressControl.IsActive = false;
        }
        private async void OnConfirmImportButtonClicked(object sender, RoutedEventArgs e)
        {
            this.addPeopleInBatchesFlyout.Hide();
            this.commandBar.IsOpen = false;

            this.progressControl.IsActive = true;

            try
            {
                // UWP TextBox: new line is a '\r' symbol instead '\r\n'
                string[] names = new string[] { };
                if (!string.IsNullOrEmpty(this.importNamesTextBox?.Text))
                {
                    string newLineSymbol = this.importNamesTextBox.Text.Contains(Environment.NewLine) ? Environment.NewLine : "\r";
                    names = this.importNamesTextBox.Text.Split(newLineSymbol);
                }
                foreach (var name in names)
                {
                    string personName = Util.CapitalizeString(name.Trim());
                    if (string.IsNullOrEmpty(personName) || this.PersonsInCurrentGroup.Any(p => p.Name == personName))
                    {
                        continue;
                    }

                    Person newPerson = await FaceServiceHelper.CreatePersonAsync(this.CurrentPersonGroup.PersonGroupId, personName);

                    IEnumerable <string> faceUrls = await BingSearchHelper.GetImageSearchResults(string.Format("{0} {1} {2}", this.importImageSearchKeywordPrefix.Text, name, this.importImageSearchKeywordSufix.Text), count : 2);

                    foreach (var url in faceUrls)
                    {
                        try
                        {
                            ImageAnalyzer imageWithFace = new ImageAnalyzer(url);

                            await imageWithFace.DetectFacesAsync();

                            if (imageWithFace.DetectedFaces.Count() == 1)
                            {
                                await FaceServiceHelper.AddPersonFaceFromUrlAsync(this.CurrentPersonGroup.PersonGroupId, newPerson.PersonId, imageWithFace.ImageUrl, imageWithFace.ImageUrl, imageWithFace.DetectedFaces.First().FaceRectangle);
                            }
                        }
                        catch (Exception)
                        {
                            // Ignore errors with any particular image and continue
                        }

                        // Force a delay to reduce the chance of hitting API call rate limits
                        await Task.Delay(250);
                    }

                    this.needsTraining = true;

                    this.PersonsInCurrentGroup.Add(newPerson);
                }
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Failure during batch processing");
            }

            this.progressControl.IsActive = false;
        }