private List <String> PromoteIntegers(List <String> Operands)
        {
            if (!EXEExecutionGlobals.AllowPromotionOfIntegerToReal)
            {
                return(Operands);
            }

            bool ContainsReal    = false;
            bool ContainsInteger = false;

            foreach (String Operand in Operands)
            {
                ContainsReal    |= EXETypes.RealTypeName.Equals(EXETypes.DetermineVariableType("", Operand));
                ContainsInteger |= EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", Operand));

                if (ContainsReal && ContainsInteger)
                {
                    break;
                }
            }

            if (!ContainsReal || !ContainsInteger)
            {
                return(Operands);
            }

            return(Operands.Select(x => EXETypes.AdjustAssignedValue(EXETypes.RealTypeName, x)).ToList());
        }
Example #2
0
        public String Evaluate(EXEScope Scope, CDClassPool ExecutionSpace)
        {
            String Result = null;

            String ValueType = EXETypes.DetermineVariableType("", this.Value);

            if (ValueType == null)
            {
                return(Result);
            }

            // If we have simple value, e.g. 5, 3.14, "hi Madelyn", we are good
            if (!EXETypes.ReferenceTypeName.Equals(ValueType))
            {
                Result = this.Value;
            }
            // We got here because we have a variable name, the variable is of primitive value
            else if (EXETypes.ReferenceTypeName.Equals(ValueType))
            {
                EXEPrimitiveVariable ThisVariable = Scope.FindPrimitiveVariableByName(this.Value);
                if (ThisVariable != null)
                {
                    Result = ThisVariable.Value;
                }
            }

            /*Console.WriteLine("Operand: " + this.Value);
             * Console.WriteLine("Result: " + Result);*/

            return(Result);
        }
Example #3
0
        public override Boolean Execute(OALProgram OALProgram, EXEScope Scope)
        {
            //Console.WriteLine("Assignment is being executed");
            Boolean Result = false;

            String AssignedValue = this.AssignedExpression.Evaluate(Scope, OALProgram.ExecutionSpace);

            if (AssignedValue == null)
            {
                return(Result);
            }

            // If we are assigning to a variable
            if (this.AttributeName == null)
            {
                //Console.WriteLine("Assigning value: " + AssignedValue + " to variable " + this.VariableName);

                EXEPrimitiveVariable Variable = Scope.FindPrimitiveVariableByName(this.VariableName);
                // If the variable doesnt exist, we simply create it
                if (Variable == null)
                {
                    //Console.WriteLine("Creating new var " + this.VariableName);
                    Result = Scope.AddVariable(new EXEPrimitiveVariable(this.VariableName, AssignedValue));
                }
                //If variable exists and its type is UNDEFINED
                else if (EXETypes.UnitializedName.Equals(Variable.Type))
                {
                    //Console.WriteLine("Assigning to unitialized var" + this.VariableName);
                    Result = Variable.AssignValue(Variable.Name, AssignedValue);
                }
                // If the variable exists and is primitive
                else if (!EXETypes.ReferenceTypeName.Equals(Variable.Type))
                {
                    //Console.WriteLine("Assigning to initialized var" + this.VariableName);
                    // If the types don't match, this fails and returns false
                    AssignedValue = EXETypes.AdjustAssignedValue(Variable.Type, AssignedValue);
                    Result        = Variable.AssignValue("", AssignedValue);
                }

                // Variable exists and is not primitive. What to do, what to do?
                // We do nothing, we CANNOT ASSIGN TO HANDLES!!!
            }
            // We are assigning to an attribute of a variable
            else
            {
                EXEReferenceEvaluator RefEvaluator = new EXEReferenceEvaluator();
                Result = RefEvaluator.SetAttributeValue(this.VariableName, this.AttributeName, Scope, OALProgram.ExecutionSpace, AssignedValue);
                //Console.WriteLine("Tried to assign " + AssignedValue + " to " + this.VariableName + "." + this.AttributeName);
            }

            //Console.WriteLine("Assignment Result: " + Result);
            return(Result);
        }
