/// <summary> /// Function to delete a result image /// </summary> /// <param name="vm">The view model of the result image which should be removed</param> private void DeleteImage(ResultImageViewModel vm) { ResultImageViewModel[] arr = new ResultImageViewModel[1]; arr[0] = vm; DeleteImageAsync(arr); }
/// <summary> /// Async function which will be invoked when there is an event triggered inside the worker class. /// </summary> /// <param name="sender">Worker instance which triggered the event</param> /// <param name="deepDreamEventArgs">Arguments passed by the event</param> private async void ProcessEventHandlerAsync(object sender, DeepDreamEventArgs deepDreamEventArgs) { switch (deepDreamEventArgs.Event) { case DeepDreamEvents.TotalProgress: //Update for the progress double value; if (Double.TryParse(deepDreamEventArgs.Status, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value)) { this.OverallProgress = value; } if (PreparingProcess) { progresStopwatch.Restart(); } PreparingProcess = false; break; case DeepDreamEvents.ProcessStarted: //Initializing a new process CurrentSeriesId = System.Guid.NewGuid().ToString(); PreparingProcess = true; Running = true; progressRemainingTimeSpan = TimeSpan.Zero; progressstring = String.Empty; timestring = String.Empty; firstIteration = true; break; case DeepDreamEvents.Progress: break; case DeepDreamEvents.StepStarted: //prepare a result image view model for a result image currentResultVm = new ResultImageViewModel(DeleteImage, mainWindowActions.ShowDetailsWindow, this.OnPropertyChanged) { SeriesId = CurrentSeriesId, Intensity = WorkImageIntensity, Octave = WorkImageOctave, SelectedModelParameter = this.SelectedModelParameter, OriginalImage = FinalWorkImage, StyleImage = StyleImage, Mode = (Modes)this.Mode, Name = Properties.Resources.info_wait }; ResultImages.AddOnUi(currentResultVm); break; case DeepDreamEvents.StepComplete: //Load the reult image into the prepared view model if (currentResultVm == null) { return; } currentResultVm.Done = true; currentResultVm.Name = $"{Properties.Resources.param_picture} {deepDreamEventArgs.Status}"; int iteration = 0; if (int.TryParse(deepDreamEventArgs.Status, out iteration)) { currentResultVm.Iteration = iteration; } currentResultVm = null; firstIteration = false; UpdateProgressTime(); break; case DeepDreamEvents.AllComplete: break; case DeepDreamEvents.SavedImage: break; case DeepDreamEvents.Error: //Something went wrong await ShowDialogAsync(Properties.Resources.info_error, deepDreamEventArgs.Status, MessageDialogStyle.Affirmative); break; case DeepDreamEvents.ProcessDone: //Everything is done ProcessStatusText = Properties.Resources.action_process_finished; OverallProgress = 0; Running = false; PreparingProcess = false; ResultImages = resultImages.Where(ri => ri.Done).ToObservableCollection(); //Delete Undone Images break; default: break; } //Update the ui UpdateProgressText(true); currentResultVm?.ProcessEventHandlerAsync(deepDreamEventArgs); ForceCommandEvaluation(); }