Пример #1
0
        /// <summary>
        /// 時間のかかる処理を実行します。
        /// </summary>
        /// <param name="method">時間のかかる処理</param>
        /// <param name="settings">設定情報</param>
        public async Task ShowProgressAsync(Func <ProgressDialogController, Task> method, MetroDialogSettings settings = null)
        {
            var pdc = await DialogCoordinator.ShowProgressAsync(this, null, null, false, settings);

            await method(pdc);

            await pdc.CloseAsync();
        }
Пример #2
0
        protected async Task OnLoadingAsync(Func <CancellationToken, Task> func)
        {
            var dialog = await DialogCoordinator.ShowProgressAsync(DialogContext, LoadingTitle,
                                                                   LoadingDescription).ConfigureAwait(false);

            try
            {
                await func.Invoke(Ct).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                await ErrorAccrued(ex);
            }
            finally
            {
                await dialog.CloseAsync();
            }
        }
Пример #3
0
        private async void CheckForUpdates()
        {
            await Task.Delay(3000);

            while (!DialogCoordinatorRegistered)
            {
                await Task.Delay(25);
            }

            if (await _updateHandler.IsUpdateAvailable())
            {
                IsUpdating = true;
                var result = await
                             DialogCoordinator.ShowMessageAsync(this, "Update available", $"An update is available.{Environment.NewLine}{Environment.NewLine}Current installed version: {_updateHandler.LocalVersion}.{Environment.NewLine}Available version: {_updateHandler.RemoteVersion}{Environment.NewLine}{Environment.NewLine}Do you want to install this update now?",
                                                                MessageDialogStyle.AffirmativeAndNegative);

                if (result == MessageDialogResult.Affirmative)
                {
                    _updateHandler.UpdateDownloadProgressChanged += (sender, args) =>
                    {
                        _progressController.SetProgress(args.ProgressPercentage / 100.0);
                        _progressController.SetMessage($"Downloading...{Environment.NewLine}Received: {args.MegabytesReceived} MB{Environment.NewLine}Total Size: {args.MegabytesToReceive} MB");
                    };

                    _updateHandler.UpdateDownloadCompleted += async(sender, args) =>
                    {
                        if (args.Aborted)
                        {
                            _progressController?.SetMessage("Failed to download update");
                        }
                        else
                        {
                            _progressController?.SetMessage("Completed!");
                            _progressController?.SetIndeterminate();
                        }

                        await Task.Delay(3000);

                        try
                        {
                            await _progressController?.CloseAsync();
                        }
                        catch (Exception)
                        {
                            // ignored
                        }

                        IsUpdating = false;
                    };

                    var task = _updateHandler.DownloadUpdate();

                    _progressController = await DialogCoordinator.ShowProgressAsync(this, "Downloading update", "", true);

                    _progressController.Canceled += (sender, args) =>
                    {
                        _progressController.CloseAsync();
                        _updateHandler.CancelDownload();
                        IsUpdating = false;
                    };
                }
                else
                {
                    IsUpdating = false;
                }
            }
        }