Example #1
0
        public ScientificCalculator(

            IInputBuffer buffer,
            IOperatorLookup lookup,
            IUnitConverter unitConverter,
            IOperatorConverter operatorConverter,
            IExpressionBuilder builder,
            IExpressionParser parser,
            IEvaluate evaluator,
            IMemoryStorage memory

            ) : base(

                buffer,
                lookup,
                unitConverter,
                operatorConverter,
                builder,
                parser,
                evaluator,
                memory

                )
        {
        }
        public bool Matches(AutomationElement element, int index)
        {
            if (_op == XPathOperator.Union)
            {
                throw new System.NotImplementedException();
            }

            IEvaluate canGetValue = _left as IEvaluate;
            var       left        = canGetValue.Evaluate(element);

            switch (_op)
            {
            case XPathOperator.Eq:
                return(_right.Equals(left));

            case XPathOperator.Ge:
            case XPathOperator.Gt:
            case XPathOperator.Le:
            case XPathOperator.Lt:
            case XPathOperator.Ne:
                break;

            default:
                throw new System.Exception("Not a relational operator " + _op);
            }

            throw new System.NotImplementedException();
        }
Example #3
0
 public bool SetRoot(IEvaluate <T> root)
 {
     AssertIsNotFrozen();
     if (Root == root)
     {
         return(false);
     }
     Root = root;
     return(true);
 }
Example #4
0
        public ValidationResult IsValid(XPath xpath, string value, IEvaluate evaluate)
        {
            var failures = new List <ValidationFailure>();

            if (string.IsNullOrEmpty(value))
            {
                failures.Add(new ValidationFailure(nameof(Required), $"Node [{xpath.Expression}] doesn't exist or is empty."));
            }

            return(new ValidationResult(failures));
        }
Example #5
0
        public ValidationResult IsValid(XPath xpath, string value, IEvaluate evaluate)
        {
            var failures = new List <ValidationFailure>();

            if (!string.IsNullOrEmpty(value) && Condition(evaluate) && !Predicate(value))
            {
                failures.Add(new ValidationFailure(nameof(ValidateIf), $"Node [{xpath.Expression}] doesn't satify given predicate. Value: [{value}]"));
            }

            return(new ValidationResult(failures));
        }
Example #6
0
        public ValidationResult IsValid(XPath xpath, string value, IEvaluate evaluate)
        {
            var failures = new List <ValidationFailure>();

            if (!string.IsNullOrEmpty(value) &&
                !(value.Length >= Min && value.Length <= Max))
            {
                failures.Add(new ValidationFailure(nameof(Length), $"Node [{xpath.Expression}] length is outside of given range. Min: [{Min}], Max: [{Max}]. Value: [{value}]."));
            }

            return(new ValidationResult(failures));
        }
Example #7
0
        public ValidationResult IsValid(XPath xpath, string value, IEvaluate evaluate)
        {
            var failures = new List <ValidationFailure>();

            if (!string.IsNullOrEmpty(value) &&
                value != ExpectedValue)
            {
                failures.Add(new ValidationFailure(nameof(Value), $"Node [{xpath.Expression}] is different from [{ExpectedValue}]. Value: [{value}]"));
            }

            return(new ValidationResult(failures));
        }
Example #8
0
 public double Calculate(string operation)
 {
     if (!String.IsNullOrEmpty(operation))
     {
         IEvaluate evaluator = mapOfOperations[operation];
         return(evaluator.evaluate(this.number1, this.number2));
     }
     else
     {
         return(0.0d);
     }
 }
Example #9
0
        public ValidationResult IsValid(XPath xpath, string value, IEvaluate evaluate)
        {
            var failures = new List <ValidationFailure>();

            if (!string.IsNullOrEmpty(value) &&
                !Pattern.IsMatch(value))
            {
                failures.Add(new ValidationFailure(nameof(Matches), $"Node [{xpath.Expression}] doesn't match pattern [{Pattern}]. Value: [{value}]"));
            }

            return(new ValidationResult(failures));
        }
