Esempio n. 1
0
        private async void Request(object sender, RoutedEventArgs e)
        {
            ErrorText.Visibility = Visibility.Collapsed;
            ForgotPasswordViewModel vm = new ForgotPasswordViewModel()
            {
                Email = EmailBox.Text
            };

            ValidationContext       validationContext = new ValidationContext(vm);
            List <ValidationResult> validationResults = new List <ValidationResult>();
            bool isValid = Validator.TryValidateObject(vm, validationContext, validationResults, true);

            if (isValid)
            {
                JObject result = await App.dataService.ForgotPassword(vm);

                if (result["success"].ToString() == "True")
                {
                    // Really, I tried to do it with x:Bind but the ui wouldn't update
                    EmailBox.IsReadOnly = true;
                    CodeBox.Visibility  = Visibility.Visible;
                    CodeBox.Focus(FocusState.Programmatic);
                    Border1.Visibility            = Visibility.Visible;
                    Message.Visibility            = Visibility.Visible;
                    PasswordBox.Visibility        = Visibility.Visible;
                    ConfirmPasswordBox.Visibility = Visibility.Visible;
                    ResetButton.Visibility        = Visibility.Visible;
                    RequestButton.Visibility      = Visibility.Collapsed;
                    ErrorText.Visibility          = Visibility.Collapsed;
                }
                else
                {
                    var test = result["errors"];
                    if (result["errors"] == null)
                    {
                        ErrorText.Text = "Error";
                    }
                    else
                    {
                        ErrorText.Text = result["errors"][0]["message"].ToString();
                    }
                    ErrorText.Visibility = Visibility.Visible;
                }
            }
            else
            {
                ErrorText.Text       = validationResults[0].ErrorMessage;
                ErrorText.Visibility = Visibility.Visible;
            }
        }