Example #4
0
        public bool VerifyReferences(EXEScope Scope, CDClassPool ExecutionSpace)
        {
            bool Result = false;

            if (!EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Value)))
            {
                Result = true;
            }
            else
            {
                Result = Scope.VariableNameExists(this.Value);
            }
            return(Result);
        }
Example #5
0
        //SetUloh1
        // Similar as task above, but this time we set the attribute value to "NewValue" parameter
        // But it's not that easy, you need to check if attribute type and NewValue type are the same (e.g. both are integer)
        // To do that, you need to find the referencing variable's class (via Scope) and then the attribute's type (vie ExecutionSpace)
        // When you know the type of attribute, use EXETypes.IsValidValue to see if you can or cannot assign that value to that attribute
        // You assign it in Scope
        // Return if you could assign it or not
        // EXETypes.determineVariableType()
        public Boolean SetAttributeValue(String ReferencingVariableName, String AttributeName, EXEScope Scope, CDClassPool ExecutionSpace, String NewValue)
        {
            EXEReferencingVariable ReferencingVariable = Scope.FindReferencingVariableByName(ReferencingVariableName);

            if (ReferencingVariable == null)
            {
                return(false);
            }

            CDClassInstance ClassInstance = ExecutionSpace.GetClassInstanceById(ReferencingVariable.ClassName, ReferencingVariable.ReferencedInstanceId);

            if (ClassInstance == null)
            {
                return(false);
            }

            CDClass Class = ExecutionSpace.getClassByName(ReferencingVariable.ClassName);

            if (Class == null)
            {
                return(false);
            }

            CDAttribute Attribute = Class.GetAttributeByName(AttributeName);

            if (Attribute == null)
            {
                return(false);
            }

            String NewValueType = EXETypes.DetermineVariableType(null, NewValue);

            if (!EXETypes.CanBeAssignedToAttribute(AttributeName, Attribute.Type, NewValueType))
            {
                return(false);
            }

            ClassInstance.SetAttribute(AttributeName, EXETypes.AdjustAssignedValue(Attribute.Type, NewValue));

            return(true);
        }
Example #6
0
        public Boolean AssignValue(String name, String NewValue)
        {
            if (name == EXETypes.UniqueIDTypeName)
            {
                return(false);
            }

            if (EXETypes.UnitializedName.Equals(this.Type))
            {
                this.Value = NewValue;
                return(true);
            }

            String NewValueType = EXETypes.DetermineVariableType(name, NewValue);

            if (NewValueType == this.Type)
            {
                this.Value = NewValue;
                return(true);
            }

            if (NewValueType == EXETypes.IntegerTypeName && this.Type == EXETypes.RealTypeName && EXEExecutionGlobals.AllowPromotionOfIntegerToReal)
            {
                int    NewValueInt    = int.Parse(NewValue);
                double newValueDouble = NewValueInt;
                this.Value = newValueDouble.ToString();
                return(true);
            }

            if (NewValueType == EXETypes.RealTypeName && this.Type == EXETypes.IntegerTypeName && EXEExecutionGlobals.AllowLossyAssignmentOfRealToInteger)
            {
                decimal newValueDouble = decimal.Parse(NewValue, CultureInfo.InvariantCulture);
                int     newValueInt    = (int)newValueDouble;
                this.Value = newValueInt.ToString();
                return(true);
            }

            return(false);
        }