Example #10
0
        public ValidationResult IsValid(XPath xpath, string value, IEvaluate evaluate)
        {
            var failures = new List <ValidationFailure>();

            var expected = evaluate.Evaluate <string>(Expected);

            if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(expected) && value != expected)
            {
                failures.Add(new ValidationFailure(nameof(Required), $"Node [{xpath.Expression}] is different from [{Expected.Expression}]. Actual: [{value}], Expected: [{expected}]"));
            }

            return(new ValidationResult(failures));
        }
Example #11
0
        /// <summary>
        /// Evaluate the results
        /// </summary>
        /// <param name="studentId"></param>
        /// <param name="courseResults"></param>
        /// <returns></returns>
        public string Evaluate(string studentId, int[] courseResults)
        {
            var result = "";

            try
            {
                IEvaluate command = (IEvaluate)Activator.GetObject(typeof(IEvaluate), $"tcp://{_host}:{_port}/{nameof(Evaluate)}");
                result = command.Run(studentId, courseResults);
            }
            catch (SocketException ex)
            {
                return("There was an error doing evaluation.");
            }
            return(result);
        }
Example #12
0
        public ValidationResult IsValid(XPath xpath, string value, IEvaluate evaluate)
        {
            var failures = new List <ValidationFailure>();

            if (!string.IsNullOrEmpty(value))
            {
                var isInValues = Values.Any(t => t.Key == value);
                if (!isInValues)
                {
                    failures.Add(new ValidationFailure(nameof(Required), $"Node [{xpath.Expression}] isn't in the allowed values. Value: [{value}]"));
                }
            }

            return(new ValidationResult(failures));
        }
Example #13
0
        static void Main()
        {
            Faculty mrLin   = new Faculty("2004034", "林立");
            Faculty msYang  = new Faculty("2002010", "杨雪梅");
            Faculty mrHuang = new Faculty("2011044", "黄至辉");
            Student girl    = new Student("2190757001", "李四");

            IEvaluate[] audiences = new IEvaluate[] { msYang, mrHuang, girl };          //对象的类型为接口(数组);
            OpenLesson  oop       = new OpenLesson()
            {
                Lecturer  = mrLin,
                Audiences = audiences
            };

            oop.Evaluate();
            Read();
        }
Example #14
0
        public LogicText(XmlNode node, Dictionary <string, ExpressionConstructorInfo> expressionConstructorInfos) : base(node)
        {
            XmlAttribute text = node.Attributes ["text"];

            if (text != null)
            {
                if (node.ChildNodes.Count > 0)
                {
                    throw new Exception("Cannot define both text attribute and expression");
                }

                this.Text = new Constant(text.Value);
            }
            else
            {
                this.Text = new Expression(node.ChildNodes [0], expressionConstructorInfos);
            }
        }
Example #15
0
 /// <summary>
 /// Lazy indexer.
 /// </summary>
 public new T this[int index]
 {
     get
     {
         var       underlyingItem = this.collection[index];
         IEvaluate itemLazy       = underlyingItem as IEvaluate;
         if (itemLazy != null && (!itemLazy.IsEvaluated))
         {
             itemLazy.Evaluate();
         }
         // return evaluated items
         return(underlyingItem);
     }
     set
     {
         throw new NotImplementedException();
     }
 }
Example #16
0
        public StandardCalculator(

            IInputBuffer buffer,
            IOperatorLookup lookup,
            IUnitConverter unitConverter,
            IOperatorConverter operatorConverter,
            IExpressionBuilder builder,
            IExpressionParser parser,
            IEvaluate evaluator,
            IMemoryStorage memory

            ) : base(buffer)
        {
            Lookup            = lookup;
            UnitConverter     = unitConverter;
            OperatorConverter = operatorConverter;
            Builder           = builder;
            Parser            = parser;
            Evaluator         = evaluator;
            Memory            = memory;
        }
