// When drone finds target, function sets ImageBox to UI. void RetrieveImage() { var Network = new UI_Network(); myImage = "/*set to the incoming image**/"; person_found.Source = setImage(); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { FTPImageTransfer transfer = null; //new FTPImageTransfer("ftp://192.168.168.1", "drone", "NEVERAGAIN"); UI_Network comms = new UI_Network(); //begins the drone search process by having the user select an image of //the target if (!isSearching) { this.Dispatcher.Invoke((Action)(() => { status_box.Foreground = Brushes.Yellow; status_box.Content = "User Selecting Target. "; status_label.Foreground = Brushes.Yellow; status_label.Content = "Standby"; })); // Makes filepicker window object. var openFileDialog = new OpenFileDialog(); // Only allows Images. openFileDialog.Filter = "Image Files (*.png, *.jpg,*.bmp)|*.png;*.jpg;*.bmp"; openFileDialog.FilterIndex = 1; // Sets default directory when opening. openFileDialog.InitialDirectory = @"C:\"; // Title of image picker window. openFileDialog.Title = "Select Image of person to be searched for"; bool? click_ok = openFileDialog.ShowDialog(); this.Dispatcher.Invoke((Action)(() => { // Sets variable myImage to the uploaded image. myImage = openFileDialog.FileName; // Sets image box to the image path in myImage. search_for_image.Source = setImage(); })); // Attempts to send user-selected image to server for drone search. try { if (click_ok == true) { // Makes a new FTP connection to the server. transfer = new FTPImageTransfer("ftp://192.168.168.1", "drone", "NEVERAGAIN"); // Uploads image with name of ui_image.png string name = "ui_image.png"; // Sends image file to server. transfer.Upload(openFileDialog.FileName, name); for (int i = 0; i <= 101; i++) { //Reports the progress of the upload. // Thread.Sleep(100); Testing the upload button backgroundWorker.ReportProgress(i); } comms.SendImage(name); comms.SendStart(); // Sets Dialog box's color and text with respect to the image upload result status_box.Foreground = Brushes.Green; if (comms.getUploadStatus()) status_box.Content = "Image succesfully uploaded, Searching for new target. "; else { status_box.Foreground = Brushes.Red; status_box.Content = "Image failed to upload, Drone not started. "; } status_label.Foreground = Brushes.Green; status_label.Content = "Active"; // Starts the timer, if user picks new target timer does not reset //if (!(stopwatch.Elapsed.Seconds > 0)) // stopwatch.Start(); // stopwatch.Stop(); //timer_label.Content = stopwatch.Elapsed; } else if (click_ok == false) { // Resets the upload fail/pass dialog box //status_box.Foreground = reset this.Dispatcher.Invoke((Action)(() => { status_box.Content = " "; status_label.Foreground = Brushes.Black; status_label.Content = "N/A"; })); } } catch (Exception ex) { Console.WriteLine(ex.InnerException); Console.WriteLine(ex.Message); Console.WriteLine(ex.TargetSite); this.Dispatcher.Invoke((Action)(() => { status_label.Foreground = Brushes.Red; status_label.Content = "Inactive"; })); } } else { } }