private async void deletePersonButton_Click(object sender, RoutedEventArgs e) { //Double check whether to delete progressDialog = new ContentDialog() { Title = " ", Content = "Do you really want to delete the chosen person?", PrimaryButtonText = "Yes, please delete it.", SecondaryButtonText = "Cancel", FullSizeDesired = false }; progressDialog.IsPrimaryButtonEnabled = true; int result = (int)await progressDialog.ShowAsync(); if (result == 1) { //Deletion begin showProgressDialog("Deleting the person"); await AzureDatabaseService.DeletePersonAndItsFaces(thisPerson); thisPerson = null; deletePersonButton.IsEnabled = false; progressDialog.Content = "Deletion Finished !"; progressDialog.IsPrimaryButtonEnabled = true; //Reload Persons List loadPersonsAndCheckEnquiry(); } }
private async void addPersonButton_Click(object sender, RoutedEventArgs e) { testInternetConnection(); if (internetConnection) { thisPerson = new Person(); var result = await PersonDialog.ShowAsync(); // Value 1 indicates primary button was selected by the user, which adds a new Person if ((int)result == 1) { //Apply the Data showProgressDialog("Apply the Data..."); thisPerson.Name = PersonNameInput.Text; thisPerson.Relation = PersonRelationInput.Text; thisPerson.RiskFactor = (int)riskSlider.Value; thisPerson.PatientId = PatientId; //Upload Person Info progressDialog.Content = "Upload Person Info..."; await AzureDatabaseService.UploadPersonInfo(thisPerson); thisPerson = await AzureDatabaseService.GetPersonFromNameAndRelation(thisPerson.Name, thisPerson.Relation, thisPerson.PatientId); //statusTextBlock.Text = "thisPerson.Id = " + thisPerson.Id; //Upload Face Info progressDialog.Content = "Upload Faces and Images..."; foreach (Face face in addFaceList) { face.PersonId = thisPerson.Id; } await AzureDatabaseService.UploadFaceInfo(thisPerson.Id, addFaceList); foreach (Face face in deleteFaceList) { await AzureDatabaseService.DeleteFace(face); } //Reload Persons List loadPersonsAndCheckEnquiry(); //Add a Person Finished! progressDialog.Content = "Add a Person Finished !"; progressDialog.IsPrimaryButtonEnabled = true; } //end result == 1 } //end internetConnection initializePersonInfoDialog(); }//end addPersonButton_Click
private async void loadPersonsAndCheckEnquiry() { Persons.Clear(); ObservableCollection <Person> persons = await AzureDatabaseService.GetPersonList(PatientId); foreach (Person person in persons) { Persons.Add(person); } //Check the unfinished Stranger Warning Enquiry unfinishedWarningList = await AzureDatabaseService.GetUnfinishedWarningList(PatientId); if (unfinishedWarningList.Count > 0) { WarningImage.Visibility = Visibility.Visible; } }
/// <summary> /// Retrieves the count of detected faces /// </summary> /// <param name="faces">The list of detected faces from the FaceDetected event of the effect</param> private async void CountDetectedFaces(IReadOnlyList <DetectedFace> faces) { FaceCount = $"{_detectionString} {faces.Count.ToString()}"; // If we detect any faces, kill our no faces timer if (faces.Count != 0) { if (_noFacesTimer != null) { _noFacesTimer.Dispose(); } } // Otherwise, if we are filtering and don't have a timer else if (_currentlyFiltered && (_noFacesTimer == null)) { // Create a callback TimerCallback noFacesCallback = (object stateInfo) => { _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { OnFilterOnFace(_unfilteredName); _noFacesTimer = null; }); _noFacesTimer.Dispose(); }; // Set our timer _noFacesTimer = new Timer(noFacesCallback, null, NoFacesTime, Timeout.Infinite); } // We are also going to take an image the first time that we detect exactly one face. // Sidenote - to avoid a race-condition, I had to use a boolean. Just checking for _faceCaptureStill == null could produce an error. if ((faces.Count == 1) && !_holdForTimer) // && !_currentlyFiltered { // Kick off the timer so we don't keep taking pictures, but will resubmit if we are not filtered _holdForTimer = true; //MainPage.isOnTime = false; // Take the picture _faceCaptureStill = await ApplicationData.Current.LocalFolder.CreateFileAsync("FaceDetected.jpg", CreationCollisionOption.ReplaceExisting); await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), _faceCaptureStill); if (((App)Application.Current).AppSettings.FaceApiKey != "" && FacialSimilarity.InitialTrainingPerformed) { var UserName = await FacialSimilarity.CheckForUserAsync(new Uri("ms-appdata:///local/FaceDetected.jpg")); if (UserName != "") { OnFilterOnFace(UserName); } else //strange face is detected { #region a strange face is detected //Voice Feedback //await MainPage._speechManager.SpeakAsync("Stranger! Sending the enquiry", MainPage.mediaElement); //Stranger Notice MainPage.thisPhrase = "stranger! Sending the enquiry!"; //stranger1 //Create a new Person thisPerson = new Person(); thisPerson.Name = "stranger"; thisPerson.FriendlyName = "stranger"; thisPerson.Relation = ""; thisPerson.PatientId = MainPage.PatientId; await AzureDatabaseService.UploadPersonInfo(thisPerson); thisPerson = new Person(); thisPerson = await AzureDatabaseService.GetLatestPerson(); thisPerson.FriendlyName += thisPerson.Id; await AzureDatabaseService.UploadPersonInfo(thisPerson); //Create a new Face thisFace = new Face(); // Prepare the captured image StorageFile newImageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("FaceDetected.jpg"); //StorageFolder newPersonFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(("Users\\" + thisPerson.FriendlyName), CreationCollisionOption.OpenIfExists); //await newImageFile.CopyAsync(newPersonFolder, "ProfilePhoto.jpg", NameCollisionOption.ReplaceExisting); string faToken = null; IRandomAccessStream irandom = await newImageFile.OpenAsync(FileAccessMode.Read); faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(newImageFile); thisFace.Image = new BitmapImage(); await thisFace.Image.SetSourceAsync(irandom); thisFace.ImageToken = faToken; thisFace.IsDefault = true; //Upload the Face //addFaceList.Add(thisFace); await AzureDatabaseService.UploadOneFaceInfo(thisPerson.Id, thisFace); //addFaceList.Clear(); thisFace = new Face(); thisFace = await AzureDatabaseService.GetLatestFace(); ObservableCollection <Face> newFaces = new ObservableCollection <Face>(); newFaces.Add(thisFace); MainPage.Persons.Add(thisPerson); //MainPage.Faces.Add(newFaces); //Upload the image //await AzureBlobService.UploadImageFromImageToken(faToken, thisFace.Id + ".jpg"); Face updatedFace = await AzureDatabaseService.UpdateFaceImageAddress(thisFace); thisFace = updatedFace; await AzureDatabaseService.UpdatePersonDefaultImageAddress(thisPerson.Id, thisFace); thisPerson = await AzureDatabaseService.GetLatestPerson(); MainPage.Persons.Add(thisPerson); //Upload a Stranger Warning Enquiry thisWarning.PersonId = thisPerson.Id; await AzureDatabaseService.UploadWarning(thisWarning); // Update the profile picture for the person //await FacialSimilarity.AddTrainingImageAsync(thisPerson.FriendlyName, new Uri($"ms-appdata:///local/Users/{thisPerson.FriendlyName}/ProfilePhoto.jpg")); AddNewPersonFromDB(thisPerson, newFaces); MainPage.thisPhrase = "Stranger! Be careful!"; //stranger2 //StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Media"); //StorageFile file = await folder.GetFileAsync("dong.wav"); //var soundStream = await file.OpenAsync(FileAccessMode.Read); //MainPage.mediaElement.SetSource(soundStream, file.ContentType); //MainPage.mediaElement.Play(); //await MainPage._speechManager.SpeakAsync("Stranger", MainPage.mediaElement); ////Perform initialization for facial detection. //await FacialSimilarity.TrainDetectionAsync(); #endregion } } // Allow the camera to take another picture in 10 seconds TimerCallback callback = (Object stateInfo) => { // Now that the timer is expired, we no longer need to hold // Nothing else to do since the timer will be restarted when the picture is taken _holdForTimer = false; if (_pictureTimer != null) { _pictureTimer.Dispose(); } }; _pictureTimer = new Timer(callback, null, 5000, Timeout.Infinite); }//end if ((faces.Count == 1) && !_holdForTimer && !_currentlyFiltered) }
private async void testInternetConnection() { //Test Internet Connection try { //showProgressDialog("Checking the Internet Connection..."); //progressDialog.Title = "Processing: "; //progressDialog.PrimaryButtonText = "Ok"; statusTextBlock.Text = "Checking the Internet Connection..."; Persons.Clear(); ObservableCollection <Person> persons = await AzureDatabaseService.GetPersonList(PatientId); foreach (Person person in persons) { Persons.Add(person); } //Check the unfinished Stranger Warning Enquiry unfinishedWarningList = await AzureDatabaseService.GetUnfinishedWarningList(PatientId); if (unfinishedWarningList.Count > 0) { WarningImage.Visibility = Visibility.Visible; } } catch (System.Net.Http.HttpRequestException) { internetConnection = false; statusTextBlock.Text = " "; showProgressDialog("Internet Connection Error! Please check your Internet connection."); progressDialog.Title = "Internet Connection Error!"; progressDialog.PrimaryButtonText = "Ok, I know"; progressDialog.IsPrimaryButtonEnabled = true; await progressDialog.ShowAsync(); return; //Test Internet Connection Again //testInternetConnection(); } //Set up the timer to check Stranger Warning Enquiry CheckEnquiryTimer = ThreadPoolTimer.CreatePeriodicTimer(async(source) => { //t++; //for testing //Check the unfinished Stranger Warning Enquiry unfinishedWarningList = await AzureDatabaseService.GetUnfinishedWarningList(PatientId); // Update the UI thread by using the UI core dispatcher. await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { //testTextBlock.Text = t.ToString(); //for testing if (unfinishedWarningList.Count > 0) { WarningImage.Visibility = Visibility.Visible; } }); }, checkEnquiryTimeSpan); internetConnection = true; statusTextBlock.Text = "Internet Connection Success!"; //progressDialog.Content = "Internet Connection Success!"; //progressDialog.IsPrimaryButtonEnabled = true; return; }
}//end addPersonButton_Click private async void WarningImage_Tapped(object sender, TappedRoutedEventArgs e) { //get the stranger info thisPerson = await AzureDatabaseService.GetOnePersonFromId(unfinishedWarningList[0].PersonId); defaultImage.Source = await AzureBlobService.DisplayImageFile(thisPerson.DefaultImageAddress); familiarRadioButton.IsChecked = thisPerson.IsFamiliar; strangeRadioButton.IsChecked = !thisPerson.IsFamiliar; //Update Faces Faces.Clear(); ObservableCollection <Face> faces = await AzureDatabaseService.GetFaceList(thisPerson.Id); foreach (Face face in faces) { face.Image = await AzureBlobService.DisplayImageFile(face.ImageAddress); Faces.Add(face); } var result = await PersonDialog.ShowAsync(); // Value 1 indicates primary button was selected by the user, which modify the Person if ((int)result == 1) { //Enable the Update of Person Info //Apply the Data showProgressDialog("Apply the Data..."); thisPerson.Name = PersonNameInput.Text; thisPerson.Relation = PersonRelationInput.Text; thisPerson.RiskFactor = (int)riskSlider.Value; //Upload Person Info progressDialog.Content = "Update Person Info..."; await AzureDatabaseService.UpdatePersonInfoWithId(thisPerson); //Upload Face Info progressDialog.Content = "Upload Faces and Images..."; foreach (Face face in addFaceList) { face.PersonId = thisPerson.Id; } await AzureDatabaseService.UploadFaceInfo(thisPerson.Id, addFaceList); foreach (Face face in deleteFaceList) { await AzureDatabaseService.DeleteFace(face); } //TODO: Cannot update the default image address in the Person //Operate the Enquiry Info progressDialog.Content = "Operate the Enquiry Info..."; Warning thisWarning = unfinishedWarningList[0]; thisWarning.IsFinished = true; thisWarning.IsFamiliar = thisPerson.IsFamiliar; await AzureDatabaseService.UpdateWarningEnquiryWithId(thisWarning); //Reload Persons List loadPersonsAndCheckEnquiry(); //Add a Person Finished! progressDialog.Content = "Operate the Enquiry Finished !"; progressDialog.IsPrimaryButtonEnabled = true; }//end result == 1 initializePersonInfoDialog(); }
private async void personGridView_ItemClick(object sender, ItemClickEventArgs e) { //Update Person Info thisPerson = e.ClickedItem as Person; familiarRadioButton.IsChecked = thisPerson.IsFamiliar; strangeRadioButton.IsChecked = !thisPerson.IsFamiliar; PersonNameInput.Text = thisPerson.Name; PersonRelationInput.Text = thisPerson.Relation; if (thisPerson.DefaultImageAddress != null) { defaultImage.Source = thisPerson.DefaultIcon; //await AzureBlobService.DisplayImageFile(thisPerson.DefaultImageAddress); } else { defaultImage.Source = nullBitmapImage; } riskSlider.Value = thisPerson.RiskFactor; //Update Faces Faces.Clear(); ObservableCollection <Face> faces = await AzureDatabaseService.GetFaceList(thisPerson.Id); foreach (Face face in faces) { face.Image = await AzureBlobService.DisplayImageFile(face.ImageAddress); Faces.Add(face); } //Show the Person Info Dialog var result = await PersonDialog.ShowAsync(); // Value 1 indicates primary button was selected by the user, which modify a new Person if ((int)result == 1) { //Enable the Update of Person Info //Apply the Data showProgressDialog("Apply the Data..."); thisPerson.Name = PersonNameInput.Text; thisPerson.Relation = PersonRelationInput.Text; thisPerson.RiskFactor = (int)riskSlider.Value; //Upload Person Info progressDialog.Content = "Update Person Info..."; await AzureDatabaseService.UpdatePersonInfoWithId(thisPerson); //Upload Face Info progressDialog.Content = "Upload Faces and Images..."; foreach (Face face in addFaceList) { face.PersonId = thisPerson.Id; Faces.Remove(face); } ObservableCollection <Face> newAddFaceList = await AzureDatabaseService.UploadFaceInfo(thisPerson.Id, addFaceList); foreach (Face face in addFaceList) { Faces.Add(face); } foreach (Face face in deleteFaceList) { await AzureDatabaseService.DeleteFace(face); } try { await AzureDatabaseService.UpdateFaceIsDefault(thisPerson.Id, Faces); } catch { } //Reload Persons List loadPersonsAndCheckEnquiry(); //Add a Person Finished! progressDialog.Content = "Update a Person Finished !"; progressDialog.IsPrimaryButtonEnabled = true; }//end result == 1 initializePersonInfoDialog(); deletePersonButton.IsEnabled = true; }
/// <summary> /// Test Internet Connection and Load Persons and Faces /// </summary> private async void testInternetConnection() { //Test Internet Connection try { showProgressDialog("Checking the Internet Connection and Loading the data..."); progressDialog.Title = "Processing: "; progressDialog.PrimaryButtonText = "Ok"; //statusTextBlock.Text = "Checking the Internet Connection..."; //Get Person List for this patient Persons.Clear(); ObservableCollection <Person> persons = await AzureDatabaseService.GetPersonList(PatientId); //statusTextBlock.Text = persons.Count + " Persons: "; //Clear Local User Folder StorageFolder userFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(("Users\\"), CreationCollisionOption.OpenIfExists); await userFolder.DeleteAsync(); userFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(("Users\\"), CreationCollisionOption.OpenIfExists); //Perform initialization for facial detection. await FacialSimilarity.TrainDetectionAsync(); //Download each person foreach (Person person in persons) { //Update Info person.DefaultIcon = await AzureBlobService.DisplayImageFile(person.DefaultImageAddress); Persons.Add(person); //Get Face List for each person ObservableCollection <Face> faces = await AzureDatabaseService.GetFaceList(person.Id); foreach (Face face in faces) { face.Image = await AzureBlobService.DisplayImageFile(face.ImageAddress); } Faces.Add(faces); AddNewPersonFromDB(person, faces); //statusTextBlock.Text += faces.Count + " faces "; } } catch (System.Net.Http.HttpRequestException) { internetConnection = false; //statusTextBlock.Text = " "; //showProgressDialog("Internet Connection Error! Please check your Internet connection."); progressDialog.Title = "Internet Connection Error!"; progressDialog.PrimaryButtonText = "Ok, I know"; progressDialog.IsPrimaryButtonEnabled = true; //await progressDialog.ShowAsync(); return; //Test Internet Connection Again //testInternetConnection(); } internetConnection = true; //statusTextBlock.Text = "Internet Connection Success!"; progressDialog.Content = "Success!"; progressDialog.IsPrimaryButtonEnabled = true; return; }