public ActionResult EvalInput(string userInput)
        {
            int             userInt = 0;
            UserInputResult uir     = new UserInputResult()
            {
                InputValue = userInput, FizzBuzzValue = "Invlaid Input", IsPalindrome = false
            };

            // Check for FizzBuzz (is input an integer)
            if (int.TryParse(userInput, out userInt))
            {
                uir.FizzBuzzValue = userInt.ToString();
                string FizzBuzzResult = "";

                if ((userInt % 3) == 0)
                {
                    FizzBuzzResult = "Fizz";
                }

                if ((userInt % 5) == 0)
                {
                    FizzBuzzResult += "Buzz";
                }

                if (!String.IsNullOrEmpty(FizzBuzzResult))
                {
                    uir.FizzBuzzValue = FizzBuzzResult;
                }
            }

            // Check if input is a palindrome
            uir.IsPalindrome = Utilities.GeneralUtilities.EvaluateForPalindrome(userInput.Replace(" ", string.Empty));

            return(View(uir));
        }
Esempio n. 2
0
        /// <inheritdoc />
        public Task <UserInputResult> GetUserInputAsync(string title, string message, UserInputOption options, UserInputResult defaultResult)
        {
            var scheduler = TaskScheduler.FromCurrentSynchronizationContext();

            return(Task.Factory.StartNew(
                       () =>
            {
                MessageBoxResult result = MessageBox.Show(Application.Current.MainWindow, message, title, (MessageBoxButton)options, MessageBoxImage.None, (MessageBoxResult)defaultResult);
                return (UserInputResult)result;
            },
                       CancellationToken.None,
                       TaskCreationOptions.None,
                       scheduler));
        }
Esempio n. 3
0
 public DialogMessageActionHandledEventArgs(UserInputResult actionResult, bool shouldCloseDialog)
 {
     ActionResult      = actionResult;
     ShouldCloseDialog = shouldCloseDialog;
 }
Esempio n. 4
0
        /// <inheritdoc />
        public async Task <UserInputResult> GetUserInputAsync(string title, string message, UserInputOption options, UserInputResult defaultResult)
        {
            var           resources = this.GetResourceLoader();
            MessageDialog dialog    = new MessageDialog(message, title);

            switch (options)
            {
            case UserInputOption.Ok:
                dialog.Commands.Add(new UICommand(resources.GetString("OK"))
                {
                    Id = UserInputResult.Ok
                });
                break;

            case UserInputOption.OkCancel:
                dialog.Commands.Add(new UICommand(resources.GetString("OK"))
                {
                    Id = UserInputResult.Ok
                });
                dialog.Commands.Add(new UICommand(resources.GetString("Cancel"))
                {
                    Id = UserInputResult.Cancel
                });
                dialog.CancelCommandIndex = 1;

                if (defaultResult == UserInputResult.Ok)
                {
                    dialog.DefaultCommandIndex = 0;
                }
                else
                {
                    dialog.DefaultCommandIndex = 1;
                }

                break;

            case UserInputOption.YesNo:
                dialog.Commands.Add(new UICommand(resources.GetString("Yes"))
                {
                    Id = UserInputResult.Yes
                });
                dialog.Commands.Add(new UICommand(resources.GetString("No"))
                {
                    Id = UserInputResult.No
                });
                dialog.CancelCommandIndex = 1;

                if (defaultResult == UserInputResult.Yes)
                {
                    dialog.DefaultCommandIndex = 0;
                }
                else
                {
                    dialog.DefaultCommandIndex = 1;
                }

                break;

            case UserInputOption.YesNoCancel:
                dialog.Commands.Add(new UICommand(resources.GetString("Yes"))
                {
                    Id = UserInputResult.Yes
                });
                dialog.Commands.Add(new UICommand(resources.GetString("No"))
                {
                    Id = UserInputResult.No
                });
                dialog.Commands.Add(new UICommand(resources.GetString("Cancel"))
                {
                    Id = UserInputResult.Cancel
                });
                dialog.CancelCommandIndex = 2;

                switch (defaultResult)
                {
                case UserInputResult.Yes:
                    dialog.DefaultCommandIndex = 0;
                    break;

                case UserInputResult.No:
                    dialog.DefaultCommandIndex = 1;
                    break;

                default:
                    dialog.DefaultCommandIndex = 2;
                    break;
                }

                break;
            }

            IUICommand command = await dialog.ShowAsync();

            return((UserInputResult)command.Id);
        }
Esempio n. 5
0
        static string GetImgSource(MessageType mt)
        {
            string name = mt switch
            {
                MessageType.Generic => "Generic",
                MessageType.Information => "Generic",
                MessageType.Error => "Error",
                MessageType.Warning => "Info",
                MessageType.Question => "Question",
                MessageType.Success => "Happy",
                _ => "Generic"
            };

            return($"{AppViewModel.WPFApplicationBasePath}Img/MessageIcons/{name}.png");
        }

        // Create the message actions
        var actions = new List <DialogMessageActionViewModel>();

        // Create a cancel action if available
        if (allowCancel)
        {
            actions.Add(new DialogMessageActionViewModel()
            {
                DisplayText        = Resources.Cancel,
                DisplayDescription = Resources.Cancel,
                IsCancel           = true,
                ActionResult       = new UserInputResult(),
            });
        }

        // Add additional actions
        actions.AddRange(additionalActions);

        // Create the default action
        actions.Add(new DialogMessageActionViewModel()
        {
            DisplayText        = Resources.Ok,
            DisplayDescription = Resources.Ok,
            IsDefault          = true,
            ActionResult       = new UserInputResult()
            {
                CanceledByUser = false
            },
        });

        // Run on the UI thread
        return(await Application.Current.Dispatcher.Invoke(async() =>
        {
            // Create the view model
            var vm = new DialogMessageViewModel()
            {
                MessageText = message,
                Title = headerMessage,
                MessageType = messageType,
                DialogImageSource = (ImageSource) new ImageSourceConverter().ConvertFromString(GetImgSource(messageType)),
                DialogActions = actions,
                DefaultActionResult = new UserInputResult(),
            };

            // Create the message box
            var dialog = new DialogMessageBox(vm);

            // Show the dialog and get the result
            UserInputResult result = await Dialog.ShowDialogWindowAsync(dialog);

            // Return the result
            return !result.CanceledByUser;
        }));
    }