public int AddMissingComponents(ParentChildRelationHierarchy hierarchy)
        {
            var result = 0;

            foreach (var relation in hierarchy.GetLevel(0))
            {
                if (AddComponent(relation))
                {
                    result++;
                }
            }

            if (hierarchy.LevelCount == 1)
            {
                return(result);
            }

            for (int i = 1; i < hierarchy.LevelCount; i++)
            {
                var level = hierarchy.GetLevel(i);
                foreach (var relation in level)
                {
                    if (AddComponent(relation))
                    {
                        result++;
                    }
                }
            }

            return(result);
        }
        public int UpdateComponents(ParentChildRelationHierarchy hierarchy)
        {
            var updatedCount = 0;

            foreach (var relation in hierarchy.GetAllParentChildRelations())
            {
                var sourceObject = relation.Child;
                var mapping      = _mappings[sourceObject.GetType()];

                var tuple     = mapping.GetComponentInfo(sourceObject);
                var component = _session.GetChildComponent(relation);
                if (!HasChanges(component, tuple.Item2))
                {
                    continue;
                }

                component.Fields.Clear();

                foreach (var pair in tuple.Item2)
                {
                    component.Fields.Add(pair.Key, pair.Value);
                }

                _session.UpdateComponent(component);
                updatedCount++;
            }

            return(updatedCount);
        }
        public int UpdateComponentTags(ParentChildRelationHierarchy hierarchy)
        {
            var updatedCount = 0;

            var tpl             = GetComponentTagMap();
            var componentTagMap = tpl.Item2;

            var componentMap = new Dictionary <Type, List <Component> >();

            foreach (var relation in hierarchy.GetAllParentChildRelations())
            {
                var sourceObject = relation.Child;
                var mapping      = _mappings[sourceObject.GetType()];
                var tuple        = mapping.GetComponentInfo(sourceObject);
                var component    = _session.GetChildComponent(relation);
                var tags         = mapping.GetTags(sourceObject);

                if ((tags == null || !tags.Any()) && !componentTagMap.ContainsKey(component.Id))
                {
                    continue;
                }

                updatedCount += MaintainTagsForComponent(tags, component, _session.GetAllTags());
            }

            return(updatedCount);
        }