Пример #1
0
        public async Task OnDelete()
        {
            var ids = View.SelectedBotIds;

            if (IsValid(ids))
            {
                var dr = _mbs.ShowQuestion($"Do you really want to delete {ids.Count} Bots?");
                if (dr == DialogResult.Yes)
                {
                    var cancellationTokenSource = new CancellationTokenSource();
                    var loadingView             = new ProgressView.ProgressView("Bots are now being deleted", cancellationTokenSource, ids.Count);
                    loadingView.Show(View);

                    var botMgr = new BotManager(_keys, _logger);

                    int i = 0;
                    foreach (var botId in ids)
                    {
                        i++;
                        loadingView.SetProgress(i);

                        if (cancellationTokenSource.IsCancellationRequested)
                        {
                            break;
                        }

                        var res = await botMgr.DeleteBot(botId);

                        if (res.IsSuccess)
                        {
                            _logger.LogInformation($"Bot {botId} deleted");
                        }
                        else
                        {
                            _logger.LogError($"Could not delete Bot {botId}. Reason: {res.Error}");
                        }
                    }

                    loadingView.Close();
                    if (cancellationTokenSource.IsCancellationRequested)
                    {
                        _logger.LogInformation("Operation cancelled");
                        _mbs.ShowError("Operation cancelled!", "");
                    }
                    else
                    {
                        _mbs.ShowInformation("Delete finished. See output section for details.");
                    }

                    _logger.LogInformation("Refreshing Bots");
                    await RefreshBots();
                }
            }
        }