Example #7
0
        public override Boolean Execute(OALProgram OALProgram, EXEScope Scope)
        {
            Boolean Success = true;

            this.OALProgram = OALProgram;

            bool   ConditionTrue = true;
            String ConditionResult;
            int    IterationCounter = 0;

            while (ConditionTrue)
            {
                OALProgram.AccessInstanceDatabase();
                ConditionResult = this.Condition.Evaluate(Scope, OALProgram.ExecutionSpace);
                OALProgram.LeaveInstanceDatabase();

                //!!NON-RECURSIVE!!
                this.ClearVariables();

                if (ConditionResult == null)
                {
                    return(false);
                }
                if (!EXETypes.BooleanTypeName.Equals(EXETypes.DetermineVariableType("", ConditionResult)))
                {
                    return(false);
                }
                ConditionTrue = EXETypes.BooleanTrue.Equals(ConditionResult);
                if (!ConditionTrue)
                {
                    break;
                }

                if (IterationCounter >= EXEExecutionGlobals.LoopIterationCap)
                {
                    Success = false;
                    break;
                }

                foreach (EXECommand Command in this.Commands)
                {
                    if (this.CurrentLoopControlCommand != LoopControlStructure.None)
                    {
                        break;
                    }

                    Success = Command.SynchronizedExecute(OALProgram, this);
                    if (!Success)
                    {
                        break;
                    }
                }
                if (!Success)
                {
                    break;
                }

                IterationCounter++;

                if (this.CurrentLoopControlCommand == LoopControlStructure.Break)
                {
                    this.CurrentLoopControlCommand = LoopControlStructure.None;
                    break;
                }
                else if (this.CurrentLoopControlCommand == LoopControlStructure.Continue)
                {
                    this.CurrentLoopControlCommand = LoopControlStructure.None;
                    continue;
                }
            }
            return(Success);
        }
        // SetUloh2
        public override bool Execute(OALProgram OALProgram, EXEScope Scope)
        {
            //Select instances of given class that match the criteria and assign them to variable with given name
            // ClassName tells us which class we are interested in
            // Cardinality tells us whether we want one random instance (matching the criteria) or all of them
            // "Many" - we create variable EXEReferencingSetVariable, "Any" - we create variable EXEReferencingVariable
            // Variable name tells us how to name the newly created referencing variable
            // Where condition tells us which instances to select from all instances of the class (just do EXEASTNode.Evaluate and return true if the result "true" and false for "false")
            // When making unit tests, do not use the "where" causule yet, because its evaluation is not yet implemented
            // If relationship selection does not exists, this is problem

            if (this.RelationshipSelection == null)
            {
                return(false);
            }

            CDClass Class = OALProgram.ExecutionSpace.getClassByName(this.RelationshipSelection.GetLastClassName());

            if (Class == null)
            {
                return(false);
            }

            // We need to check, if the variable already exists, it must be of corresponding type
            if (Scope.VariableNameExists(this.VariableName))
            {
                if
                (
                    !(
                        (EXECommandQuerySelect.CardinalityAny.Equals(this.Cardinality)
                         &&
                         this.RelationshipSelection.GetLastClassName() == Scope.FindReferencingVariableByName(this.VariableName).ClassName)
                        ||
                        (EXECommandQuerySelect.CardinalityMany.Equals(this.Cardinality)
                         &&
                         this.RelationshipSelection.GetLastClassName() == Scope.FindSetReferencingVariableByName(this.VariableName).ClassName)
                        )
                )
                {
                    return(false);
                }
            }

            // Evaluate relationship selection. If it fails, execution fails too
            List <long> SelectedIds = this.RelationshipSelection.Evaluate(OALProgram.RelationshipSpace, Scope);

            if (SelectedIds == null)
            {
                return(false);
            }
            // If class has no instances, command may execute successfully, but we better verify references in the WHERE condition
            if (SelectedIds.Count() == 0 && this.WhereCondition != null)
            {
                return(this.WhereCondition.VerifyReferences(Scope, OALProgram.ExecutionSpace));
            }

            // Now let's evaluate the condition
            if (this.WhereCondition != null && SelectedIds.Any())
            {
                String TempSelectedVarName = "selected";

                EXEReferencingVariable SelectedVar = new EXEReferencingVariable(TempSelectedVarName, this.RelationshipSelection.GetLastClassName(), -1);
                if (!Scope.AddVariable(SelectedVar))
                {
                    return(false);
                }

                List <long> ResultIds = new List <long>();
                foreach (long Id in SelectedIds)
                {
                    SelectedVar.ReferencedInstanceId = Id;
                    String ConditionResult = this.WhereCondition.Evaluate(Scope, OALProgram.ExecutionSpace);
                    //Console.Write(Id + " : " + ConditionResult);

                    if (!EXETypes.IsValidValue(ConditionResult, EXETypes.BooleanTypeName))
                    {
                        Scope.DestroyReferencingVariable(TempSelectedVarName);
                        return(false);
                    }

                    if (EXETypes.BooleanTrue.Equals(ConditionResult))
                    {
                        ResultIds.Add(Id);
                    }
                }

                SelectedIds = ResultIds;
                Scope.DestroyReferencingVariable(TempSelectedVarName);
            }

            // Now we have ids of selected instances. Let's assign them to a variable
            if (EXECommandQuerySelect.CardinalityMany.Equals(this.Cardinality))
            {
                EXEReferencingSetVariable Variable = Scope.FindSetReferencingVariableByName(this.VariableName);
                if (Variable == null)
                {
                    Variable = new EXEReferencingSetVariable(this.VariableName, this.RelationshipSelection.GetLastClassName());
                    if (!Scope.AddVariable(Variable))
                    {
                        return(false);
                    }
                }
                foreach (long Id in SelectedIds)
                {
                    Variable.AddReferencingVariable(new EXEReferencingVariable("", Variable.ClassName, Id));
                }
            }
            else if (EXECommandQuerySelect.CardinalityAny.Equals(this.Cardinality))
            {
                EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.VariableName);
                if (Variable == null)
                {
                    long ResultId = SelectedIds.Any() ? SelectedIds[new Random().Next(SelectedIds.Count)] : -1;
                    Variable = new EXEReferencingVariable(this.VariableName, this.RelationshipSelection.GetLastClassName(), ResultId);
                    if (!Scope.AddVariable(Variable))
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #9
0
        public String Evaluate(EXEScope Scope, CDClassPool ExecutionSpace)
        {
            String Result = null;
            EXEExpressionEvaluator      Evaluator       = new EXEExpressionEvaluator();
            EXEEvaluatorHandleOperators HandleEvaluator = new EXEEvaluatorHandleOperators();
            EXEReferenceEvaluator       AccessEvaluator = new EXEReferenceEvaluator();

            // If we just calculate with ints, reals, bools, strings
            if (Evaluator.IsSimpleOperator(this.Operation))
            {
                List <String> EvaluatedOperands = new List <String>();
                foreach (EXEASTNode Operand in this.Operands)
                {
                    EvaluatedOperands.Add(Operand.Evaluate(Scope, ExecutionSpace));
                }
                if (EvaluatedOperands.Contains(null))
                {
                    return(Result);
                }
                //If we are returning real number, let's format it so that we don't have trouble with precision
                Result = Evaluator.Evaluate(this.Operation, EvaluatedOperands);

                /*Console.Write("AST Composite operation " + this.Operation + " has result ");
                 * Console.Write(Result == null ? "null" : Result);
                 * Console.WriteLine();*/
                if (Result == null)
                {
                    return(Result);
                }

                /* Console.WriteLine("Operation: " + this.Operation);
                 * Console.WriteLine("Result of operation" + (Result == null ? "null" : Result));*/
                if (EXETypes.RealTypeName.Equals(EXETypes.DetermineVariableType("", Result)))
                {
                    //Console.WriteLine("is real and needs formatting");
                    if (!Result.Contains("."))
                    {
                        Result = FormatDouble(Result);
                    }
                    if (!Result.Contains("."))
                    {
                        Result += ".0";
                    }
                }
            }
            // If we have handle operators
            else if (HandleEvaluator.IsHandleOperator(this.Operation))
            {
                Console.WriteLine("We have handle operator");
                Result = HandleEvaluator.Evaluate(this.Operation, this.Operands.Select(x => ((EXEASTNodeLeaf)x).GetNodeValue()).ToList(), Scope);
            }
            // If we have access operator - we either access attribute or have decimal number. There are always 2 operands
            else if (".".Equals(this.Operation) && this.Operands.Count == 2)
            {
                if (EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) &&
                    EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue()))
                    )
                {
                    Result = this.Operands[0].GetNodeValue() + "." + this.Operands[1].GetNodeValue();
                }
                else if (EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) &&
                         EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue()))
                         )
                {
                    Result = AccessEvaluator.EvaluateAttributeValue(this.Operands[0].GetNodeValue(), this.Operands[1].GetNodeValue(), Scope, ExecutionSpace);
                }
            }
            return(Result);
        }
