public void SchEd_WriterCalling_RemoveOverriddenPropertyFromNodeType() { Test(() => { SchemaEditor ed1 = new SchemaEditor(); SchemaEditor ed2 = new SchemaEditor(); SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2); TestSchemaWriter wr = new TestSchemaWriter(); //-- create original PropertyType pt1 = CreatePropertyType(ed1, "PT1", DataType.String, 1); NodeType nt1 = CreateNodeType(ed1, null, "NT1", "NT1", 1); NodeType nt2 = CreateNodeType(ed1, nt1, "NT2", "NT2", 2); NodeType nt3 = CreateNodeType(ed1, nt2, "NT3", "NT3", 3); NodeType nt4 = CreateNodeType(ed1, nt3, "NT4", "NT4", 4); NodeType nt5 = CreateNodeType(ed1, nt4, "NT5", "NT5", 5); ed1.AddPropertyTypeToPropertySet(pt1, nt4); ed1.AddPropertyTypeToPropertySet(pt1, nt2); //-- create current XmlDocument xd = new XmlDocument(); xd.LoadXml(ed1.ToXml()); ed2.Load(xd); //-- edit ed2.RemovePropertyTypeFromPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT4"]); //-- register ed2Acc.RegisterSchema(ed1, wr); //-- test string log = wr.Log.Replace("\r\n", ""); Assert.IsTrue(log == "Open();UpdatePropertyTypeDeclarationState(propType=<PT1>, newSet=<NT4>, isDeclared=<False>);Close();"); }); }
public void SchemaEditor_RemovePropertyType_FromDeclarerType() { //-- krealunk egy torolhetot es felulirjuk SchemaEditor editor = new SchemaEditor(); NodeType nt1 = editor.CreateNodeType(null, "nt1"); NodeType nt2 = editor.CreateNodeType(nt1, "nt2"); PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0); editor.AddPropertyTypeToPropertySet(slot, nt1); //-- meg kell jelenjen mindketton PropertyType pt1 = nt1.PropertyTypes["slot"]; PropertyType pt2 = nt2.PropertyTypes["slot"]; //-- toroljuk a deklaralas eredeti helyerol PropertyType pt = editor.PropertyTypes["slot"]; editor.RemovePropertyTypeFromPropertySet(pt, nt1); //-- el kell tunjon mindkettorol pt1 = nt1.PropertyTypes["slot"]; pt2 = nt2.PropertyTypes["slot"]; Assert.IsNull(nt1.PropertyTypes["slot"], "Ancestor PropertyType was not deleted"); Assert.IsNull(nt2.PropertyTypes["slot"], "Inherited PropertyType was not deleted"); }
public void SchemaEditor_RemovePropertyType_FromDeclarerType() { //-- create a deletable and inherit from it SchemaEditor editor = new SchemaEditor(); NodeType nt1 = editor.CreateNodeType(null, "nt1", "t1"); NodeType nt2 = editor.CreateNodeType(nt1, "nt2", "t2"); PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0); editor.AddPropertyTypeToPropertySet(slot, nt1); //-- propertyType need to appear on both nodeType PropertyType pt1 = nt1.PropertyTypes["slot"]; PropertyType pt2 = nt2.PropertyTypes["slot"]; //-- delete from the original place PropertyType pt = editor.PropertyTypes["slot"]; editor.RemovePropertyTypeFromPropertySet(pt, nt1); //-- propertyType need to disappear from both nodeType pt1 = nt1.PropertyTypes["slot"]; pt2 = nt2.PropertyTypes["slot"]; Assert.IsNull(nt1.PropertyTypes["slot"], "Ancestor PropertyType was not deleted"); Assert.IsNull(nt2.PropertyTypes["slot"], "Inherited PropertyType was not deleted"); }
public void SchemaEditor_RemoveAncestorOfOverriddenPropertyFromNodeType() { SchemaEditor editor = new SchemaEditor(); PropertyType pt1 = editor.CreatePropertyType("PT1", DataType.String); NodeType nt1 = editor.CreateNodeType(null, "NT1", "T1"); NodeType nt2 = editor.CreateNodeType(nt1, "NT2", "T2"); NodeType nt3 = editor.CreateNodeType(nt2, "NT3", "T3"); NodeType nt4 = editor.CreateNodeType(nt3, "NT4", "T4"); NodeType nt5 = editor.CreateNodeType(nt4, "NT5", "T5"); editor.AddPropertyTypeToPropertySet(pt1, nt4); editor.AddPropertyTypeToPropertySet(pt1, nt2); editor.RemovePropertyTypeFromPropertySet(pt1, nt2); Assert.IsNull(nt1.PropertyTypes["PT1"], "#1"); Assert.IsNull(nt2.PropertyTypes["PT1"], "#2"); Assert.IsNull(nt3.PropertyTypes["PT1"], "#3"); Assert.IsNotNull(nt4.PropertyTypes["PT1"], "#4"); Assert.IsNotNull(nt5.PropertyTypes["PT1"], "#5"); Assert.IsNull(nt1.DeclaredPropertyTypes["PT1"], "#6"); Assert.IsNull(nt2.DeclaredPropertyTypes["PT1"], "#7"); Assert.IsNull(nt3.DeclaredPropertyTypes["PT1"], "#8"); Assert.IsNotNull(nt4.DeclaredPropertyTypes["PT1"], "#9"); Assert.IsNull(nt5.DeclaredPropertyTypes["PT1"], "#10"); }
public void SchemaEditor_RemovePropertyType_FromTopReDeclarerType() { SchemaEditor editor = new SchemaEditor(); NodeType nt1 = editor.CreateNodeType(null, "nt1", "t1"); NodeType nt2 = editor.CreateNodeType(nt1, "nt2", "t2"); NodeType nt3 = editor.CreateNodeType(nt2, "nt3", "t3"); PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0); editor.AddPropertyTypeToPropertySet(slot, nt2); editor.AddPropertyTypeToPropertySet(slot, nt1); //-- propertyType need to appear in all three nodeTypes PropertyType pt1 = nt1.PropertyTypes["slot"]; PropertyType pt2 = nt2.PropertyTypes["slot"]; PropertyType pt3 = nt3.PropertyTypes["slot"]; //-- delete from the original place PropertyType pt = editor.PropertyTypes["slot"]; editor.RemovePropertyTypeFromPropertySet(pt, nt1); //-- propertyType need to disappear from all three nodeTypes pt1 = nt1.PropertyTypes["slot"]; pt2 = nt2.PropertyTypes["slot"]; pt3 = nt3.PropertyTypes["slot"]; Assert.IsNull(nt1.PropertyTypes["slot"], "#1"); Assert.IsNotNull(nt2.PropertyTypes["slot"], "#2"); Assert.IsNotNull(nt3.PropertyTypes["slot"], "#3"); }
public void SchemaEditor_RemovePropertyType_FromTopReDeclarerType() { SchemaEditor editor = new SchemaEditor(); NodeType nt1 = editor.CreateNodeType(null, "nt1"); NodeType nt2 = editor.CreateNodeType(nt1, "nt2"); NodeType nt3 = editor.CreateNodeType(nt2, "nt3"); PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0); editor.AddPropertyTypeToPropertySet(slot, nt2); editor.AddPropertyTypeToPropertySet(slot, nt1); //-- meg kell jelenjen mindharmon PropertyType pt1 = nt1.PropertyTypes["slot"]; PropertyType pt2 = nt2.PropertyTypes["slot"]; PropertyType pt3 = nt3.PropertyTypes["slot"]; //-- toroljuk a deklaralas eredeti helyerol PropertyType pt = editor.PropertyTypes["slot"]; editor.RemovePropertyTypeFromPropertySet(pt, nt1); //-- el kell tunjon mindkettorol pt1 = nt1.PropertyTypes["slot"]; pt2 = nt2.PropertyTypes["slot"]; pt3 = nt3.PropertyTypes["slot"]; Assert.IsNull(nt1.PropertyTypes["slot"], "#1"); Assert.IsNotNull(nt2.PropertyTypes["slot"], "#2"); Assert.IsNotNull(nt3.PropertyTypes["slot"], "#3"); }
public void SchemaWriter_RemovePropertyTypeFromNodeType() { IntegrationTest(() => { var ed = new SchemaEditor(); ed.Load(); var nt = ed.CreateNodeType(null, "NT1-" + Guid.NewGuid(), "ClassName1"); var pt0 = ed.CreatePropertyType("PT0-" + Guid.NewGuid(), DataType.String, GetNextMapping(ed, false)); var pt1 = ed.CreatePropertyType("PT1-" + Guid.NewGuid(), DataType.String, GetNextMapping(ed, false)); var pt2 = ed.CreatePropertyType("PT2-" + Guid.NewGuid(), DataType.String, GetNextMapping(ed, false)); var pt3 = ed.CreatePropertyType("PT3-" + Guid.NewGuid(), DataType.String, GetNextMapping(ed, false)); var pt4 = ed.CreatePropertyType("PT4-" + Guid.NewGuid(), DataType.String, GetNextMapping(ed, false)); nt.AddPropertyType(pt0); nt.AddPropertyType(pt1); nt.AddPropertyType(pt2); nt.AddPropertyType(pt3); nt.AddPropertyType(pt4); ed.Register(); // ACTION ed = new SchemaEditor(); ed.Load(); nt = ed.NodeTypes[nt.Name]; pt0 = ed.PropertyTypes[pt0.Name]; pt1 = ed.PropertyTypes[pt1.Name]; pt2 = ed.PropertyTypes[pt2.Name]; pt3 = ed.PropertyTypes[pt3.Name]; pt4 = ed.PropertyTypes[pt4.Name]; var ptX = ed.CreatePropertyType("PTX-" + Guid.NewGuid(), DataType.String, GetNextMapping(ed, false)); ed.RemovePropertyTypeFromPropertySet(pt4, nt); // last ed.RemovePropertyTypeFromPropertySet(pt2, nt); // middle ed.RemovePropertyTypeFromPropertySet(pt0, nt); // first ed.RemovePropertyTypeFromPropertySet(pt0, nt); // first ed.RemovePropertyTypeFromPropertySet(ptX, nt); // not a member (without error) ed.Register(); // ASSERT var schema = DP.LoadSchemaAsync(CancellationToken.None).GetAwaiter().GetResult(); var ltData = schema.NodeTypes.First(x => x.Name == nt.Name); AssertSequenceEqual(new[] { pt1.Name, pt3.Name }, ltData.Properties); }); }
public void SchemaEditor_RemovePropertyType_WrongContext() { //-- wrong context SchemaEditor editor = new SchemaEditor(); NodeType nt = editor.CreateNodeType(null, "nt", "t"); PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0); editor.AddPropertyTypeToPropertySet(slot, nt); SchemaEditor editor1 = new SchemaEditor(); nt = editor1.CreateNodeType(null, "nt", "t"); slot = editor1.CreatePropertyType("slot", DataType.String, 0); editor1.AddPropertyTypeToPropertySet(slot, nt); editor.RemovePropertyTypeFromPropertySet(editor1.PropertyTypes["slot"], editor1.NodeTypes["nt"]); }
public void SchemaEditor_RemovePropertyType_Inherited() { SchemaEditor editor = new SchemaEditor(); NodeType nt1 = editor.CreateNodeType(null, "nt1", "t1"); NodeType nt2 = editor.CreateNodeType(nt1, "nt2", "t2"); PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0); editor.AddPropertyTypeToPropertySet(slot, nt1); PropertyType pt2 = nt2.PropertyTypes["slot"]; editor.RemovePropertyTypeFromPropertySet(pt2, nt2); Assert.IsNotNull(nt1.PropertyTypes["slot"], "#1"); Assert.IsNotNull(nt2.PropertyTypes["slot"], "#2"); Assert.IsNotNull(nt1.DeclaredPropertyTypes["slot"], "#3"); Assert.IsNull(nt2.DeclaredPropertyTypes["slot"], "#4"); }
private bool RemoveUnusedFields(Dictionary <string, FieldDescriptor> fieldInfoList, Dictionary <string, List <string> > oldBindings, ContentListType listType, SchemaEditor editor) { bool hasChanges = false; for (int i = _fieldSettings.Count - 1; i >= 0; i--) { FieldSetting oldType = _fieldSettings[i]; bool needtoDelete = !fieldInfoList.ContainsKey(oldType.Name); if (!needtoDelete) { FieldDescriptor newType = fieldInfoList[oldType.Name]; if (oldType.DataTypes.Length != newType.DataTypes.Length) { needtoDelete = true; } else { for (int j = 0; j < oldType.DataTypes.Length; j++) { if (oldType.DataTypes[j] != newType.DataTypes[j]) { needtoDelete = true; break; } } } } if (needtoDelete) { hasChanges = true; foreach (string binding in oldType.Bindings) { PropertyType oldPropertyType = editor.PropertyTypes[binding]; editor.RemovePropertyTypeFromPropertySet(oldPropertyType, listType); } _fieldSettings.RemoveAt(i); oldBindings.Remove(oldType.Name); } } //-- Apply changes. Slot reusing prerequisit: values of unused slots must be null. //if (hasChanges) // editor.Register(); return(hasChanges); }
public void SchEd_WriterCalling_Complex_01() { Test(() => { SchemaEditor ed1 = new SchemaEditor(); SchemaEditor ed2 = new SchemaEditor(); SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2); TestSchemaWriter wr = new TestSchemaWriter(); //-- create original PropertyType ptX = CreatePropertyType(ed1, "X", DataType.String, 1); PropertyType ptY = CreatePropertyType(ed1, "Y", DataType.String, 2); PropertyType ptZ = CreatePropertyType(ed1, "Z", DataType.String, 3); NodeType ntA = CreateNodeType(ed1, null, "A", null, 1); NodeType ntB = CreateNodeType(ed1, ntA, "B", null, 2); NodeType ntC = CreateNodeType(ed1, ntB, "C", null, 3); ed1.AddPropertyTypeToPropertySet(ptX, ntB); ed1.AddPropertyTypeToPropertySet(ptY, ntC); ed1.AddPropertyTypeToPropertySet(ptX, ntA); //-- create current XmlDocument xd = new XmlDocument(); xd.LoadXml(ed1.ToXml()); ed2.Load(xd); ptX = ed2.PropertyTypes["X"]; ptY = ed2.PropertyTypes["Y"]; ptZ = ed2.PropertyTypes["Z"]; ntA = ed2.NodeTypes["A"]; ntB = ed2.NodeTypes["B"]; ntC = ed2.NodeTypes["C"]; //-- edit ed2.RemovePropertyTypeFromPropertySet(ptX, ntA); //-- register ed2Acc.RegisterSchema(ed1, wr); //-- test string log = wr.Log.Replace("\r\n", ""); Assert.IsTrue(log == "Open();RemovePropertyTypeFromPropertySet(propertyType=<X>, owner=<A>);Close();"); }); }
public void SchEd_WriterCalling_RemoveAncestorOfOverriddenPropertyFromNodeType() { SchemaEditor ed1 = new SchemaEditor(); SchemaEditor ed2 = new SchemaEditor(); SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2); TestSchemaWriter wr = new TestSchemaWriter(); //-- create original PropertyType pt1 = CreatePropertyType(ed1, "PT1", DataType.String, 1); NodeType nt1 = CreateNodeType(ed1, null, "NT1", "NT1", 1); NodeType nt2 = CreateNodeType(ed1, nt1, "NT2", "NT2", 2); NodeType nt3 = CreateNodeType(ed1, nt2, "NT3", "NT3", 3); NodeType nt4 = CreateNodeType(ed1, nt3, "NT4", "NT4", 4); NodeType nt5 = CreateNodeType(ed1, nt4, "NT5", "NT5", 5); ed1.AddPropertyTypeToPropertySet(pt1, nt4); ed1.AddPropertyTypeToPropertySet(pt1, nt2); //-- create current XmlDocument xd = new XmlDocument(); xd.LoadXml(ed1.ToXml()); ed2.Load(xd); //-- edit ed2.RemovePropertyTypeFromPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT2"]); //-- register ed2Acc.RegisterSchema(ed1, wr); //-- test string expectedLog = @" Open(); RemovePropertyTypeFromPropertySet(propertyType=<PT1>, owner=<NT2>); RemovePropertyTypeFromPropertySet(propertyType=<PT1>, owner=<NT3>); Close();" .Replace("\r\n", "").Replace("\t", "").Replace(" ", ""); string log = wr.Log.Replace("\r\n", "").Replace(" ", ""); Assert.IsTrue(log == expectedLog); }
internal static void ApplyChangesInEditor(ContentType contentType, SchemaEditor editor) { // Find ContentHandler var handlerType = TypeResolver.GetType(contentType.HandlerName, false); if (handlerType == null) { throw new RegistrationException(string.Concat( SR.Exceptions.Registration.Msg_ContentHandlerNotFound, ": ", contentType.HandlerName)); } // parent type NodeType parentNodeType = null; if (contentType.ParentTypeName != null) { parentNodeType = editor.NodeTypes[contentType.ParentTypeName]; if (parentNodeType == null) { throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_UnknownParentContentType, contentType.Name); } // make sure that all content handlers defined on the parent chain exist var pnt = parentNodeType; while (pnt != null) { var ht = TypeResolver.GetType(pnt.ClassName, false); if (ht == null) { throw new RegistrationException($"Unknown content handler: {pnt.ClassName}"); } pnt = pnt.Parent; } } // handler type NodeType nodeType = editor.NodeTypes[contentType.Name]; if (nodeType == null) { nodeType = editor.CreateNodeType(parentNodeType, contentType.Name, contentType.HandlerName); } if (nodeType.ClassName != contentType.HandlerName) { editor.ModifyNodeType(nodeType, contentType.HandlerName); } if (nodeType.Parent != parentNodeType) { editor.ModifyNodeType(nodeType, parentNodeType); } // 1: ContentHandler properties NodeTypeRegistration ntReg = ParseAttributes(handlerType); if (ntReg == null) { throw new ContentRegistrationException( SR.Exceptions.Registration.Msg_DefinedHandlerIsNotAContentHandler, contentType.Name); } // 2: Field properties foreach (FieldSetting fieldSetting in contentType.FieldSettings) { Type[][] slots = fieldSetting.HandlerSlots; int fieldSlotCount = slots.GetLength(0); if (fieldSetting.Bindings.Count != fieldSlotCount) { throw new ContentRegistrationException(String.Format(CultureInfo.InvariantCulture, SR.Exceptions.Registration.Msg_FieldBindingsCount_1, fieldSlotCount), contentType.Name, fieldSetting.Name); } for (int i = 0; i < fieldSetting.Bindings.Count; i++) { string propName = fieldSetting.Bindings[i]; var dataType = fieldSetting.DataTypes[i]; CheckDataType(propName, dataType, contentType.Name, editor); PropertyInfo propInfo = handlerType.GetProperty(propName); if (propInfo != null) { // #1: there is a property under the slot: bool ok = false; for (int j = 0; j < slots[i].Length; j++) { if (slots[i][j].IsAssignableFrom(propInfo.PropertyType)) { PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propName); if (propInfo.DeclaringType != handlerType) { if (propReg == null) { object[] attrs = propInfo.GetCustomAttributes(typeof(RepositoryPropertyAttribute), false); if (attrs.Length > 0) { propReg = new PropertyTypeRegistration(propInfo, (RepositoryPropertyAttribute)attrs[0]); ntReg.PropertyTypeRegistrations.Add(propReg); } } } if (propReg != null && propReg.DataType != fieldSetting.DataTypes[i]) { throw new ContentRegistrationException(String.Concat( "The data type of the field in the content type definition does not match the data type of its content handler's property. ", "Please modify the field type in the content type definition. ", "ContentTypeDefinition: '", contentType.Name, "', FieldName: '", fieldSetting.Name, "', DataType of Field's binding: '", fieldSetting.DataTypes[i], "', ContentHandler: '", handlerType.FullName, "', PropertyName: '", propReg.Name, "', DataType of property: '", propReg.DataType, "'")); } ok = true; fieldSetting.HandlerSlotIndices[i] = j; fieldSetting.PropertyIsReadOnly = !PropertyHasPublicSetter(propInfo); break; } } if (!ok) { if (fieldSetting.ShortName == "Reference" || fieldSetting.DataTypes[i] == RepositoryDataType.Reference) { CheckReference(propInfo, slots[i], contentType, fieldSetting); } else { throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_PropertyAndFieldAreNotConnectable, contentType.Name, fieldSetting.Name); } } } else { // #2: there is not a property under the slot: PropertyTypeRegistration propReg = new PropertyTypeRegistration(propName, dataType); ntReg.PropertyTypeRegistrations.Add(propReg); } } } // Collect deletables. Check equals foreach (PropertyType propType in nodeType.PropertyTypes.ToArray()) { PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propType.Name); if (propReg == null) { editor.RemovePropertyTypeFromPropertySet(propType, nodeType); } } // Register foreach (PropertyTypeRegistration ptReg in ntReg.PropertyTypeRegistrations) { PropertyType propType = nodeType.PropertyTypes[ptReg.Name]; if (propType == null) { propType = editor.PropertyTypes[ptReg.Name]; if (propType == null) { propType = editor.CreatePropertyType(ptReg.Name, ConvertDataType(ptReg.DataType)); } editor.AddPropertyTypeToPropertySet(propType, nodeType); } } }
public void SchemaEditor_RemoveAncestorOfOverriddenPropertyFromNodeType() { SchemaEditor editor = new SchemaEditor(); PropertyType pt1 = editor.CreatePropertyType("PT1", DataType.String); NodeType nt1 = editor.CreateNodeType(null, "NT1"); NodeType nt2 = editor.CreateNodeType(nt1, "NT2"); NodeType nt3 = editor.CreateNodeType(nt2, "NT3"); NodeType nt4 = editor.CreateNodeType(nt3, "NT4"); NodeType nt5 = editor.CreateNodeType(nt4, "NT5"); editor.AddPropertyTypeToPropertySet(pt1, nt4); editor.AddPropertyTypeToPropertySet(pt1, nt2); editor.RemovePropertyTypeFromPropertySet(pt1, nt2); Assert.IsNull(nt1.PropertyTypes["PT1"], "#1"); Assert.IsNull(nt2.PropertyTypes["PT1"], "#2"); Assert.IsNull(nt3.PropertyTypes["PT1"], "#3"); Assert.IsNotNull(nt4.PropertyTypes["PT1"], "#4"); Assert.IsNotNull(nt5.PropertyTypes["PT1"], "#5"); Assert.IsNull(nt1.DeclaredPropertyTypes["PT1"], "#6"); Assert.IsNull(nt2.DeclaredPropertyTypes["PT1"], "#7"); Assert.IsNull(nt3.DeclaredPropertyTypes["PT1"], "#8"); Assert.IsNotNull(nt4.DeclaredPropertyTypes["PT1"], "#9"); Assert.IsNull(nt5.DeclaredPropertyTypes["PT1"], "#10"); }
public void SchemaEditor_RemovePropertyType_WrongContext() { //-- hiba: hibas context SchemaEditor editor = new SchemaEditor(); NodeType nt = editor.CreateNodeType(null, "nt"); PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0); editor.AddPropertyTypeToPropertySet(slot, nt); SchemaEditor editor1 = new SchemaEditor(); nt = editor1.CreateNodeType(null, "nt"); slot = editor1.CreatePropertyType("slot", DataType.String, 0); editor1.AddPropertyTypeToPropertySet(slot, nt); editor.RemovePropertyTypeFromPropertySet(editor1.PropertyTypes["slot"], editor1.NodeTypes["nt"]); }
public void SchemaEditor_RemovePropertyType_Inherited() { SchemaEditor editor = new SchemaEditor(); NodeType nt1 = editor.CreateNodeType(null, "nt1"); NodeType nt2 = editor.CreateNodeType(nt1, "nt2"); PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0); editor.AddPropertyTypeToPropertySet(slot, nt1); PropertyType pt2 = nt2.PropertyTypes["slot"]; editor.RemovePropertyTypeFromPropertySet(pt2, nt2); Assert.IsNotNull(nt1.PropertyTypes["slot"], "#1"); Assert.IsNotNull(nt2.PropertyTypes["slot"], "#2"); Assert.IsNotNull(nt1.DeclaredPropertyTypes["slot"], "#3"); Assert.IsNull(nt2.DeclaredPropertyTypes["slot"], "#4"); }
public void SchEd_WriterCalling_RemoveAncestorOfOverriddenPropertyFromNodeType() { SchemaEditor ed1 = new SchemaEditor(); SchemaEditor ed2 = new SchemaEditor(); SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2); TestSchemaWriter wr = new TestSchemaWriter(); //-- create original PropertyType pt1 = CreatePropertyType(ed1, "PT1", DataType.String, 1); NodeType nt1 = CreateNodeType(ed1, null, "NT1", "NT1", 1); NodeType nt2 = CreateNodeType(ed1, nt1, "NT2", "NT2", 2); NodeType nt3 = CreateNodeType(ed1, nt2, "NT3", "NT3", 3); NodeType nt4 = CreateNodeType(ed1, nt3, "NT4", "NT4", 4); NodeType nt5 = CreateNodeType(ed1, nt4, "NT5", "NT5", 5); ed1.AddPropertyTypeToPropertySet(pt1, nt4); ed1.AddPropertyTypeToPropertySet(pt1, nt2); //-- create current XmlDocument xd = new XmlDocument(); xd.LoadXml(ed1.ToXml()); ed2.Load(xd); //-- edit ed2.RemovePropertyTypeFromPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT2"]); //-- register ed2Acc.RegisterSchema(ed1, wr); //-- test string expectedLog = @" Open(); RemovePropertyTypeFromPropertySet(propertyType=<PT1>, owner=<NT2>); RemovePropertyTypeFromPropertySet(propertyType=<PT1>, owner=<NT3>); Close();".Replace("\r\n", "").Replace("\t", "").Replace(" ", ""); string log = wr.Log.Replace("\r\n", "").Replace(" ", ""); Assert.IsTrue(log == expectedLog); }
private bool RemoveUnusedFields(Dictionary<string, FieldDescriptor> fieldInfoList, Dictionary<string, List<string>> oldBindings, ContentListType listType, SchemaEditor editor) { bool hasChanges = false; for (int i = _fieldSettings.Count - 1; i >= 0; i--) { FieldSetting oldType = _fieldSettings[i]; bool needtoDelete = !fieldInfoList.ContainsKey(oldType.Name); if (!needtoDelete) { FieldDescriptor newType = fieldInfoList[oldType.Name]; if (oldType.DataTypes.Length != newType.DataTypes.Length) { needtoDelete = true; } else { for (int j = 0; j < oldType.DataTypes.Length; j++) { if (oldType.DataTypes[j] != newType.DataTypes[j]) { needtoDelete = true; break; } } } } if (needtoDelete) { hasChanges = true; foreach (string binding in oldType.Bindings) { PropertyType oldPropertyType = editor.PropertyTypes[binding]; editor.RemovePropertyTypeFromPropertySet(oldPropertyType, listType); } _fieldSettings.RemoveAt(i); oldBindings.Remove(oldType.Name); } } //-- Apply changes. Slot reusing prerequisit: values of unused slots must be null. //if (hasChanges) // editor.Register(); return hasChanges; }
internal static void ApplyChangesInEditor(ContentType contentType, SchemaEditor editor) { //-- Find ContentHandler Type handlerType = TypeHandler.GetType(contentType.HandlerName); if (handlerType == null) throw new RegistrationException(String.Concat( SR.Exceptions.Registration.Msg_ContentHandlerNotFound, ": ", contentType.HandlerName)); //-- parent type NodeType parentNodeType = null; if (contentType.ParentTypeName != null) { parentNodeType = editor.NodeTypes[contentType.ParentTypeName]; if (parentNodeType == null) throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_UnknownParentContentType, contentType.Name); } //-- handler type NodeType nodeType = editor.NodeTypes[contentType.Name]; if (nodeType == null) nodeType = editor.CreateNodeType(parentNodeType, contentType.Name, contentType.HandlerName); if (nodeType.ClassName != contentType.HandlerName) editor.ModifyNodeType(nodeType, contentType.HandlerName); if (nodeType.Parent != parentNodeType) editor.ModifyNodeType(nodeType, parentNodeType); //-- 1: ContentHandler properties NodeTypeRegistration ntReg = ParseAttributes(handlerType); if (ntReg == null) throw new ContentRegistrationException( SR.Exceptions.Registration.Msg_DefinedHandlerIsNotAContentHandler, contentType.Name); //-- 2: Field properties foreach (FieldSetting fieldSetting in contentType.FieldSettings) { Type[][] slots = fieldSetting.HandlerSlots; int fieldSlotCount = slots.GetLength(0); if (fieldSetting.Bindings.Count != fieldSlotCount) throw new ContentRegistrationException(String.Format(CultureInfo.InvariantCulture, SR.Exceptions.Registration.Msg_FieldBindingsCount_1, fieldSlotCount), contentType.Name, fieldSetting.Name); for (int i = 0; i < fieldSetting.Bindings.Count; i++) { string propName = fieldSetting.Bindings[i]; var dataType = fieldSetting.DataTypes[i]; CheckDataType(propName, dataType, contentType.Name, editor); PropertyInfo propInfo = handlerType.GetProperty(propName); if (propInfo != null) { //-- #1: there is a property under the slot: bool ok = false; for (int j = 0; j < slots[i].Length; j++) { //if (slots[i][j] == propInfo.PropertyType) if (slots[i][j].IsAssignableFrom(propInfo.PropertyType)) { PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propName); if (propInfo.DeclaringType != handlerType) { if (propReg == null) { object[] attrs = propInfo.GetCustomAttributes(typeof(RepositoryPropertyAttribute), false); if (attrs.Length > 0) { propReg = new PropertyTypeRegistration(propInfo, (RepositoryPropertyAttribute)attrs[0]); ntReg.PropertyTypeRegistrations.Add(propReg); } } } if (propReg != null && propReg.DataType != fieldSetting.DataTypes[i]) throw new ContentRegistrationException(String.Concat( "The data type of the field in the content type definition does not match the data type of its content handler's property. ", "Please modify the field type in the content type definition. ", "ContentTypeDefinition: '", contentType.Name, "', FieldName: '", fieldSetting.Name, "', DataType of Field's binding: '", fieldSetting.DataTypes[i], "', ContentHandler: '", handlerType.FullName, "', PropertyName: '", propReg.Name, "', DataType of property: '", propReg.DataType, "'")); ok = true; fieldSetting.HandlerSlotIndices[i] = j; fieldSetting.PropertyIsReadOnly = !PropertyHasPublicSetter(propInfo); break; } } if (!ok) { //if (fieldSetting.ShortName != "Reference") // if (fieldSetting.DataTypes[i] != RepositoryDataType.Reference) // throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_PropertyAndFieldAreNotConnectable, // contentType.Name, fieldSetting.Name); //CheckReference(propInfo, slots[i], contentType, fieldSetting); if (fieldSetting.ShortName == "Reference" || fieldSetting.DataTypes[i] == RepositoryDataType.Reference) CheckReference(propInfo, slots[i], contentType, fieldSetting); //else if (fieldSetting.ShortName == "Choice") // CheckChoice(propInfo, slots[i], contentType, fieldSetting); else throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_PropertyAndFieldAreNotConnectable, contentType.Name, fieldSetting.Name); } } else { //-- #2: there is not a property under the slot: PropertyTypeRegistration propReg = new PropertyTypeRegistration(propName, dataType); ntReg.PropertyTypeRegistrations.Add(propReg); } } } //-- Collect deletables. Check equals foreach (PropertyType propType in nodeType.PropertyTypes.ToArray()) { PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propType.Name); if (propReg == null) { editor.RemovePropertyTypeFromPropertySet(propType, nodeType); } } //-- Register foreach (PropertyTypeRegistration ptReg in ntReg.PropertyTypeRegistrations) { PropertyType propType = nodeType.PropertyTypes[ptReg.Name]; if (propType == null) { propType = editor.PropertyTypes[ptReg.Name]; if (propType == null) propType = editor.CreatePropertyType(ptReg.Name, ConvertDataType(ptReg.DataType)); editor.AddPropertyTypeToPropertySet(propType, nodeType); } } }
public void SchEd_WriterCalling_Complex_01() { SchemaEditor ed1 = new SchemaEditor(); SchemaEditor ed2 = new SchemaEditor(); SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2); TestSchemaWriter wr = new TestSchemaWriter(); //-- create original PropertyType ptX = CreatePropertyType(ed1, "X", DataType.String, 1); PropertyType ptY = CreatePropertyType(ed1, "Y", DataType.String, 2); PropertyType ptZ = CreatePropertyType(ed1, "Z", DataType.String, 3); NodeType ntA = CreateNodeType(ed1, null, "A", null, 1); NodeType ntB = CreateNodeType(ed1, ntA, "B", null, 2); NodeType ntC = CreateNodeType(ed1, ntB, "C", null, 3); ed1.AddPropertyTypeToPropertySet(ptX, ntB); ed1.AddPropertyTypeToPropertySet(ptY, ntC); ed1.AddPropertyTypeToPropertySet(ptX, ntA); //-- create current XmlDocument xd = new XmlDocument(); xd.LoadXml(ed1.ToXml()); ed2.Load(xd); ptX = ed2.PropertyTypes["X"]; ptY = ed2.PropertyTypes["Y"]; ptZ = ed2.PropertyTypes["Z"]; ntA = ed2.NodeTypes["A"]; ntB = ed2.NodeTypes["B"]; ntC = ed2.NodeTypes["C"]; //-- edit ed2.RemovePropertyTypeFromPropertySet(ptX, ntA); //-- register ed2Acc.RegisterSchema(ed1, wr); //-- test string log = wr.Log.Replace("\r\n", ""); Assert.IsTrue(log == "Open();RemovePropertyTypeFromPropertySet(propertyType=<X>, owner=<A>);Close();"); }