private void SetIdentifiedPersonInfo(Guid tagId, Item imageItem, Person personItem)
        {
            if (personItem == null || imageItem == null)
            {
                return;
            }


            var value = (!string.IsNullOrEmpty(imageItem["IdentifiedPersons"])
                ? JsonConvert.DeserializeObject <IdentifiedPerson[]>(imageItem["IdentifiedPersons"])
                : new IdentifiedPerson[0]).ToList();

            if (!value.Any(i => i.Id == tagId && i.Data != null && i.Data.ID == personItem.ID))
            {
                value.Add(new IdentifiedPerson
                {
                    Id         = tagId,
                    Confidence = 1.0,
                    Data       = personItem
                });
            }

            using (new SecurityDisabler())
            {
                imageItem.Editing.BeginEdit();
                imageItem.Fields["IdentifiedPersons"].SetValue(JsonConvert.SerializeObject(value), true);
                imageItem.Editing.EndEdit(false);
            }
        }
        private async Task UpdateFaceDefinition(Item imageItem, FaceMetadata face, Person personItem)
        {
            if (face != null)
            {
                if (imageItem != null)
                {
                    var mediaItem = new MediaItem(imageItem);

                    using (var croppedImage = new MemoryStream())
                    {
                        try
                        {
                            CropImage(face.FacePosition, mediaItem.GetMediaStream(), croppedImage);

                            var faceServiceClient = CreateAzureClient();

                            croppedImage.Seek(0, SeekOrigin.Begin);

                            Image img = Image.FromStream(croppedImage);
                            img.Save(HttpContext.Current.Server.MapPath("~/face.jpg"));

                            croppedImage.Seek(0, SeekOrigin.Begin);

                            Log.Info($"Adding person face to person {personItem.AzurePersonGroupId} {personItem.AzureId}", this);

                            await faceServiceClient.AddPersonFaceAsync(personItem.AzurePersonGroupId.ToLowerInvariant(),
                                                                       Guid.Parse(personItem.AzureId), croppedImage);

                            Log.Info("Identify tag - Success", this);
                        }
                        catch (FaceAPIException faceEx)
                        {
                            Log.Info("FaceAPI exception + " + faceEx.ErrorMessage, this);
                        }
                        catch (Exception e)
                        {
                            Log.Info("Error during resize " + e, this);
                        }
                    }
                }
            }
        }