public static Cardinality GetCardinality(this GraphMap graphMap, RoleMap roleMap, DataDictionary dataDictionary, string fixedIdentifierBoundary)
        {
            ClassTemplateMap ctm = graphMap.GetClassTemplateMap(roleMap.classMap.id, roleMap.classMap.index);

            if (ctm == null || ctm.classMap == null)
            {
                return(Cardinality.Self);
            }

            // determine cardinality to related class
            foreach (string identifier in roleMap.classMap.identifiers)
            {
                if (!(identifier.StartsWith(fixedIdentifierBoundary) && identifier.EndsWith(fixedIdentifierBoundary)))
                {
                    string[] propertyParts = identifier.Split('.');

                    if (propertyParts.Length > 2)
                    {
                        DataObject       dataObject       = dataDictionary.dataObjects.First(c => c.objectName == propertyParts[0]);
                        DataRelationship dataRelationship = dataObject.dataRelationships.First(c => c.relationshipName == propertyParts[1]);

                        if (dataRelationship.relationshipType == RelationshipType.OneToMany)
                        {
                            return(Cardinality.OneToMany);
                        }
                    }
                }
            }

            return(Cardinality.OneToOne);
        }
 public static void SetClassPath(this GraphMap graphMap)
 {
     if (graphMap != null && graphMap.classTemplateMaps != null && graphMap.classTemplateMaps[0] != null)
     {
         ClassTemplateMap ctm = graphMap.classTemplateMaps[0];
         ctm.classMap.path = ""; // class path for root class
         SetClassPath(graphMap, ctm.classMap);
     }
 }
        public static void AddTemplateMap(this GraphMap graphMap, ClassMap classMap, TemplateMap templateMap)
        {
            graphMap.AddClassMap(null, classMap);
            ClassTemplateMap classTemplateMap = graphMap.classTemplateMaps.Where(c => (c.classMap.id == classMap.id && c.classMap.index == classMap.index)).FirstOrDefault();

            var tmpIndexes = classTemplateMap.templateMaps.Where(x => x.id == templateMap.id).Select(x => x.index).ToArray();

            templateMap.index = tmpIndexes.Count() == 0 ? 0 : tmpIndexes.Max() + 1;

            if (classTemplateMap.classMap != null)
            {
                classTemplateMap.templateMaps.Add(templateMap);
            }
        }
        public static void DeleteTemplateMap(this GraphMap graphMap, string parentClassId, int parentClassIndex, int templateMapIndex)
        {
            ClassTemplateMap ctm = graphMap.GetClassTemplateMap(parentClassId, parentClassIndex);
            TemplateMap      tm  = ctm.templateMaps[templateMapIndex];

            foreach (RoleMap rm in tm.roleMaps)
            {
                DeleteRoleMap(graphMap, tm, rm.id);
            }

            ctm.templateMaps.RemoveAt(templateMapIndex);

            //int newIndex = 0;
            //foreach (TemplateMap tMap in ctm.templateMaps.Where(x => x.id == tm.id))
            //{
            //  tMap.index = newIndex++;
            //}

            graphMap.SetClassPath();
        }
        private static void SetClassPath(this GraphMap graphMap, ClassMap parentClassMap)
        {
            if (parentClassMap.path == null)
            {
                parentClassMap.path = "";
            }

            ClassTemplateMap ctm = graphMap.classTemplateMaps.SingleOrDefault(x => x.classMap.id == parentClassMap.id && x.classMap.index == parentClassMap.index);

            if (ctm != null)
            {
                ctm.classMap.path = parentClassMap.path;
                foreach (TemplateMap tm in ctm.templateMaps)
                {
                    foreach (RoleMap rm in tm.roleMaps.Where(x => x.classMap != null))
                    {
                        rm.classMap.path = string.Format("{0}/{1}/{2}({3})/{4}", ctm.classMap.path, ctm.classMap.id, tm.id, tm.index, rm.id).Trim('/');

                        SetClassPath(graphMap, rm.classMap);
                    }
                }
            }
        }
        public static void DeleteClassMap(this GraphMap graphMap, string classId, int classIndex)
        {
            ClassTemplateMap classTemplateMap = graphMap.GetClassTemplateMap(classId, classIndex);

            if (classTemplateMap != null && classTemplateMap.classMap != null)
            {
                List <TemplateMap> templateMaps = classTemplateMap.templateMaps;

                foreach (TemplateMap templateMap in templateMaps)
                {
                    RoleMap classRole = templateMap.roleMaps.Where(c => c.classMap != null).FirstOrDefault();
                    if (classRole != null)
                    {
                        graphMap.DeleteClassMap(classRole.classMap.id, classRole.classMap.index);
                        classRole.classMap = null;
                    }
                }

                templateMaps.Clear();
                graphMap.classTemplateMaps.Remove(classTemplateMap);
            }

            //RearrangeClassMapIndex(graphMap, classId);
        }
        public static void AddClassMap(this GraphMap graphMap, RoleMap roleMap, ClassMap classMap)
        {
            ClassTemplateMap ctm = graphMap.GetClassTemplateMap(classMap.id, classMap.index);

            if (ctm == null)
            {
                graphMap.classTemplateMaps.Add(
                    new ClassTemplateMap
                {
                    classMap     = classMap,
                    templateMaps = new TemplateMaps()
                }
                    );
            }
            else
            {
                ctm.classMap = classMap;
            }

            if (roleMap != null)
            {
                roleMap.classMap = classMap;
            }
        }