public static PersonGroup CreatePersonGroup(this azure.PersonGroup personGroup)
 {
     return(new PersonGroup
     {
         Name = personGroup.Name,
         PersonGroupId = personGroup.PersonGroupId,
         UserData = personGroup.UserData,
     });
 }
Beispiel #2
0
        public async Task SyncPersonsAsync()
        {
            try
            {
                PersonGroup group = null;
                try
                {
                    group = await _faceClient.PersonGroup.GetAsync(PersonGroupId);
                }
                catch (Exception)
                {
                    // ignored
                }

                if (group == null)
                {
                    await _faceClient.PersonGroup.CreateAsync(PersonGroupId, PersonGroupId, recognitionModel : RecognitionModel);
                }

                var dbPersons = await _personRepository.GetAll().ToListAsync();

                var servicePersons = await _faceClient.PersonGroupPerson.ListAsync(PersonGroupId);

                foreach (var dbPerson in dbPersons)
                {
                    if (dbPerson.ExternalGuid != Guid.Empty && servicePersons.Select(p => p.PersonId).Contains(dbPerson.ExternalGuid))
                    {
                        continue;
                    }

                    var person = await _faceClient.PersonGroupPerson.CreateAsync(PersonGroupId, dbPerson.Name,
                                                                                 dbPerson.Id.ToString());

                    await Task.Delay(1000);

                    dbPerson.ExternalGuid = person.PersonId;
                    await _personRepository.UpdateAsync(dbPerson, p => p.ExternalGuid);
                }

                foreach (var servicePerson in servicePersons)
                {
                    if (dbPersons.Select(p => p.ExternalGuid).Contains(servicePerson.PersonId))
                    {
                        continue;
                    }

                    await _faceClient.PersonGroupPerson.DeleteAsync(PersonGroupId, servicePerson.PersonId);

                    await Task.Delay(1000);
                }
            }
            catch (APIErrorException ae)
            {
                Debug.WriteLine(ae.Message);
            }
        }
 public static void UpdatePersonGroup(this azure.PersonGroup sourcePersonGroup, ref PersonGroup targetPersonGroup)
 {
     targetPersonGroup.Name          = sourcePersonGroup.Name;
     targetPersonGroup.PersonGroupId = sourcePersonGroup.PersonGroupId;
     targetPersonGroup.UserData      = sourcePersonGroup.UserData;
 }