/// <summary>
        /// Delete User Data
        /// </summary>
        /// <param name="sender">A sender object</param>
        /// <param name="e">RoutedEventArgs</param>
        /// <remarks>
        /// <para>Removes ALL Label/Value pairs for user data</para>
        /// </remarks>
        private async void DeleteUserDataButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            //Clear Globals
            personUserData = "{}";
            userDataPayload.Clear();

            //Reset UI Globals
            TrainStatusTextBlock.Text      = "";
            SubmissionStatusTextBlock.Text = "";

            //Reset UI Colors
            SubmissionStatusTextBlock.Foreground = new SolidColorBrush(Colors.Black);
            TrainStatusTextBlock.Foreground      = new SolidColorBrush(Colors.Black);

            //Logic
            if (knownPerson.Name.Length <= 0)
            {
                UpdateUserDataStatusTextBlock.Text = $"Person not found. Fetch a known Person";

                UpdateUserDataStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
            }
            else
            {
                await ApiCallAllowed(true);

                await faceServiceClient.UpdatePersonAsync(personGroupId, knownPerson.PersonId, knownPerson.Name, personUserData);

                Person[] people = await GetKnownPeople();

                var matchedPeople = people.Where(p => p.Name == personName);

                if (matchedPeople.Count() > 0)
                {
                    knownPerson = matchedPeople.FirstOrDefault();

                    UpdateUserDataStatusTextBlock.Text = "User Data for Person: " + knownPerson.Name + " has been deleted. ";
                    if (knownPerson.UserData == "{}")
                    {
                        UpdateUserDataPayloadTextBlock.Text = "No User Data...";
                        JSONTextBlock.Text       = "";
                        JSONHeaderTextBlock.Text = "";
                        InfoHeaderTextBlock.Text = "";
                    }
                    else
                    {
                        UpdateUserDataPayloadTextBlock.Text = knownPerson.UserData;
                    }
                }
            }
        }
 public void UpdatePerson(Person person)
 {
     try
     {
         Task.Run(() => Api.UpdatePersonAsync(person.GroupName.ToLowerInvariant(), person.Id.Value, person.Name, person.UserData)).GetAwaiter().GetResult();
     }
     catch (FaceAPIException ex)
     {
         throw new FaceApiException(ex.ErrorMessage);
     }
 }
Beispiel #3
0
        public async Task <bool> UpdatePerson(User user, byte[] pic)
        {
            try
            {
                // Update user's data
                await _faceClient.UpdatePersonAsync(_miriotPersonGroupId, user.Id, user.Name, JsonConvert.SerializeObject(user.UserData));

                // Add the new face
                using (var stream = new MemoryStream(pic))
                    await _faceClient.AddPersonFaceAsync(_miriotPersonGroupId, user.Id, stream);

                // Train model
                await _faceClient.TrainPersonGroupAsync(_miriotPersonGroupId);

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// This method creates a new person if it doesn't exist yet within the Face API, and uses its newly created person ID as its name.
        /// </summary>
        /// <param name="name">The name of the person to create: can either be a real name when updating a person, or a temporary GUID for a newly found person.</param>
        /// <returns>The final person ID of the Face API created person, or the ID of the person with this name that already existed.</returns>
        public async Task <Guid> CreatePerson(string name)
        {
            var persons = await faceServiceClient.GetPersonsAsync(personGroupId);

            var result = persons.Where(p => p.Name == name).ToList();

            if (result.Any())
            {
                // if the person exists, update its name with the possible new value
                var person = result.FirstOrDefault();
                return(person.PersonId);
            }

            // if the person doesn't exist, create him or her
            var createPersonResult = await faceServiceClient.CreatePersonAsync(personGroupId, name);

            // now update the name with its Face API person ID (because we do not yet know the name of newly found persons)
            var newName = createPersonResult.PersonId.ToString();
            await faceServiceClient.UpdatePersonAsync(personGroupId, createPersonResult.PersonId, newName);

            return(createPersonResult.PersonId);
        }