Example #1
0
        private static void WriteCreateOrModifyNodeTypes(SchemaEditor origSchema, SchemaEditor newSchema, List <PropertySet> modifiedPropertySets, SchemaWriter writer)
        {
            List <NodeType> _nodeTypesToEnumerate = new List <NodeType>();

            //-- collect only roots
            foreach (NodeType rootNodeType in newSchema.NodeTypes)
            {
                if (rootNodeType.Parent == null)
                {
                    _nodeTypesToEnumerate.Add(rootNodeType);
                }
            }

            int index = 0;

            while (index < _nodeTypesToEnumerate.Count)
            {
                NodeType currentType = _nodeTypesToEnumerate[index++];
                NodeType origType    = null;

                if (NeedToCreate <NodeType>(origSchema.NodeTypes, currentType))
                {
                    writer.CreateNodeType(currentType.Parent, currentType.Name, currentType.ClassName);
                }
                else
                {
                    origType = origSchema.NodeTypes[currentType.Name];
                    string origParentName = origType.Parent == null ? null : origType.Parent.Name;
                    string newParentName  = currentType.Parent == null ? null : currentType.Parent.Name;
                    bool   parentChanged  = origParentName != newParentName;
                    if (parentChanged || origType.ClassName != currentType.ClassName)
                    {
                        writer.ModifyNodeType(origType, currentType.Parent, currentType.ClassName);
                        if (!modifiedPropertySets.Contains(origType))
                        {
                            modifiedPropertySets.Add(origType);
                        }
                    }
                }

                //-- Property list (origType can be null)
                WriteAddOrRemovePropertyTypes(origType, currentType, modifiedPropertySets, writer);

                //-- Add children to enumerator
                _nodeTypesToEnumerate.AddRange(currentType.GetChildren());
            }
        }
Example #2
0
        //private static List<T> GetExclusiveTypesFromMain<T>(TypeCollection<T> mainSet, TypeCollection<T> subSet) where T : SchemaItem
        //{
        //    List<T> exclusiveTypes = new List<T>();
        //    foreach (T mainType in mainSet)
        //        if (subSet[mainType.Name] == null)
        //            exclusiveTypes.Add(mainType);
        //    return exclusiveTypes;
        //}
        private static List <NodeType> GetNodeTypeRootsToDelete(TypeCollection <NodeType> origSet, TypeCollection <NodeType> newSet)
        {
            //-- Walks (preorder) origSet NodeType tree and collects only deletable subtree roots.

            List <NodeType> _nodeTypeRootsToDelete = new List <NodeType>();
            List <NodeType> _nodeTypesToEnumerate  = new List <NodeType>();

            //-- collect only roots
            foreach (NodeType rootNodeType in origSet)
            {
                if (rootNodeType.Parent == null)
                {
                    _nodeTypesToEnumerate.Add(rootNodeType);
                }
            }

            int index = 0;

            while (index < _nodeTypesToEnumerate.Count)
            {
                NodeType currentType = _nodeTypesToEnumerate[index++];

                //-- ha nincs az ujban, akkor torolni kell, egyebkent a gyerekek mennek az enumeratorba
                //-- delete currentType if newSet does not contain it otherwise add its children to enumerator
                if (newSet.GetItemById(currentType.Id) == null)
                {
                    _nodeTypeRootsToDelete.Add(currentType);
                }
                else
                {
                    _nodeTypesToEnumerate.AddRange(currentType.GetChildren());
                }
            }

            return(_nodeTypeRootsToDelete);
        }