Exemplo n.º 1
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method gets the collection context associated with this node.</summary>
        ///
        /// <param name="solutionContext">The associated solution.</param>
        /// <param name="templateContext">The associated template.</param>
        /// <param name="modelContext">The associated model context.</param>
        ///--------------------------------------------------------------------------------
        public IEnterpriseEnumerable GetCollection(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext, ModelContextNode collectionType, InterpreterTypeCode interpreterType)
        {
            IDomainEnterpriseObject collectionContext = modelContext;

            if (ModelContext != null)
            {
                bool isValidContext;
                collectionContext = ModelContext.GetModelContext(solutionContext, templateContext, modelContext, out isValidContext);
                return(collectionType.GetCollection(solutionContext, templateContext, collectionContext));
            }
            else if (CurrentItem != null)
            {
                collectionContext = CurrentItem.GetModelContext(solutionContext, templateContext, modelContext);
                return(collectionType.GetCollection(solutionContext, templateContext, collectionContext));
            }
            else if (SpecCurrentItem != null)
            {
                collectionContext = SpecCurrentItem.GetModelContext(solutionContext, templateContext, modelContext);
                return(collectionType.GetCollection(solutionContext, templateContext, collectionContext));
            }
            else if (CollectionHelper != null)
            {
                return(CollectionHelper.GetCollection(solutionContext, templateContext, modelContext, collectionType, interpreterType));
            }
            return(null);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method gets the collection context associated with this node.</summary>
        ///
        /// <param name="solutionContext">The associated solution.</param>
        /// <param name="templateContext">The associated template.</param>
        /// <param name="modelContext">The associated model context.</param>
        /// <param name="collectionType">The type of collection to get.</param>
        /// <param name="interpreterType">The type of interpretation to perform.</param>
        ///--------------------------------------------------------------------------------
        public IEnterpriseEnumerable GetCollection(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext, ModelContextNode collectionType, InterpreterTypeCode interpreterType)
        {
            IDomainEnterpriseObject collectionContext = modelContext;

            if (ModelContext != null)
            {
                bool isValidContext;
                collectionContext = ModelContext.GetModelContext(solutionContext, templateContext, modelContext, out isValidContext);
            }
            else if (CurrentItem != null)
            {
                collectionContext = CurrentItem.GetModelContext(solutionContext, templateContext, modelContext);
            }
            else if (SpecCurrentItem != null)
            {
                collectionContext = SpecCurrentItem.GetModelContext(solutionContext, templateContext, modelContext);
            }
            if (MethodName == LanguageTerms.FindAllMethod && ModelProperty != null)
            {
                IEnterpriseEnumerable collection = collectionType.GetCollection(solutionContext, templateContext, collectionContext);
                if (collection != null)
                {
                    return(collection.FindItems(ModelProperty.ModelPropertyName, Parameter.GetObjectValue(solutionContext, templateContext, modelContext, interpreterType)));
                }
            }
            else if (MethodName == LanguageTerms.GetEntityAndBasesCollection)
            {
                // TODO: condense ability to get extended collections
                if (collectionType.ModelContextName == "Entity" && collectionContext is Entity)
                {
                    EnterpriseDataObjectList <Entity> entities = new EnterpriseDataObjectList <Entity>();
                    Entity currentEntity = collectionContext as Entity;
                    while (currentEntity != null)
                    {
                        entities.Add(currentEntity);
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(entities);
                }
                else if (collectionType.ModelContextName == "Property")
                {
                    EnterpriseDataObjectList <Property> items = new EnterpriseDataObjectList <Property>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Property loopItem in currentEntity.PropertyList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "PropertyReference")
                {
                    EnterpriseDataObjectList <PropertyReference> items = new EnterpriseDataObjectList <PropertyReference>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (PropertyReference loopItem in currentEntity.PropertyReferenceList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "EntityReference")
                {
                    EnterpriseDataObjectList <EntityReference> items = new EnterpriseDataObjectList <EntityReference>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (EntityReference loopItem in currentEntity.EntityReferenceList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Collection")
                {
                    EnterpriseDataObjectList <Collection> items = new EnterpriseDataObjectList <Collection>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Collection loopItem in currentEntity.CollectionList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Relationship")
                {
                    EnterpriseDataObjectList <Relationship> items = new EnterpriseDataObjectList <Relationship>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Relationship loopItem in currentEntity.RelationshipList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Index")
                {
                    EnterpriseDataObjectList <Index> items = new EnterpriseDataObjectList <Index>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Index loopItem in currentEntity.IndexList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Method")
                {
                    EnterpriseDataObjectList <Method> items = new EnterpriseDataObjectList <Method>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Method loopItem in currentEntity.MethodList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
            }
            else if (MethodName == LanguageTerms.GetBaseAndEntitiesCollection)
            {
                // TODO: condense ability to get extended collections
                if (collectionType.ModelContextName == "Entity" && collectionContext is Entity)
                {
                    EnterpriseDataObjectList <Entity> items = new EnterpriseDataObjectList <Entity>();
                    Entity currentEntity = collectionContext as Entity;
                    while (currentEntity != null)
                    {
                        items.Insert(0, currentEntity);
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Property")
                {
                    EnterpriseDataObjectList <Property> items = new EnterpriseDataObjectList <Property>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Property loopItem in currentEntity.PropertyList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "PropertyReference")
                {
                    EnterpriseDataObjectList <PropertyReference> items = new EnterpriseDataObjectList <PropertyReference>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (PropertyReference loopItem in currentEntity.PropertyReferenceList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "EntityReference")
                {
                    EnterpriseDataObjectList <EntityReference> items = new EnterpriseDataObjectList <EntityReference>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (EntityReference loopItem in currentEntity.EntityReferenceList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Collection")
                {
                    EnterpriseDataObjectList <Collection> items = new EnterpriseDataObjectList <Collection>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Collection loopItem in currentEntity.CollectionList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Relationship")
                {
                    EnterpriseDataObjectList <Relationship> items = new EnterpriseDataObjectList <Relationship>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Relationship loopItem in currentEntity.RelationshipList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Index")
                {
                    EnterpriseDataObjectList <Index> items = new EnterpriseDataObjectList <Index>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Index loopItem in currentEntity.IndexList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Method")
                {
                    EnterpriseDataObjectList <Method> items = new EnterpriseDataObjectList <Method>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    while (currentEntity != null)
                    {
                        foreach (Method loopItem in currentEntity.MethodList)
                        {
                            items.Add(loopItem);
                        }
                        currentEntity = currentEntity.BaseEntity;
                    }
                    return(items);
                }
            }
            else if (MethodName == LanguageTerms.ExtendingEntitiesCollection)
            {
                if (collectionType.ModelContextName == "Entity" && collectionContext is Entity)
                {
                    return((collectionContext as Entity).ExtendingEntites);
                }
                else if (collectionType.ModelContextName == "Property")
                {
                    EnterpriseDataObjectList <Property> items = new EnterpriseDataObjectList <Property>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    if (currentEntity != null)
                    {
                        foreach (Entity loopEntity in currentEntity.ExtendingEntites)
                        {
                            foreach (Property loopItem in loopEntity.PropertyList)
                            {
                                items.Add(loopItem);
                            }
                        }
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "PropertyReference")
                {
                    EnterpriseDataObjectList <PropertyReference> items = new EnterpriseDataObjectList <PropertyReference>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    if (currentEntity != null)
                    {
                        foreach (Entity loopEntity in currentEntity.ExtendingEntites)
                        {
                            foreach (PropertyReference loopItem in loopEntity.PropertyReferenceList)
                            {
                                items.Add(loopItem);
                            }
                        }
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "EntityReference")
                {
                    EnterpriseDataObjectList <EntityReference> items = new EnterpriseDataObjectList <EntityReference>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    if (currentEntity != null)
                    {
                        foreach (Entity loopEntity in currentEntity.ExtendingEntites)
                        {
                            foreach (EntityReference loopItem in loopEntity.EntityReferenceList)
                            {
                                items.Add(loopItem);
                            }
                        }
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Collection")
                {
                    EnterpriseDataObjectList <Collection> items = new EnterpriseDataObjectList <Collection>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    if (currentEntity != null)
                    {
                        foreach (Entity loopEntity in currentEntity.ExtendingEntites)
                        {
                            foreach (Collection loopItem in loopEntity.CollectionList)
                            {
                                items.Add(loopItem);
                            }
                        }
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Relationship")
                {
                    EnterpriseDataObjectList <Relationship> items = new EnterpriseDataObjectList <Relationship>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    if (currentEntity != null)
                    {
                        foreach (Entity loopEntity in currentEntity.ExtendingEntites)
                        {
                            foreach (Relationship loopItem in loopEntity.RelationshipList)
                            {
                                items.Add(loopItem);
                            }
                        }
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Index")
                {
                    EnterpriseDataObjectList <Index> items = new EnterpriseDataObjectList <Index>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    if (currentEntity != null)
                    {
                        foreach (Entity loopEntity in currentEntity.ExtendingEntites)
                        {
                            foreach (Index loopItem in loopEntity.IndexList)
                            {
                                items.Add(loopItem);
                            }
                        }
                    }
                    return(items);
                }
                else if (collectionType.ModelContextName == "Method")
                {
                    EnterpriseDataObjectList <Method> items = new EnterpriseDataObjectList <Method>();
                    bool   isValidContext;
                    Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity;
                    if (currentEntity != null)
                    {
                        foreach (Entity loopEntity in currentEntity.ExtendingEntites)
                        {
                            foreach (Method loopItem in loopEntity.MethodList)
                            {
                                items.Add(loopItem);
                            }
                        }
                    }
                    return(items);
                }
            }
            else if (MethodName == LanguageTerms.PathRelationships)
            {
                if (collectionType.ModelContextName == "Relationship" && collectionContext is Entity)
                {
                    return((collectionContext as Entity).PathRelationships);
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        ///--------------------------------------------------------------------------------
        /// <summary>Evaluate expression associated with this node.</summary>
        ///
        /// <param name="solutionContext">The associated solution.</param>
        /// <param name="templateContext">The associated template.</param>
        /// <param name="modelContext">The associated model context.</param>
        /// <param name="interpreterType">The type of interpretation to perform.</param>
        ///--------------------------------------------------------------------------------
        public string GetExpressionValue(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext, InterpreterTypeCode interpreterType)
        {
            string expression1Value = String.Empty;

            if (Expression1 != null)
            {
                expression1Value = Expression1.GetExpressionValue(solutionContext, templateContext, modelContext, interpreterType);
            }
            string expression2Value = String.Empty;

            if (Expression2 != null)
            {
                expression2Value = Expression2.GetExpressionValue(solutionContext, templateContext, modelContext, interpreterType);
            }
            if (String.IsNullOrEmpty(expression1Value))
            {
                expression1Value = "null";
            }
            if (String.IsNullOrEmpty(expression2Value))
            {
                expression2Value = "null";
            }
            long   expression1Long;
            long   expression2Long;
            double expression1Double;
            double expression2Double;

            if (Literal != null)
            {
                return(Literal.RawValue);
            }
            if (ModelProperty != null)
            {
                return(ModelProperty.GetPropertyStringValue(solutionContext, templateContext, modelContext, modelContext, interpreterType));
            }
            if (ModelContext != null)
            {
                bool isValidContext;
                IDomainEnterpriseObject nodeContext = ModelContext.GetModelContext(solutionContext, templateContext, modelContext, out isValidContext);
                if (nodeContext == null)
                {
                    return("null");
                }
                else
                {
                    if (nodeContext.ID == Guid.Empty || nodeContext.ID == null)
                    {
                        return("null");
                    }
                    return(nodeContext.ID.ToString());
                }
            }
            else if (CurrentItem != null)
            {
                IDomainEnterpriseObject nodeContext = CurrentItem.GetModelContext(solutionContext, templateContext, modelContext);
                if (nodeContext == null)
                {
                    return("null");
                }
                else
                {
                    return(nodeContext.ID.ToString());
                }
            }
            else if (SpecCurrentItem != null)
            {
                IDomainEnterpriseObject nodeContext = SpecCurrentItem.GetModelContext(solutionContext, templateContext, modelContext);
                if (nodeContext == null)
                {
                    return("null");
                }
                else
                {
                    return(nodeContext.ID.ToString());
                }
            }
            else if (Expression1 != null && Expression2 != null)
            {
                if (BinaryOperator != null)
                {
                    switch (BinaryOperator.Operator)
                    {
                    case "||":
                        if (Expression1.EvaluateExpression(solutionContext, templateContext, modelContext, interpreterType) || Expression2.EvaluateExpression(solutionContext, templateContext, modelContext, interpreterType))
                        {
                            return("true");
                        }
                        return("false");

                    case "&&":
                        if (Expression1.EvaluateExpression(solutionContext, templateContext, modelContext, interpreterType) && Expression2.EvaluateExpression(solutionContext, templateContext, modelContext, interpreterType))
                        {
                            return("true");
                        }
                        return("false");

                    case "==":
                        if (expression1Value == expression2Value)
                        {
                            return("true");
                        }
                        return("false");

                    case "!=":
                        if (expression1Value != expression2Value)
                        {
                            return("true");
                        }
                        return("false");

                    case "<":
                        if (long.TryParse(expression1Value, out expression1Long) == true && long.TryParse(expression2Value, out expression2Long) == true)
                        {
                            if (expression1Long < expression2Long)
                            {
                                return("true");
                            }
                        }
                        else if (double.TryParse(expression1Value, out expression1Double) == true && double.TryParse(expression2Value, out expression2Double) == true)
                        {
                            if (expression1Double < expression2Double)
                            {
                                return("true");
                            }
                        }
                        else
                        {
                            if (expression1Value.Length < expression2Value.Length)
                            {
                                return("true");
                            }
                        }
                        return("false");

                    case ">":
                        if (long.TryParse(expression1Value, out expression1Long) == true && long.TryParse(expression2Value, out expression2Long) == true)
                        {
                            if (expression1Long > expression2Long)
                            {
                                return("true");
                            }
                        }
                        else if (double.TryParse(expression1Value, out expression1Double) == true && double.TryParse(expression2Value, out expression2Double) == true)
                        {
                            if (expression1Double > expression2Double)
                            {
                                return("true");
                            }
                        }
                        else
                        {
                            if (expression1Value.Length > expression2Value.Length)
                            {
                                return("true");
                            }
                        }
                        return("false");

                    case "<=":
                        if (long.TryParse(expression1Value, out expression1Long) == true && long.TryParse(expression2Value, out expression2Long) == true)
                        {
                            if (expression1Long <= expression2Long)
                            {
                                return("true");
                            }
                        }
                        else if (double.TryParse(expression1Value, out expression1Double) == true && double.TryParse(expression2Value, out expression2Double) == true)
                        {
                            if (expression1Double <= expression2Double)
                            {
                                return("true");
                            }
                        }
                        else
                        {
                            if (expression1Value.Length <= expression2Value.Length)
                            {
                                return("true");
                            }
                        }
                        return("false");

                    case ">=":
                        if (long.TryParse(expression1Value, out expression1Long) == true && long.TryParse(expression2Value, out expression2Long) == true)
                        {
                            if (expression1Long >= expression2Long)
                            {
                                return("true");
                            }
                        }
                        else if (double.TryParse(expression1Value, out expression1Double) == true && double.TryParse(expression2Value, out expression2Double) == true)
                        {
                            if (expression1Double >= expression2Double)
                            {
                                return("true");
                            }
                        }
                        else
                        {
                            if (expression1Value.Length >= expression2Value.Length)
                            {
                                return("true");
                            }
                        }
                        return("false");

                    default:
                        return("false");
                    }
                }
                else if (MathOperator != null)
                {
                    switch (MathOperator.Operator)
                    {
                    case "+":
                        if (long.TryParse(expression1Value, out expression1Long) == true && long.TryParse(expression2Value, out expression2Long) == true)
                        {
                            return((expression1Long + expression2Long).ToString());
                        }
                        else if (double.TryParse(expression1Value, out expression1Double) == true && double.TryParse(expression2Value, out expression2Double) == true)
                        {
                            return((expression1Double + expression2Double).ToString());
                        }
                        else
                        {
                            return(expression1Value + expression2Value);
                        }

                    case "-":
                        if (long.TryParse(expression1Value, out expression1Long) == true && long.TryParse(expression2Value, out expression2Long) == true)
                        {
                            return((expression1Long - expression2Long).ToString());
                        }
                        else if (double.TryParse(expression1Value, out expression1Double) == true && double.TryParse(expression2Value, out expression2Double) == true)
                        {
                            return((expression1Double - expression2Double).ToString());
                        }
                        else
                        {
                            return(expression1Value.Replace(expression2Value, ""));
                        }

                    case "*":
                        if (long.TryParse(expression1Value, out expression1Long) == true && long.TryParse(expression2Value, out expression2Long) == true)
                        {
                            return((expression1Long * expression2Long).ToString());
                        }
                        else if (double.TryParse(expression1Value, out expression1Double) == true && double.TryParse(expression2Value, out expression2Double) == true)
                        {
                            return((expression1Double * expression2Double).ToString());
                        }
                        break;

                    case "/":
                        if (long.TryParse(expression1Value, out expression1Long) == true && long.TryParse(expression2Value, out expression2Long) == true && expression2Long != 0)
                        {
                            return((expression1Long / expression2Long).ToString());
                        }
                        else if (double.TryParse(expression1Value, out expression1Double) == true && double.TryParse(expression2Value, out expression2Double) == true && expression2Double != 0.00)
                        {
                            return((expression1Double / expression2Double).ToString());
                        }
                        break;

                    default:
                        break;
                    }
                    return("null");
                }
            }
            else if (Expression1 != null)
            {
                return(Expression1.GetExpressionValue(solutionContext, templateContext, modelContext, interpreterType));
            }
            return("null");
        }