public static async Task <Guid> AddNewFace(string username, Stream photo) { UpdateActivityIndicatorStatus(true); try { await CreatePersonGroup().ConfigureAwait(false); var createPersonResult = await FaceApiClient.PersonGroupPerson.CreateAsync(_personGroupId, username).ConfigureAwait(false); var faceResult = await FaceApiClient.PersonGroupPerson.AddFaceFromStreamAsync(_personGroupId, createPersonResult.PersonId, photo).ConfigureAwait(false); var trainingStatus = await TrainPersonGroup(_personGroupId).ConfigureAwait(false); if (trainingStatus.Status.Equals(TrainingStatusType.Failed)) { throw new Exception(trainingStatus.Message); } return(faceResult.PersistedFaceId); } catch (Exception ex) { Debug.WriteLine("An error occured, Please try again."); DebugService.PrintException(ex); throw new Exception(ex.Message); } finally { UpdateActivityIndicatorStatus(false); } }
static async Task CreatePersonGroup() { try { await FaceApiClient.PersonGroup.CreateAsync(_personGroupId, _personGroupName).ConfigureAwait(false); } catch (APIErrorException e) when(e.Response.StatusCode is HttpStatusCode.Conflict) { Debug.WriteLine("Person Group Already Exists"); DebugService.PrintException(e); } }
public static async Task RemoveExistingFace(Guid userId) { await UpdateActivityIndicatorStatus(true).ConfigureAwait(false); try { await FaceApiClient.PersonGroupPerson.DeleteAsync(_personGroupId, userId).ConfigureAwait(false); } catch (APIErrorException e) when(e.Response.StatusCode.Equals(HttpStatusCode.NotFound)) { Debug.WriteLine("Person Does Not Exist"); DebugService.PrintException(e); } finally { await UpdateActivityIndicatorStatus(false).ConfigureAwait(false); } }