Example #10
0
        public bool VerifyReferences(EXEScope Scope, CDClassPool ExecutionSpace)
        {
            bool Result = false;
            EXEExpressionEvaluator      Evaluator       = new EXEExpressionEvaluator();
            EXEEvaluatorHandleOperators HandleEvaluator = new EXEEvaluatorHandleOperators();
            EXEReferenceEvaluator       AccessEvaluator = new EXEReferenceEvaluator();

            // If we just calculate with ints, reals, bools, strings
            if (Evaluator.IsSimpleOperator(this.Operation))
            {
                foreach (EXEASTNode Operand in this.Operands)
                {
                    if (!Operand.VerifyReferences(Scope, ExecutionSpace))
                    {
                        return(false);
                    }
                }
                Result = true;
            }
            // If we have handle operators
            else if (HandleEvaluator.IsHandleOperator(this.Operation))
            {
                if (this.Operands.Count() == 1 && Scope.FindReferenceHandleByName(((EXEASTNodeLeaf)this.Operands[0]).GetNodeValue()) != null)
                {
                    Result = true;
                }
            }
            // If we have access operator - we either access attribute or have decimal number. There are always 2 operands
            else if (".".Equals(this.Operation) && this.Operands.Count == 2)
            {
                if (EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) &&
                    EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue()))
                    )
                {
                    Result = true;
                }
                else if (EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) &&
                         EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue()))
                         )
                {
                    EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.Operands[0].GetNodeValue());
                    if (Variable == null)
                    {
                        return(false);
                    }
                    CDClass Class = ExecutionSpace.getClassByName(Variable.ClassName);
                    if (Class == null)
                    {
                        return(false);
                    }
                    CDAttribute Attribute = Class.GetAttributeByName(this.Operands[1].GetNodeValue());
                    if (Attribute == null)
                    {
                        return(false);
                    }
                    CDClassInstance Instance = Variable.RetrieveReferencedClassInstance(ExecutionSpace);
                    if (Instance == null)
                    {
                        return(false);
                    }
                    Result = true;
                }
            }
            return(Result);
        }
