Exemple #1
0
        private async Task <string> ShowDialog(RContext[] contexts, string message, MessageButtons buttons, CancellationToken ct)
        {
            TaskUtilities.AssertIsOnBackgroundThread();

            MessageButtons input = await _callbacks.ShowDialog(contexts, message, buttons, ct);

            ct.ThrowIfCancellationRequested();

            string response;

            switch (input)
            {
            case MessageButtons.No:
                response = "N";
                break;

            case MessageButtons.Cancel:
                response = "C";
                break;

            case MessageButtons.Yes:
                response = "Y";
                break;

            default: {
                var error = Invariant($"YesNoCancel: callback returned an invalid value: {input}");
                Trace.Fail(error);
                throw new InvalidOperationException(error);
            }
            }
            return(response);
        }
Exemple #2
0
        private async Task ShowDialog(Message request, bool allowEval, MessageButtons buttons, CancellationToken ct)
        {
            TaskUtilities.AssertIsOnBackgroundThread();

            request.ExpectArguments(2);
            var contexts = GetContexts(request);
            var s        = request.GetString(1, "s", allowNull: true);

            MessageButtons input;

            try {
                _canEval = allowEval;
                input    = await _callbacks.ShowDialog(contexts, s, _canEval, buttons, ct);
            } finally {
                _canEval = false;
            }

            ct.ThrowIfCancellationRequested();

            string response;

            switch (input)
            {
            case MessageButtons.No:
                response = "N";
                break;

            case MessageButtons.Cancel:
                response = "C";
                break;

            case MessageButtons.Yes:
                response = "Y";
                break;

            default: {
                FormattableString error = $"YesNoCancel: callback returned an invalid value: {input}";
                Trace.Fail(Invariant(error));
                throw new InvalidOperationException(Invariant(error));
            }
            }

            await RespondAsync(request, ct, response);
        }