Exemple #1
0
        private PrimesBigInteger IsGmpBigInteger(string s)
        {
            PrimesBigInteger ipt = null;

            validator.Value = s;
            Primes.WpfControls.Validation.ValidationResult res = validator.Validate(ref ipt);
            if (res != Primes.WpfControls.Validation.ValidationResult.OK)
            {
                log.Info(string.Format(rsc.proot_novalidnumber, new object[] { s, MIN.ToString(), MAX.ToString() }));
                return(null);
            }
            return(ipt);
        }
Exemple #2
0
        public PrimesBigInteger GetValue()
        {
            PrimesBigInteger value = null;

            ResetMessages();

            if (m_RbSelection == Selection.Free)
            {
                ValidateFreeInput(ref value);
            }
            else if (m_RbSelection == Selection.Calc)
            {
                ValidateCalcInput(ref value);
            }

            if (value != null)
            {
                SetButtonExecuteButtonEnabled(true);
                if (m_ValueValidators.ContainsKey(Value))
                {
                    IValidator <PrimesBigInteger> validator = m_ValueValidators[Value];
                    validator.Value = value.ToString();
                    Primes.WpfControls.Validation.ValidationResult result = validator.Validate(ref value);
                    if (result != Primes.WpfControls.Validation.ValidationResult.OK)
                    {
                        switch (result)
                        {
                        case Primes.WpfControls.Validation.ValidationResult.WARNING:
                            if (m_RbSelection == Selection.Calc)
                            {
                                InfoCalc(validator.Message, new TextBox[] { m_tbCalcBase, m_tbCalcExp, m_tbCalcFactor, m_tbCalcSum }, validator.HelpLink);
                            }
                            else
                            {
                                InfoFree(validator.Message, m_tbFree, validator.HelpLink);
                            }
                            SetButtonExecuteButtonEnabled(false);

                            break;

                        case Primes.WpfControls.Validation.ValidationResult.ERROR:
                            if (m_RbSelection == Selection.Calc)
                            {
                                ErrorCalc(validator.Message, new TextBox[] { m_tbCalcBase, m_tbCalcExp, m_tbCalcFactor, m_tbCalcSum }, validator.HelpLink);
                            }
                            else
                            {
                                ErrorFree(validator.Message, m_tbFree, validator.HelpLink);
                            }
                            SetButtonExecuteButtonEnabled(false);
                            break;

                        default:
                            break;
                        }
                        return(null);
                    }
                }
                foreach (IValidator <PrimesBigInteger> validator in this.m_SingleAdvisors[Value])
                {
                    if (validator.Validate(ref value) != Primes.WpfControls.Validation.ValidationResult.OK)
                    {
                        if (m_RbSelection == Selection.Free)
                        {
                            InfoFree(validator.Message, new TextBox[] { m_tbFree }, validator.HelpLink);
                        }
                        else if (m_RbSelection == Selection.Calc)
                        {
                            InfoFree(validator.Message, new TextBox[] { m_tbCalcFactor, m_tbCalcBase, m_tbCalcExp, m_tbCalcSum }, validator.HelpLink);
                        }
                        break;
                    }
                }
            }
            else
            {
                SetButtonExecuteButtonEnabled(false);
            }
            return(value);
        }
Exemple #3
0
        private void Execute(bool doExecute)
        {
            ClearLog();
            intervals.Clear();

            string _input = tbInput.Text;

            if (!string.IsNullOrEmpty(_input))
            {
                string[] input = _input.Trim().Split(',');
                if (input != null && input.Length > 0)
                {
                    foreach (string s in input)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            string[] _inputrange = s.Split(':');
                            if (_inputrange.Length == 1)
                            {
                                PrimesBigInteger ipt = null;
                                validator.Value = s;
                                Primes.WpfControls.Validation.ValidationResult res = validator.Validate(ref ipt);
                                if (res == Primes.WpfControls.Validation.ValidationResult.OK)
                                {
                                    if (ipt.IsPrime(10))
                                    {
                                        intervals.Add(new List <PrimesBigInteger> {
                                            ipt, ipt
                                        });
                                        if (ipt.CompareTo(MAX) > 0)
                                        {
                                            log.Info(string.Format(rsc.proot_warningbignumber, s));
                                        }
                                    }
                                    else
                                    {
                                        log.Info(string.Format(rsc.proot_noprime, s));
                                    }
                                }
                                else
                                {
                                    log.Info(string.Format(rsc.proot_novalidnumber, new object[] { s, MIN.ToString(), MAX.ToString() }));
                                }
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(_inputrange[0]) && string.IsNullOrEmpty(_inputrange[1]))
                                {
                                    log.Info(rsc.proot_rangeboth);
                                }
                                else if (string.IsNullOrEmpty(_inputrange[0]))
                                {
                                    log.Info(string.Format(rsc.proot_rangeupper, _inputrange[1]));
                                }
                                else if (string.IsNullOrEmpty(_inputrange[1]))
                                {
                                    log.Info(string.Format(rsc.proot_rangedown, _inputrange[0]));
                                }
                                else
                                {
                                    PrimesBigInteger i1 = IsGmpBigInteger(_inputrange[0]);
                                    PrimesBigInteger i2 = IsGmpBigInteger(_inputrange[1]);
                                    if (i1 != null && i2 != null)
                                    {
                                        if (i1.CompareTo(i2) >= 0)
                                        {
                                            log.Info(string.Format(rsc.proot_wronginterval, s));
                                        }
                                        else
                                        {
                                            intervals.Add(new List <PrimesBigInteger> {
                                                i1, i2
                                            });
                                            if (i2.CompareTo(MAXWARN) > 0)
                                            {
                                                log.Info(string.Format(rsc.proot_warningbiginterval, s));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (doExecute && intervals.Count > 0)
                {
                    StartThread();
                }
            }
            else
            {
                Info(rsc.proot_insert);
            }
        }