private async void AddNewPersonDialog(Person currentPerson) { var dialog = new AddPersonContentDialog(); dialog.ProvideExistingPerson(currentPerson); await dialog.ShowAsync(); Person newPerson = dialog.AddedPerson; // If there is a valid person to add, add them if (newPerson != null) { // Get or create a directory for the user (we do this regardless of whether or not there is a profile picture) StorageFolder userFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(("Users\\" + newPerson.FriendlyName), CreationCollisionOption.OpenIfExists); // See if we have a profile photo if (dialog.TemporaryFile != null) { // Save off the profile photo and delete the temporary file await dialog.TemporaryFile.CopyAsync(userFolder, "ProfilePhoto.jpg", NameCollisionOption.ReplaceExisting); await dialog.TemporaryFile.DeleteAsync(); // Update the profile picture for the person newPerson.IsProfileImage = true; newPerson.ImageFileName = userFolder.Path + "\\ProfilePhoto.jpg"; if (AppSettings.FaceApiKey != "") { await FacialSimilarity.AddTrainingImageAsync(newPerson.FriendlyName, new Uri($"ms-appdata:///local/Users/{newPerson.FriendlyName}/ProfilePhoto.jpg")); } } // Add the user if it is new now that changes have been made if (currentPerson == null) { await FamilyModel.AddPersonAsync(newPerson); } // Otherwise we had a user, so update the current one else { //await FamilyModel.UpdatePersonImageAsync(newPerson); Person personToUpdate = FamilyModel.PersonFromName(currentPerson.FriendlyName); if (personToUpdate != null) { personToUpdate.IsProfileImage = true; personToUpdate.ImageFileName = userFolder.Path + "\\ProfilePhoto.jpg"; } } } }
private async void AddNewPersonFromDB(Person person, ObservableCollection <Face> faces) { //var dialog = new AddPersonContentDialog(); //dialog.ProvideExistingPerson(currentPerson); //await dialog.ShowAsync(); //dialog.AddedPerson = person; //Person newPerson = dialog.AddedPerson; Person newPerson = person; // If there is a valid person to add, add them if (newPerson != null) { try { // Get or create a directory for the user (we do this regardless of whether or not there is a profile picture) StorageFolder userFolder; if (person.FriendlyName != null && person.FriendlyName != "" && person.FriendlyName.Contains("stranger")) { userFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(("Users\\" + newPerson.FriendlyName), CreationCollisionOption.FailIfExists); } else { userFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(("Users\\" + newPerson.Name), CreationCollisionOption.FailIfExists); } StorageFile userFile = await userFolder.CreateFileAsync("ProfilePhoto.jpg", CreationCollisionOption.OpenIfExists); foreach (Face face in faces) { await AzureBlobService.DownloadFaceImageAsFile(face, userFile); } newPerson.IsProfileImage = true; newPerson.ImageFileName = userFolder.Path + "\\ProfilePhoto.jpg"; } catch { } // See if we have a profile photo //if (dialog.TemporaryFile != null) //{ // Save off the profile photo and delete the temporary file //await dialog.TemporaryFile.CopyAsync(userFolder, "ProfilePhoto.jpg", NameCollisionOption.GenerateUniqueName); //await dialog.TemporaryFile.DeleteAsync(); // Update the profile picture for the person await FacialSimilarity.AddTrainingImageAsync(newPerson.FriendlyName, new Uri($"ms-appdata:///local/Users/{newPerson.FriendlyName}/ProfilePhoto.jpg")); person = newPerson; //} // Add the user if it is new now that changes have been made //if (currentPerson == null) //{ // await FamilyModel.AddPersonAsync(newPerson); //} // Otherwise we had a user, so update the current one //else //{ // //await FamilyModel.UpdatePersonImageAsync(newPerson); // Person personToUpdate = FamilyModel.PersonFromName(currentPerson.FriendlyName); // if (personToUpdate != null) // { // personToUpdate.IsProfileImage = true; // personToUpdate.ImageFileName = userFolder.Path + "\\ProfilePhoto.jpg"; // } //} } }