예제 #1
0
        public void ChangeOperatorType(OperatorType operatorType)
        {
            OperatorKey findEmpty = Operators.FirstOrDefault(x => x.OperatorType == OperatorType.None);

            if (findEmpty == null)
            {
                throw new Exception("before I found left side condition I found operator, this is not right code I think");
            }
            findEmpty.OperatorType = operatorType;
        }
예제 #2
0
        public virtual object Run(object newPoint)
        {
            //periority check of opertators,
            //near will be check first
            List <OperatorType> operatorPeriority = new List <OperatorType>
            {
                OperatorType.Equal,
                OperatorType.GreaterThan,
                OperatorType.GreaterThanEqual,
                OperatorType.LessThan,
                OperatorType.LessThanEqual,
                OperatorType.NotEqual,
                OperatorType.And,
                OperatorType.Or,
                OperatorType.None
            };
            List <OperatorKey> operators = Operators.ToList();
            object             value     = null;

            do
            {
                OperatorType operatorToCheck = operatorPeriority.FirstOrDefault();
                if (operators.Count == 1 && value == null)
                {
                    value = operators.FirstOrDefault().OperatorInfo.Run(newPoint);
                    break;
                }
                foreach (OperatorKey leftItem in operators.Where(x => x.OperatorType == operatorToCheck).ToArray())
                {
                    int         index    = operators.IndexOf(leftItem);
                    OperatorKey sideItem = null;
                    if (index + 1 >= operators.Count)
                    {
                        sideItem = operators[index - 1];
                    }
                    else
                    {
                        sideItem = operators[index + 1];
                    }
                    value = OperatorInfo.Compare(newPoint, leftItem.OperatorInfo, sideItem.OperatorInfo, operatorToCheck);
                    operators.Remove(leftItem);
                    operators.Remove(sideItem);
                    if (operators.Count == 0)
                    {
                        break;
                    }
                    operators.Add(new OperatorKey()
                    {
                        OperatorType = sideItem.OperatorType, OperatorInfo = new ValueInfo()
                        {
                            Value = value
                        }
                    });
                }
                if (operators.Count(x => x.OperatorType == operatorToCheck) == 0)
                {
                    operatorPeriority.Remove(operatorToCheck);
                }
            }while (operatorPeriority.Count > 0);
            //OperatorType lastOperatorType = OperatorType.None;
            //foreach (OperatorKey item in Operators)
            //{
            //    lastValue = OperatorInfo.Compare(newPoint, lastValue, item.OperatorInfo, lastOperatorType);
            //    lastOperatorType = item.OperatorType;
            //}
            return(value);
        }