/// <summary> /// Async check if a profile is regsitered for the email address. /// Returns true if so, false otherwise. /// /// /// </summary> /// <param name="email"></param> /// <returns></returns> private async Task <User> CheckProfileExists(string email) { var taskComplete = new TaskCompletionSource <User>(); /*Try to load a user with this email */ User registeredUser = DatabaseController.LoadUser(email); if (registeredUser == null) { return(null); } taskComplete.SetResult(registeredUser); return(registeredUser); }
/// <summary> /// Creates a new user profile for a User in the DiScribe database. /// /// Also creates a corresponding profile with the Azure Speaker Recognition /// endpoint and returns the GUID for that profile on success. /// /// /// </summary> /// <param name="client"></param> /// <param name="locale"></param> /// <returns>Created profile GUID or GUID {00000000-0000-0000-0000-000000000000} on fail</returns> public async Task <Guid> CreateUserProfile(UserParams userParams) { foreach (var profile in UserProfiles) { /*Profile has already been enrolled */ if (profile.Email == userParams.Email) { return(profile.ProfileGUID); } } var taskComplete = new TaskCompletionSource <Guid>(); Task <CreateProfileResponse> profileTask = null; Guid failGuid = new Guid(); try { profileTask = EnrollmentClient.CreateProfileAsync(EnrollmentLocale); await profileTask; } catch (AggregateException ex) { Console.Error.WriteLine("Error creating user profile with Azure Speaker Recognition endpoint\n" + ex.InnerException.Message); taskComplete.SetResult(failGuid); return(failGuid); } userParams.ProfileGUID = profileTask.Result.ProfileId; /*Attempt to Create user profile in DB and add to list of user profiles */ User registeredUser = DatabaseController.CreateUser(userParams); if (registeredUser == null) { taskComplete.SetResult(failGuid); return(failGuid); } UserProfiles.Add(registeredUser); //Add profile to list of profiles managed by this instance taskComplete.SetResult(profileTask.Result.ProfileId); return(profileTask.Result.ProfileId); }