public static void DeleteRoleMap(this GraphMap graphMap, TemplateMap templateMap, string roleId)
        {
            RoleMap roleMap = templateMap.roleMaps.Where(c => c.id == roleId).FirstOrDefault();

            if (roleMap != null)
            {
                if (roleMap.classMap != null)
                {
                    graphMap.DeleteClassMap(roleMap.classMap.id, roleMap.classMap.index);
                    roleMap.value    = null;
                    roleMap.classMap = null;
                }
            }
        }
        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 TemplateMap Clone(this TemplateMap templateMap)
        {
            TemplateMap clone = new TemplateMap
            {
                id       = templateMap.id,
                name     = templateMap.name,
                roleMaps = new RoleMaps(),
            };

            foreach (RoleMap roleMap in templateMap.roleMaps)
            {
                clone.roleMaps.Add(roleMap.Clone());
            }

            return(clone);
        }
        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();
        }
        public static string BuildClassPath(this GraphMap graphMap, ClassMap parentClassMap, TemplateMap templateMap, RoleMap roleMap)
        {
            string path = string.Format("{0}/{1}/{2}({3})/{4}", parentClassMap.path, parentClassMap.id, templateMap.id, templateMap.index, roleMap.id).Trim('/');

            return(path);
        }