Exemplo n.º 1
0
        /// <summary>
        /// Async function which will be invoked if there is an event happing in the main view and this instance of result image is involved.
        /// Handel the event arguments
        /// </summary>
        /// <param name="deepDreamEventArgs">Arguments of the event</param>
        public async void ProcessEventHandlerAsync(DeepDreamEventArgs deepDreamEventArgs)
        {
            switch (deepDreamEventArgs.Event)
            {
            case DeepDreamEvents.TotalProgress:
                break;

            case DeepDreamEvents.ProcessStarted:
                break;

            case DeepDreamEvents.Progress:
                //If there is a progress update, the result image progress will be updated
                double value;
                if (Double.TryParse(deepDreamEventArgs.Status, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value))
                {
                    this.Progress = value;
                }
                break;

            case DeepDreamEvents.StepStarted:
                break;

            case DeepDreamEvents.StepComplete:
                break;

            case DeepDreamEvents.AllComplete:
                break;

            case DeepDreamEvents.SavedImage:
                //If there is a result image saved by the process, load it
                Image = await ImageModel.LoadImageAsync(deepDreamEventArgs.Status, true);

                Loading = false;
                Done    = true;
                break;

            case DeepDreamEvents.Error:
                break;

            case DeepDreamEvents.ProcessDone:
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        /// <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();
        }