Esempio n. 1
0
        /// <summary>
        /// Return the representation of the entities that the parameter entity depends
        /// </summary>
        public RelationDependency create(EntityClass entity, Model model)
        {
            RelationDependency toReturn = new RelationDependency(entity.Name);
            if (entityNames.Contains(entity.Name))
            {
                toReturn.IsReusable = true;
            }
            else
            {
                entityNames.Add(entity.Name);
            }
            foreach (EntityField field in entity.Fields)
            {
                if( field.Mult == Multiplicity.ManyToOne /*|| field.Mult == Multiplicity.ManyToMany*/)
                {
                    //RelationDependency relates = create((EntityClass)model[ GetEntityIndex(field.Type.Name, model) ], entity, model);
                    //toReturn.Dependencies.Add(relates);
                    toReturn.Dependencies.Add(create((EntityClass)model[ GetEntityIndex(field.Type.Name, model) ], model));
                }
            }

            if (entity.HasParent)
            {
                foreach (EntityField field in ((EntityClass)entity.Parent).Fields)
                {
                    if( field.Mult == Multiplicity.ManyToOne /*|| field.Mult == Multiplicity.ManyToMany */)
                    {
                        toReturn.Dependencies.Add(create((EntityClass)model[ GetEntityIndex(field.Type.Name, model) ], model));
                    }
                }
            }
            return toReturn;
        }
Esempio n. 2
0
        private string DependenciesWhithoutDeclarationString(RelationDependency deps)
        {
            StringBuilder toReturn = new StringBuilder();

            foreach (RelationDependency depRec in deps.Dependencies)
            {
                if (!depRec.IsReusable)
                {
                    toReturn.Append("_");
                    toReturn.Append(depRec.Name);
                    toReturn.Append("Persistance = ");
                    toReturn.Append(depRec.Name);
                    toReturn.Append("Persistance.GetSession(); \n\t\t\t");

                    toReturn.Append("_" + depRec.Name);
                    toReturn.Append(" = _" + depRec.Name);
                    toReturn.Append("Persistance.Create(); \n\t\t\t");
                }

                toReturn.Append(DependenciesWhithoutDeclarationString(depRec));

                toReturn.Append("_" + deps.Name);
                toReturn.Append("." + depRec.Name);
                toReturn.Append(" = _" + depRec.Name + "; \n\t\t\t");
            }
            toReturn.Append("_" + deps.Name);
            toReturn.Append("Persistance.Update ( _");
            toReturn.Append(deps.Name + " ); \n\n\t\t\t");

            return(toReturn.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Return the representation of the entities that the parameter entity depends
        /// </summary>
        public RelationDependency create(EntityClass entity, Model model)
        {
            RelationDependency toReturn = new RelationDependency(entity.Name);

            if (entityNames.Contains(entity.Name))
            {
                toReturn.IsReusable = true;
            }
            else
            {
                entityNames.Add(entity.Name);
            }
            foreach (EntityField field in entity.Fields)
            {
                if (field.Mult == Multiplicity.ManyToOne /*|| field.Mult == Multiplicity.ManyToMany*/)
                {
                    //RelationDependency relates = create((EntityClass)model[ GetEntityIndex(field.Type.Name, model) ], entity, model);
                    //toReturn.Dependencies.Add(relates);
                    toReturn.Dependencies.Add(create((EntityClass)model[GetEntityIndex(field.Type.Name, model)], model));
                }
            }

            if (entity.HasParent)
            {
                foreach (EntityField field in ((EntityClass)entity.Parent).Fields)
                {
                    if (field.Mult == Multiplicity.ManyToOne /*|| field.Mult == Multiplicity.ManyToMany */)
                    {
                        toReturn.Dependencies.Add(create((EntityClass)model[GetEntityIndex(field.Type.Name, model)], model));
                    }
                }
            }
            return(toReturn);
        }
Esempio n. 4
0
        private void TemplateClassTests(string output, EntityClass entity)
        {
            Dictionary <string, object> param      = new Dictionary <string, object>();
            RelationDependencyFactory   depFactory = new RelationDependencyFactory();
            RelationDependency          dep        = depFactory.create(entity, Project.Model);

            param.Add("entity", entity);
            param.Add("namespace", Project.Name + "." + ComponentType.Tests.ToString());
            param.Add("entityClass", (EntityClass)entity);
            param.Add("coreName", Project.Name.ToString() + "." + ComponentType.Core.ToString());
            param.Add("dataName", Project.Name.ToString() + "." + ComponentType.DataAccessLayer.ToString());
            param.Add("dep", dep);
            param.Add("depsWhithDeclaration", DependenciesString(dep));
            param.Add("depsWhithoutDeclaration", DependenciesWhithoutDeclarationString(dep));

            string template = GetResource("BaseClassTestsTemplate.vtl");

            Templates.Generate(template, output, param);
        }