Example #11
0
 public EXEPrimitiveVariable(String Name, String Value)
 {
     this.Name  = Name;
     this.Value = Value;
     this.Type  = EXETypes.DetermineVariableType(Name, Value);
 }
        // Potentially refactor this
        public String IsValid(string oper, string[] param)
        {
            if (String.IsNullOrEmpty(oper) || param == null)
            {
                return(EXETypes.BooleanFalse);
            }

            //get the first element type
            String ParamType = EXETypes.DetermineVariableType(null, param[0]);

            //check if it is int or real number
            if (String.Equals(ParamType, EXETypes.IntegerTypeName) || String.Equals(ParamType, EXETypes.RealTypeName))
            {
                if (oper == "+" || oper == "-" || oper == "*" || oper == "/" || oper == "%")
                {
                    if (param.Length < 2)
                    {
                        return(EXETypes.BooleanFalse);
                    }
                }
                else if (oper == "==" || oper == "!=" || oper == "<" || oper == ">" || oper == "<=" || oper == ">=")
                {
                    if (param.Length != 2)
                    {
                        return(EXETypes.BooleanFalse);
                    }
                }
                else if (oper == "and" || oper == "or" || oper == "not")
                {
                    return(EXETypes.BooleanFalse);
                }

                //chcek if all parameter is integer
                if (String.Equals(ParamType, EXETypes.IntegerTypeName))
                {
                    foreach (var value in param)
                    {
                        if (!EXETypes.IsValidValue(value, EXETypes.IntegerTypeName))
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }

                    return(EXETypes.BooleanTrue);
                }
                //chcek if all parameter is double
                else if (String.Equals(ParamType, EXETypes.RealTypeName))
                {
                    foreach (var value in param)
                    {
                        if (!EXETypes.IsValidValue(value, EXETypes.RealTypeName))
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }

                    return(EXETypes.BooleanTrue);
                }

                return(EXETypes.BooleanFalse);
            }

            //check if it is boolean type
            if (String.Equals(ParamType, EXETypes.BooleanTypeName))
            {
                if (oper.ToLower() == "not")
                {
                    if (param.Length != 1)
                    {
                        return(EXETypes.BooleanFalse);
                    }
                    return((Boolean.TryParse(param[0], out _)) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }

                if (((oper == "==" || oper == "!=") && param.Length == 2) || ((oper.ToLower() == "and" || oper.ToLower() == "or") && param.Length >= 2))
                {
                    foreach (var value in param)
                    {
                        if (!Boolean.TryParse(value, out _))
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    return(EXETypes.BooleanTrue);
                }

                return(EXETypes.BooleanFalse);
            }

            //check if it is boolean type
            if (String.Equals(ParamType, EXETypes.StringTypeName))
            {
                if (oper == ">" || oper == "<" || oper == "<=" || oper == ">=" || oper == "==" || oper == "!=")
                {
                    if (param.Length != 2)
                    {
                        return(EXETypes.BooleanFalse);
                    }

                    foreach (String value in param)
                    {
                        if (!IsValidEXETypeString(value))
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }

                    return(EXETypes.BooleanTrue);
                }

                if (oper == "+")
                {
                    if (param.Length < 2)
                    {
                        return(EXETypes.BooleanFalse);
                    }

                    foreach (String value in param)
                    {
                        if (!IsValidEXETypeString(value))
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }

                    return(EXETypes.BooleanTrue);
                }

                return(EXETypes.BooleanFalse);
            }

            return(EXETypes.BooleanFalse);
        }
        // SetUloh1
        // Here you get operator and operands, and you need to return the result. Check the unit tests to see what this is about
        public String Evaluate(String Operator, List <String> InOperands)
        {
            List <String> Operands = PromoteIntegers(InOperands);

            if (!this.CanBeEvaluated(Operator, Operands))
            {
                return(null);
            }

            //Console.WriteLine("Can be evaluated");

            //get variable type
            String VariableType = EXETypes.DetermineVariableType(null, Operands[0]);


            switch (Operator)
            {
            case "+":     //int, real, string
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //add numbers in list and return result
                    return(IntList.Aggregate((a, x) => a + x).ToString());
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //add numbers in list and return result
                    return(EXETypes.AdjustAssignedValue(EXETypes.RealTypeName, DoubleList.Aggregate((a, x) => a + x).ToString()));
                }
                if (String.Equals(EXETypes.StringTypeName, VariableType))
                {
                    //add string in list and return result
                    //remove \" from Operands
                    List <String> StringList = Operands.Select(s => s.Replace("\"", "")).ToList();

                    //add strings in list and return result
                    return(CreateEXETypeString(StringList.Aggregate((a, x) => a + x).ToString()));
                }
                break;

            case "-":     //int, real
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //sub numbers in list and return result
                    return(IntList.Aggregate((a, x) => a - x).ToString());
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //sub numbers in list and return result
                    return(EXETypes.AdjustAssignedValue(EXETypes.RealTypeName, DoubleList.Aggregate((a, x) => a - x).ToString()));
                }
                break;

            case "*":     //int, real
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //multiply numbers in list and return result
                    return(IntList.Aggregate((a, x) => a * x).ToString());
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //multiply numbers in list and return result
                    return(EXETypes.AdjustAssignedValue(EXETypes.RealTypeName, DoubleList.Aggregate((a, x) => a * x).ToString()));
                }

                break;

            case "/":     //int, real
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    for (int i = 1; i < IntList.Count; i++)
                    {
                        if (IntList[i] == 0)
                        {
                            return(null);
                        }
                    }
                    //divide numbers in list and return result
                    return(IntList.Aggregate((a, x) => a / x).ToString());
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                            for (int i = 1; i < DoubleList.Count; i++)
                            {
                                if (DoubleList[i] == 0)
                                {
                                    return(EXETypes.BooleanFalse);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //divide numbers in list and return result
                    return(EXETypes.AdjustAssignedValue(EXETypes.RealTypeName, DoubleList.Aggregate((a, x) => a / x).ToString()));
                }

                break;

            case "%":     //int, real
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    for (int i = 1; i < IntList.Count; i++)
                    {
                        if (IntList[i] == 0)
                        {
                            return(null);
                        }
                    }
                    //divide numbers in list and return result
                    return(IntList.Aggregate((a, x) => a % x).ToString());
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                            for (int i = 1; i < DoubleList.Count; i++)
                            {
                                if (DoubleList[i] == 0)
                                {
                                    return(EXETypes.BooleanFalse);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //divide numbers in list and return result
                    return(EXETypes.AdjustAssignedValue(EXETypes.RealTypeName, DoubleList.Aggregate((a, x) => a % x).ToString()));
                }

                break;

            case "==":     //int, real, string, booelan, unique ID
                //return bool
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //compare 2 numbers in list (equals) and return result
                    return(int.Equals(IntList[0], IntList[1]) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //compare 2 numbers in list (equals) and return result
                    return(Double.Equals(DoubleList[0], DoubleList[1]) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                if (String.Equals(EXETypes.StringTypeName, VariableType))
                {
                    //compare 2 string in list (equals) and return result
                    return(String.Equals(Operands[0], Operands[1]) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }

                //only 2 operands
                if (String.Equals(EXETypes.BooleanTypeName, VariableType))
                {
                    //convert to list of int
                    List <bool> BooleanList = Operands.Select(bool.Parse).ToList();
                    //compare 2 boolean in list (equals) and return result
                    return(Boolean.Equals(BooleanList[0], BooleanList[1]) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                break;

            case "!=":     //int, real, string, booelan, unique ID
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //compare 2 numbers in list (equals) and return result
                    return(!int.Equals(IntList[0], IntList[1]) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //compare 2 numbers in list (equals) and return result
                    return(!Double.Equals(DoubleList[0], DoubleList[1]) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                if (String.Equals(EXETypes.StringTypeName, VariableType))
                {
                    //compare 2 string in list (equals) and return result
                    return(!String.Equals(Operands[0], Operands[1]) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                //true if Operands are boolean
                if (String.Equals(EXETypes.BooleanTypeName, VariableType))
                {
                    //convert to list of boolean
                    List <bool> BooleanList = Operands.Select(bool.Parse).ToList();
                    //compare 2 boolean in list (not equals) and return result
                    return(!Boolean.Equals(BooleanList[0], BooleanList[1]) ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                break;

            //only 2 operands
            case "<":     //int, real, string
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //compare numbers in list (less then) and return result
                    return(IntList[0] < IntList[1] ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //compare numbers in list (less then) and return result
                    return(DoubleList[0] < DoubleList[1] ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                if (String.Equals(EXETypes.StringTypeName, VariableType))
                {
                    //compare 2 strings in list (less then) and return result
                    return(String.Compare(Operands[0], Operands[1]) < 0 ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                break;

            case ">":     //int, real, string
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //compare numbers in list (greater then) and return result
                    return(IntList[0] > IntList[1] ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //compare numbers in list (greater then) and return result
                    return(DoubleList[0] > DoubleList[1] ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                if (String.Equals(EXETypes.StringTypeName, VariableType))
                {
                    //add string in list and return result
                    return(String.Compare(Operands[0], Operands[1]) > 0 ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                break;

            case "<=":     //int, real, string
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //compare numbers in list (less then or equals to) and return result
                    return(IntList[0] <= IntList[1] ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //compare numbers in list (less then or equals to) and return result
                    return(DoubleList[0] <= DoubleList[1] ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                if (String.Equals(EXETypes.StringTypeName, VariableType))
                {
                    //compare strings in list (less then or equals to) and return result
                    return(String.Compare(Operands[0], Operands[1]) <= 0 ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                break;

            case ">=":     //int, real, string
                //true if Operands are integers
                if (String.Equals(EXETypes.IntegerTypeName, VariableType))
                {
                    //convert to list of int
                    List <int> IntList = Operands.Select(int.Parse).ToList();
                    //compare numbers in list (greater then or equals to) and return result
                    return(IntList[0] >= IntList[1] ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                //true if Operands are real numbers
                if (String.Equals(EXETypes.RealTypeName, VariableType))
                {
                    //convert to list of real numbers
                    // List<double> DoubleList = Operands.Select(double.Parse.).ToList();
                    List <decimal> DoubleList = new List <decimal>();
                    foreach (String Operand in Operands)
                    {
                        try
                        {
                            DoubleList.Add(decimal.Parse(Operand, CultureInfo.InvariantCulture));
                        }
                        catch (Exception e)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    //compare numbers in list (greater then or equals to) and return result
                    return(DoubleList[0] >= DoubleList[1] ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                if (String.Equals(EXETypes.StringTypeName, VariableType))
                {
                    //compare numbers in list (greater then or equals to) and return result
                    return(String.Compare(Operands[0], Operands[1]) >= 0 ? EXETypes.BooleanTrue : EXETypes.BooleanFalse);
                }
                break;

            case "and":     //only boolean
                //true if Operands are boolean
                if (String.Equals(EXETypes.BooleanTypeName, VariableType))
                {
                    //convert to list of int
                    List <bool> BooleanList = Operands.Select(bool.Parse).ToList();
                    foreach (bool bool_var in BooleanList)
                    {
                        if (!bool_var)
                        {
                            return(EXETypes.BooleanFalse);
                        }
                    }
                    return(EXETypes.BooleanTrue);
                }
                break;

            case "or":     //only boolean
                //true if Operands are boolean
                if (String.Equals(EXETypes.BooleanTypeName, VariableType))
                {
                    //convert to list of int
                    List <bool> BooleanList = Operands.Select(bool.Parse).ToList();
                    foreach (bool bool_var in BooleanList)
                    {
                        if (bool_var)
                        {
                            return(EXETypes.BooleanTrue);
                        }
                    }
                    return(EXETypes.BooleanFalse);
                }
                break;

            //only 1 operand
            case "not":     //only boolean
                //true if Operands are boolean
                if (String.Equals(EXETypes.BooleanTypeName, VariableType))
                {
                    //return TRUE or FALSE
                    return(String.Equals(Operands[0], EXETypes.BooleanTrue) ? EXETypes.BooleanFalse : EXETypes.BooleanTrue);
                }
                break;
            }

            return(null);
        }
Example #14
0
        public override Boolean Execute(OALProgram OALProgram, EXEScope Scope)
        {
            this.OALProgram = OALProgram;
            Boolean Result            = true;
            Boolean AScopeWasExecuted = false;

            if (this.Condition == null)
            {
                return(false);
            }

            OALProgram.AccessInstanceDatabase();
            String ConditionResult = this.Condition.Evaluate(Scope, OALProgram.ExecutionSpace);

            OALProgram.LeaveInstanceDatabase();
            if (ConditionResult == null)
            {
                return(false);
            }
            if (!EXETypes.BooleanTypeName.Equals(EXETypes.DetermineVariableType("", ConditionResult)))
            {
                return(false);
            }
            Boolean IfConditionResult = EXETypes.BooleanTrue.Equals(ConditionResult) ? true : false;

            if (IfConditionResult)
            {
                foreach (EXECommand Command in this.Commands)
                {
                    Result = Command.SynchronizedExecute(OALProgram, this);
                    if (!Result)
                    {
                        break;
                    }
                }
                AScopeWasExecuted = true;
            }

            if (AScopeWasExecuted)
            {
                return(Result);
            }

            if (this.ElifScopes != null)
            {
                foreach (EXEScopeCondition CurrentElif in this.ElifScopes)
                {
                    if (CurrentElif.Condition == null)
                    {
                        return(false);
                    }
                    OALProgram.AccessInstanceDatabase();
                    ConditionResult = CurrentElif.Condition.Evaluate(Scope, OALProgram.ExecutionSpace);
                    OALProgram.LeaveInstanceDatabase();

                    if (ConditionResult == null)
                    {
                        return(false);
                    }
                    if (!EXETypes.BooleanTypeName.Equals(EXETypes.DetermineVariableType("", ConditionResult)))
                    {
                        return(false);
                    }
                    IfConditionResult = EXETypes.BooleanTrue.Equals(ConditionResult) ? true : false;

                    if (IfConditionResult)
                    {
                        Result            = CurrentElif.SynchronizedExecute(OALProgram, CurrentElif);
                        AScopeWasExecuted = true;
                        break;
                    }
                }
            }

            if (AScopeWasExecuted)
            {
                return(Result);
            }

            if (this.ElseScope != null)
            {
                Result = this.ElseScope.SynchronizedExecute(OALProgram, ElseScope);
            }

            return(Result);
        }