Пример #1
0
        public async Task <IActionResult <TResult> > BusyTask <TResult>(BusyDialogOptions <TResult> options)
        {
            var controller = await _dialog.ShowProgressAsync(options.Context,
                                                             options.Title,
                                                             options.Message,
                                                             options.CancellationToken != default(CancellationToken),
                                                             options);

            var progression = new Progress <Progression>(p =>
            {
                if (p.Message != null)
                {
                    controller.SetMessage(p.Message);
                }
                if (p.Value == null)
                {
                    controller.SetIndeterminate();
                }
                else
                {
                    controller.SetProgress(p.Value.Value);
                }
            });

            controller.SetIndeterminate();
            IActionResult <TResult> ret;

            try
            {
                ret = _arf.SuccessAction(await options.Task(progression, options.CancellationToken), options.Title);
            }
            catch (Exception e) when(e.IsCancellation())
            {
                await _dialog.ShowMessageAsync(options.Context, options.Title, "Cancelled");

                ret = _arf.CancelAction <TResult>(options.Title);
            }
            catch (Exception e)
            {
                if (!(e is IDoNotLog))
                {
                    options.Log?.ErrorException($"Error while processing {options.Title} in {options.Context.GetType().FullName}", e);
                }
                await _dialog.ShowMessageAsync(options.Context, $"Error while {options.Title}", e.Message);

                ret = _arf.ErrorAction <TResult>(e, options.Title);
            }

            await controller.CloseAsync();

            return(ret);
        }