Example #17
0
 /// <summary>
 /// Lazy indexer.
 /// </summary>
 public new T this[int index]
 {
     get
     {
         var       underlyingItem = this.lazifiedCollection[index];
         IEvaluate itemLazy       = underlyingItem as IEvaluate;
         if (itemLazy != null)
         {
             if (!itemLazy.IsEvaluated)
             {
                 itemLazy.Evaluate();
             }
         }
         // return item, evaluated if it was IEvaluate
         return(underlyingItem);
     }
     set
     {
         throw new NotImplementedException();
     }
 }
        public void Setup()
        {
            buffer            = new InputBuffer();
            lookup            = new OperatorLookup();
            unitConverter     = new AngleConverter();
            operatorConverter = new OperatorConverter(lookup.Operators, lookup.Unary);
            parenthesizer     = new Parenthesizer(lookup.Precedence);
            builder           = new ExpressionBuilder(parenthesizer);
            parser            = new ExpressionParser(operatorConverter);
            evaluator         = new Evaluator(unitConverter, operatorConverter, lookup);
            memory            = new MemoryStorage();

            calculator = new ScientificCalculator(

                buffer,
                lookup,
                unitConverter,
                operatorConverter,
                builder,
                parser,
                evaluator,
                memory
                );
        }
Example #19
0
 public LogicCondition(XmlNode node, CreateLogicVessel vessel, Dictionary <string, ExpressionConstructorInfo> expressionConstructorInfos) : base(node)
 {
     this.Condition      = new Expression(node.ChildNodes [0], expressionConstructorInfos);
     this.TrueLogicList  = (LogicList)vessel.CreateLogic(node.ChildNodes [1].ChildNodes [0]);
     this.FalseLogicList = (LogicList)vessel.CreateLogic(node.ChildNodes [2].ChildNodes [0]);
 }
Example #20
0
 public NumericRouletteWheel(IEvaluate <double> evaluator, IFitness <double> fitness)
     : base(evaluator, fitness)
 {
 }
Example #21
0
 public EvalGenome(IEvaluate <T> root)
 {
     SetRoot(root);
 }
Example #22
0
 public Evaluate()
 {
     dal = DataAccess.CreateEvaluate();
 }
Example #23
0
 public RouletteWheel(IEvaluate <T> evaluator,
                      IFitness <T> fitness)
 {
     Evaluator = evaluator;
     Fitness   = fitness;
 }
 protected EvalGenome <T> Create(IEvaluate <T> root, (string message, string data) origin)
Example #25
0
 public NumericalRound05(IEvaluate number)
 {
     this.number = number;
 }
Example #26
0
 /// <summary>
 /// Wraps an evaluatable expression in a new compound expression.
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 internal static AndExpressionGroup <TSource> Begin(IEvaluate <TSource> expression)
 {
     return(new AndExpressionGroup <TSource>(expression is TruthyExpressionWrapper <TSource>?((TruthyExpressionWrapper <TSource>)expression).Inner: expression));
 }
Example #27
0
 internal AndExpressionGroup(IEvaluate <TSource> expression)
 {
     AddExpression(expression);
 }
Example #28
0
 /// <summary>
 /// Adds a new expression to evaluate.
 /// </summary>
 /// <param name="expression"></param>
 protected internal LogicalExpressionGroup <TSource> AddExpression(IEvaluate <TSource> expression)
 {
     expressions.Add(expression);
     return(this);
 }
Example #29
0
 internal LogicalExpression <TSource> And(IEvaluate <TSource> expression)
 {
     return((this as AndExpressionGroup <TSource> ?? AndExpressionGroup <TSource> .Begin(this)).AddExpression(expression));
 }
Example #30
0
 internal TruthyExpressionWrapper(IEvaluate <TSource> inner)
 {
     Inner = inner;
 }