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++]; // 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); }
private void BuildPropertyTypeAssignments(DataTable table) { foreach (DataRow row in table.Rows) { int propertyTypeId = TypeConverter.ToInt32(row["PropertyTypeId"]); int propertySetId = TypeConverter.ToInt32(row["PropertySetID"]); bool isDeclared = TypeConverter.ToBoolean(row["IsDeclared"]); PropertyType propertyType = _propertyTypes.GetItemById(propertyTypeId); if (propertyType == null) { throw new InvalidSchemaException(String.Concat(SR.Exceptions.Schema.Msg_PropertyTypeDoesNotExist, ": id=", propertyTypeId)); } PropertySet propertySet = null; if (propertyType.IsContentListProperty) { propertySet = _contentListTypes.GetItemById(propertySetId); } else { propertySet = _nodeTypes.GetItemById(propertySetId); } if (isDeclared) { AddPropertyTypeToPropertySet(propertyType, propertySet); } } }
private void BuildPropertySets(DataTable table, Dictionary <int, PropertySetType> propertySetTypes) { List <NodeTypeInfo> ntiList = new List <NodeTypeInfo>(); foreach (DataRow row in table.Rows) { int id = TypeConverter.ToInt32(row["PropertySetID"]); int parentID = row["ParentID"] is DBNull ? 0 : TypeConverter.ToInt32(row["ParentID"]); string name = TypeConverter.ToString(row["Name"]); string className = row["ClassName"] is DBNull ? null : TypeConverter.ToString(row["ClassName"]); PropertySetType propertySetType = propertySetTypes[TypeConverter.ToInt32(row["PropertySetTypeID"])]; switch (propertySetType) { case PropertySetType.NodeType: ntiList.Add(new NodeTypeInfo(id, parentID, name, className)); break; case PropertySetType.ContentListType: CreateContentListType(id, name); break; default: throw new InvalidSchemaException(String.Concat(SR.Exceptions.Schema.Msg_UnknownPropertySetType, propertySetType)); } } while (ntiList.Count > 0) { for (int i = ntiList.Count - 1; i >= 0; i--) { NodeTypeInfo nti = ntiList[i]; NodeType parent = null; if (nti.ParentId == 0 || ((parent = _nodeTypes.GetItemById(nti.ParentId)) != null)) { CreateNodeType(nti.Id, _nodeTypes.GetItemById(nti.ParentId), nti.Name, nti.ClassName); ntiList.Remove(nti); } } } }
private void BuildPropertyTypeAssignments(DataTable table) { foreach (DataRow row in table.Rows) { int propertyTypeId = TypeConverter.ToInt32(row["PropertyTypeId"]); int propertySetId = TypeConverter.ToInt32(row["PropertySetID"]); bool isDeclared = TypeConverter.ToBoolean(row["IsDeclared"]); PropertyType propertyType = _propertyTypes.GetItemById(propertyTypeId); if (propertyType == null) { throw new InvalidSchemaException(String.Concat(SR.Exceptions.Schema.Msg_PropertyTypeDoesNotExist, ": id=", propertyTypeId)); } PropertySet propertySet = null; if (propertyType.IsContentListProperty) { propertySet = _contentListTypes.GetItemById(propertySetId); } else { propertySet = _nodeTypes.GetItemById(propertySetId); } try { if (isDeclared) { AddPropertyTypeToPropertySet(propertyType, propertySet); } } catch (ArgumentNullException ex) { SnLog.WriteWarning("Unknown property set: " + propertySetId, properties: new Dictionary <string, object> { { "PropertyTypeId", propertyType.Id }, { "Content list types: ", string.Join(", ", _contentListTypes.Select(cl => cl.Id)) }, { "Node types: ", string.Join(", ", _nodeTypes.Select(nt => string.Format("{0} ({1})", nt.Name, nt.Id))) }, }); throw new InvalidSchemaException("Unknown property set: " + propertySetId, ex); } } }