Esempio n. 2
0
        /* Color selected line */
        public void ColorSelLine(int offset)
        {
            return;

            if (colorRTB == null)
            {
                return;
            }

            int oldSel  = colorRTB.SelectionStart;
            int lineNum = colorRTB.GetLineFromCharIndex(oldSel);

            //HideSelection will hide the selection color when the RTB is not in focus
            colorRTB.HideSelection = true;
            CodeBox.Focus();

            ColorLine(lineNum + offset);

            colorRTB.Focus();
            colorRTB.SelectionStart  = oldSel;
            colorRTB.SelectionLength = 0;
        }
        public async Task ProcessLine(string line)
        {
            CodeBox.Focus();
            var lineIndex  = WindowBindings.CurrentLine - 2;
            var superIndex = 0;

            for (var i = 0; i < lineIndex + 1; i++)
            {
                if (i == 0)
                {
                    CodeBox.Select(0, _codeLines[i].Length + 2);
                    superIndex += _codeLines[i].Length + 2;
                }
                else
                {
                    CodeBox.Select(superIndex, _codeLines[i].Length + 2);
                    superIndex += _codeLines[i].Length + 2;
                }
            }
            if (line.Length == 0)
            {
                return;
            }
            var commandArgs = line.Split(new[] { ' ' }, 2);

            WindowBindings.CurrentInstruction = commandArgs[0];
            if (commandArgs.Length >= 2)
            {
                WindowBindings.CurrentInstructionData = commandArgs[1];
            }
            WindowBindings.CurrentInstructionBrush = new SolidColorBrush(BlueColor);
            if ((int)DelaySizer.Value > 10)
            {
                await Task.Delay((int)DelaySizer.Value);
            }
            WindowBindings.CurrentInstructionBrush = null;
            var args = new string[] { };

            if (commandArgs.Length >= 2)
            {
                args = commandArgs[1].Replace(" ", "").Split(',');
            }
            WindowBindings.DecoderBrush = new SolidColorBrush(BlueColor);
            if ((int)DelaySizer.Value > 10)
            {
                await Task.Delay((int)DelaySizer.Value);
            }
            WindowBindings.DecoderBrush = null;
            switch (commandArgs[0])
            {
            case "LOD":
                WindowBindings.AluRegister1      = "";
                WindowBindings.AluRegister2      = "";
                WindowBindings.AluRegister1Brush = new SolidColorBrush(BlueColor);
                WindowBindings.AluRegister2Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister1Brush = null;
                WindowBindings.AluRegister2Brush = null;
                WindowBindings.AluMethod         = "↓";
                WindowBindings.AluMethodBrush    = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush   = null;
                WindowBindings.Accumulator      = _memoryContainer.GetValue(args[0]);
                WindowBindings.AccumulatorBrush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AccumulatorBrush = null;
                break;

            case "STO":
                WindowBindings.AluRegister1      = "";
                WindowBindings.AluRegister2      = "";
                WindowBindings.AluRegister1Brush = new SolidColorBrush(BlueColor);
                WindowBindings.AluRegister2Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister1Brush = null;
                WindowBindings.AluRegister2Brush = null;
                WindowBindings.AluMethod         = "↑";
                WindowBindings.AluMethodBrush    = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                _memoryContainer.SetValue(args[0], WindowBindings.Accumulator);
                WindowBindings.AccumulatorBrush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AccumulatorBrush = null;
                break;

            case "ADD":
                WindowBindings.AluRegister1      = WindowBindings.Accumulator.ToString();
                WindowBindings.AluRegister1Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister1Brush = null;
                if (args.Length > 0 && args[0][0] == '#')
                {
                    WindowBindings.AluRegister2 = args[0].Remove(0, 1);
                }
                else
                {
                    WindowBindings.AluRegister2 = _memoryContainer.GetValue(args[0]).ToString();
                }
                WindowBindings.AluRegister2Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister2Brush = null;
                WindowBindings.AluMethod         = "+";
                WindowBindings.AluMethodBrush    = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                if (args.Length > 0 && args[0][0] == '#' && int.TryParse(args[0].Remove(0, 1), out var result))
                {
                    WindowBindings.Accumulator += result;
                }
                else
                {
                    WindowBindings.Accumulator += _memoryContainer.GetValue(args[0]);
                }
                WindowBindings.AccumulatorBrush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AccumulatorBrush = null;
                break;

            case "SUB":
                WindowBindings.AluRegister1      = WindowBindings.Accumulator.ToString();
                WindowBindings.AluRegister1Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    if ((int)DelaySizer.Value > 10)
                    {
                        await Task.Delay((int)DelaySizer.Value);
                    }
                }
                WindowBindings.AluRegister1Brush = null;
                if (args.Length > 0 && args[0][0] == '#')
                {
                    WindowBindings.AluRegister2 = args[0].Remove(0, 1);
                }
                else
                {
                    WindowBindings.AluRegister2 = _memoryContainer.GetValue(args[0]).ToString();
                }
                WindowBindings.AluRegister2Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister2Brush = null;
                WindowBindings.AluMethod         = "-";
                WindowBindings.AluMethodBrush    = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                if (args.Length > 0 && args[0][0] == '#' && int.TryParse(args[0].Remove(0, 1), out var result2))
                {
                    WindowBindings.Accumulator -= result2;
                }
                else
                {
                    WindowBindings.Accumulator -= _memoryContainer.GetValue(args[0]);
                }
                WindowBindings.AccumulatorBrush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AccumulatorBrush = null;
                break;

            case "MUL":
                WindowBindings.AluRegister1      = WindowBindings.Accumulator.ToString();
                WindowBindings.AluRegister1Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister1Brush = null;
                if (args.Length > 0 && args[0][0] == '#')
                {
                    WindowBindings.AluRegister2 = args[0].Remove(0, 1);
                }
                else
                {
                    WindowBindings.AluRegister2 = _memoryContainer.GetValue(args[0]).ToString();
                }
                WindowBindings.AluRegister2Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister2Brush = null;
                WindowBindings.AluMethod         = "*";
                WindowBindings.AluMethodBrush    = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                if (args.Length > 0 && args[0][0] == '#' && int.TryParse(args[0].Remove(0, 1), out var result3))
                {
                    WindowBindings.Accumulator *= result3;
                }
                else
                {
                    WindowBindings.Accumulator *= _memoryContainer.GetValue(args[0]);
                }
                WindowBindings.AccumulatorBrush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AccumulatorBrush = null;
                break;

            case "DIV":
                WindowBindings.AluRegister1      = WindowBindings.Accumulator.ToString();
                WindowBindings.AluRegister1Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister1Brush = null;
                if (args.Length > 0 && args[0][0] == '#')
                {
                    WindowBindings.AluRegister2 = args[0].Remove(0, 1);
                }
                else
                {
                    WindowBindings.AluRegister2 = _memoryContainer.GetValue(args[0]).ToString();
                }
                WindowBindings.AluRegister2Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister2Brush = null;
                WindowBindings.AluMethod         = "/";
                WindowBindings.AluMethodBrush    = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                try {
                    if (args.Length > 0 && args[0][0] == '#' && int.TryParse(args[0].Remove(0, 1), out var result4))
                    {
                        WindowBindings.Accumulator /= result4;
                    }
                    else
                    {
                        WindowBindings.Accumulator /= _memoryContainer.GetValue(args[0]);
                    }
                }
                catch {
                    MessageBox.Show(
                        $"Failed to execute line {WindowBindings.CurrentLine - 1}:{Environment.NewLine}Attempting to divide a number by 0{Environment.NewLine}\"{line}\"",
                        "Runtime exception", MessageBoxButton.OK, MessageBoxImage.Error
                        );
                }
                WindowBindings.AccumulatorBrush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AccumulatorBrush = null;
                break;

            case "JMP":
                WindowBindings.AluRegister1      = "";
                WindowBindings.AluRegister2      = "";
                WindowBindings.AluRegister1Brush = new SolidColorBrush(BlueColor);
                WindowBindings.AluRegister2Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister1Brush = null;
                WindowBindings.AluRegister2Brush = null;
                WindowBindings.AluMethod         = "↷";
                WindowBindings.AluMethodBrush    = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                WindowBindings.CurrentLine    = int.Parse(args[0]);
                break;

            case "JMZ":
                WindowBindings.AluRegister1      = "";
                WindowBindings.AluRegister2      = "";
                WindowBindings.AluRegister1Brush = new SolidColorBrush(BlueColor);
                WindowBindings.AluRegister2Brush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluRegister1Brush = null;
                WindowBindings.AluRegister2Brush = null;
                WindowBindings.AluMethod         = "↷";
                WindowBindings.AluMethodBrush    = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                if (WindowBindings.Accumulator == 0)
                {
                    WindowBindings.CurrentLine = int.Parse(args[0]);
                }
                break;

            case "HLT":
                WindowBindings.AluRegister1   = "";
                WindowBindings.AluRegister2   = "";
                WindowBindings.AluMethod      = "❌";
                WindowBindings.LinesBrush     = new SolidColorBrush(Colors.Red);
                WindowBindings.AluMethodBrush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                WindowBindings.IsRunning      = false;
                break;

            case "NOP":
                WindowBindings.AluRegister1 = "";
                WindowBindings.AluRegister2 = "";
                WindowBindings.AluMethod    = "";
                break;

            default:
                MessageBox.Show(
                    $"Failed to execute line {WindowBindings.CurrentLine - 1}:{Environment.NewLine}This command is not recognized{Environment.NewLine}\"{line}\"",
                    "Runtime exception", MessageBoxButton.OK, MessageBoxImage.Error
                    );
                WindowBindings.AluMethod      = "❌";
                WindowBindings.LinesBrush     = new SolidColorBrush(Colors.Red);
                WindowBindings.AluMethodBrush = new SolidColorBrush(BlueColor);
                if ((int)DelaySizer.Value > 10)
                {
                    await Task.Delay((int)DelaySizer.Value);
                }
                WindowBindings.AluMethodBrush = null;
                WindowBindings.IsRunning      = false;
                break;
            }
        }