private async void OnDownloadStateChanged(object sender, ProgressStateEventArgs e)
        {
            var model = (sender as FrameworkElement)?.DataContext as DownloaderModel;

            switch (e.NewValue)
            {
            case ProgressState.Ready:
                break;

            case ProgressState.Started:
                try
                {
                    await model?.StartDownloadAsync();
                }
                catch (OperationCanceledException)
                {
                    //do nothing
                }
                break;

            case ProgressState.Completed:
                break;

            case ProgressState.Faulted:
                break;

            case ProgressState.Paused:
                model?.Stop();
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        private async void FaultProgressControlStateChanged(object sender, ProgressStateEventArgs e)
        {
            switch (e.NewValue)
            {
            case ProgressState.Ready:
                _faultTestService          = new TestService();
                FaultProgressControl.Value = FaultProgressControl.Minimum;
                break;

            case ProgressState.Started:
                try
                {
                    _faultTestService.IsPaused         = false;
                    _faultTestService.ProgressChanged += (s, args) => { FaultProgressControl.Value = args; };
                    await _faultTestService.Start(true);

                    if (_faultTestService.IsCompleted)
                    {
                        FaultProgressControl.State = ProgressState.Completed;
                    }
                }
                catch (Exception)
                {
                    FaultProgressControl.State = ProgressState.Faulted;
                }
                break;

            case ProgressState.Paused:
                _faultTestService.IsPaused = true;
                break;

            case ProgressState.Completed:
                break;

            case ProgressState.Faulted:
                break;
            }
        }