Ejemplo n.º 1
0
        public Dictionary <String, String> GetRefStateAttrsDictRecursive(CDClassPool ExecutionSpace)
        {
            Dictionary <String, String> Result = new Dictionary <String, String>();
            EXEScope CurrentScope = this;

            while (CurrentScope != null)
            {
                foreach (EXEReferencingVariable Var in CurrentScope.ReferencingVariables)
                {
                    CDClassInstance Inst = Var.RetrieveReferencedClassInstance(ExecutionSpace);
                    if (Inst == null)
                    {
                        continue;
                    }
                    foreach (var Attribute in Inst.GetStateWithoutID())
                    {
                        Result[Var.Name + "." + Attribute.Key] = Attribute.Value;
                    }
                }

                CurrentScope = CurrentScope.SuperScope;
            }

            return(Result);
        }
Ejemplo n.º 2
0
        public Dictionary <String, String> GetSetRefStateAttrsDictRecursive(CDClassPool ExecutionSpace, String VarName)
        {
            Dictionary <String, String> Result = new Dictionary <String, String>();

            EXEReferencingSetVariable SetVar = this.FindSetReferencingVariableByName(VarName);

            if (SetVar == null)
            {
                return(Result);
            }
            int i = 0;

            Console.WriteLine(VarName + " has cardinality " + SetVar.GetReferencingVariables().Count());
            foreach (EXEReferencingVariable Var in SetVar.GetReferencingVariables())
            {
                CDClassInstance Inst = Var.RetrieveReferencedClassInstance(ExecutionSpace);
                if (Inst == null)
                {
                    i++;
                    continue;
                }
                foreach (var Attribute in Inst.GetStateWithoutID())
                {
                    Result[VarName + "[" + i + "]." + Attribute.Key] = Attribute.Value;
                }
                i++;
            }

            return(Result);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void AnimateDistributors()
        {
            CDClassPool        cp = new CDClassPool();
            CDRelationshipPool rp = new CDRelationshipPool();

            cp.SpawnClass("Outer Control Class");
            cp.SpawnClass("Order");
            cp.SpawnClass("Careful Distributor");
            cp.SpawnClass("Regular Distributor");
            cp.SpawnClass("Messenger");
            cp.SpawnClass("Line Item");

            CDRelationship R1 = rp.SpawnRelationship("Outer Control Class", "Order");
            CDRelationship R2 = rp.SpawnRelationship("Careful Distributor", "Order");
            CDRelationship R3 = rp.SpawnRelationship("Regular Distributor", "Order");
            CDRelationship R4 = rp.SpawnRelationship("Messenger", "Order");

            EXEScope OALProgramSuperscope = new EXEScope();

            EXECommandQueryCreate CreateQuery1 = new EXECommandQueryCreate("Outer Control Class", "ooc");
            EXECommandQueryCreate CreateQuery2 = new EXECommandQueryCreate("Order", "order");
            EXECommandQueryCreate CreateQuery3 = new EXECommandQueryCreate("Careful Distributor", "car_distrib");
            EXECommandQueryCreate CreateQuery4 = new EXECommandQueryCreate("Regular Distributor", "reg_distrib");
            EXECommandQueryCreate CreateQuery5 = new EXECommandQueryCreate("Messenger", "messenger");

            OALProgramSuperscope.AddCommand(CreateQuery1);
            OALProgramSuperscope.AddCommand(CreateQuery2);
            OALProgramSuperscope.AddCommand(CreateQuery3);
            OALProgramSuperscope.AddCommand(CreateQuery4);
            OALProgramSuperscope.AddCommand(CreateQuery5);
            for (int i = 0; i < 3; i++)
            {
                OALProgramSuperscope.AddCommand(new EXECommandQueryCreate("Line Item", "li" + i));
            }

            EXECommandQueryRelate RelQuery1 = new EXECommandQueryRelate("ooc", "order", R1.RelationshipName);
            EXECommandQueryRelate RelQuery2 = new EXECommandQueryRelate("car_distrib", "order", R2.RelationshipName);
            EXECommandQueryRelate RelQuery3 = new EXECommandQueryRelate("reg_distrib", "order", R3.RelationshipName);
            EXECommandQueryRelate RelQuery4 = new EXECommandQueryRelate("messenger", "order", R4.RelationshipName);

            OALProgramSuperscope.AddCommand(RelQuery1);
            OALProgramSuperscope.AddCommand(RelQuery2);
            OALProgramSuperscope.AddCommand(RelQuery3);
            OALProgramSuperscope.AddCommand(RelQuery4);

            EXECommandCall        Call1          = new EXECommandCall("ooc", "InitiateDispatch", R1.RelationshipName, "order", "dispatch");
            EXECommandQuerySelect SelectSetQuery = new EXECommandQuerySelect(EXECommandQuerySelect.CardinalityMany, "Line Item", "line_items");

            OALProgramSuperscope.AddCommand(Call1);
            OALProgramSuperscope.AddCommand(SelectSetQuery);

            EXEScopeForEach ForEachCommand = new EXEScopeForEach("current_li", "line_items");
            // EXEScopeCondition IfCommand = new EXEScopeCondition(new EXEASTNodeLeaf(EXETypes.BooleanTrue));
        }
Ejemplo n.º 5
0
        // SetUloh1
        public CDClassInstance RetrieveReferencedClassInstance(CDClassPool ExecutionSpace)
        {
            CDClass Class = ExecutionSpace.getClassByName(this.ClassName);

            if (Class == null)
            {
                return(null);
            }
            CDClassInstance Instance = Class.GetInstanceByID(this.ReferencedInstanceId);

            return(Instance);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public Dictionary <String, String> GetRefStateAttrsDictRecursive(CDClassPool ExecutionSpace, String VarName)
        {
            Dictionary <String, String> Result = new Dictionary <String, String>();
            EXEReferencingVariable      Var    = this.FindReferencingVariableByName(VarName);

            if (Var == null)
            {
                return(Result);
            }
            CDClassInstance Inst = Var.RetrieveReferencedClassInstance(ExecutionSpace);

            if (Inst == null)
            {
                return(Result);
            }
            foreach (var Attribute in Inst.GetStateWithoutID())
            {
                Result[VarName + "." + Attribute.Key] = Attribute.Value;
            }

            return(Result);
        }
Ejemplo n.º 8
0
        public Dictionary <String, String> GetAllHandleStateAttrsDictRecursive(CDClassPool ExecutionSpace)
        {
            Dictionary <String, String> Result = new Dictionary <String, String>();
            Dictionary <String, String> Temp;

            foreach (EXEReferencingVariable Var in this.ReferencingVariables)
            {
                Temp = this.GetRefStateAttrsDictRecursive(ExecutionSpace, Var.Name);
                Temp.ToList().ForEach(x => Result.Add(x.Key, x.Value));
            }
            foreach (EXEReferencingSetVariable Var in this.SetReferencingVariables)
            {
                Temp = this.GetSetRefStateAttrsDictRecursive(ExecutionSpace, Var.Name);
                Temp.ToList().ForEach(x => Result.Add(x.Key, x.Value));
            }
            if (this.SuperScope != null)
            {
                Temp = this.SuperScope.GetAllHandleStateAttrsDictRecursive(ExecutionSpace);
                Temp.ToList().ForEach(x => Result.Add(x.Key, x.Value));
            }

            return(Result);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        //SetUloh1
        // We have variable name, attribute name and scope, in which to look for variable
        // We need to get the value of given attribute of given variable
        // If this does not exist, return null
        // You will use EXEScope.FindReferencingVariableByName() method, but you need to implement it first
        // user.name

        public String EvaluateAttributeValue(String ReferencingVariableName, String AttributeName, EXEScope Scope, CDClassPool ExecutionSpace)
        {
            EXEReferencingVariable ReferencingVariable = Scope.FindReferencingVariableByName(ReferencingVariableName);

            if (ReferencingVariable == null)
            {
                return(null);
            }
            CDClassInstance ClassInstance = ExecutionSpace.GetClassInstanceById(ReferencingVariable.ClassName, ReferencingVariable.ReferencedInstanceId);

            if (ClassInstance == null)
            {
                return(null);
            }
            return(ClassInstance.GetAttributeValue(AttributeName));
        }