Exemplo n.º 1
0
		public void TypeCollection_SetItemWithName()
		{
			SchemaEditor ed = new SchemaEditor();
			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			tc.Add(ed.CreateNodeType(null, String.Concat("NT0")));
			tc.Add(ed.CreateNodeType(null, String.Concat("NT1")));
			try
			{
				tc["NT1"] = ed.NodeTypes["NT0"];
			}
			catch (Exception e)
			{
				throw e.InnerException;
			}
		}
Exemplo n.º 2
0
		//TODO: Change structure: not implemented
		//[TestMethod()]
		//public void ContentType_FullInstall_InheritedClass_ChangeParent()
		//{
		//    Assembly asm = SchemaTestTools.DynamicAssembly;

		//    //-- Step 1: Install content types: TestType1, TestType2 and TestType1/TestType3
		//    string contentTypeDef1 = @"<?xml version='1.0' encoding='utf-8'?>
		//		<ContentType name='TestType1' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
		//			<Fields>
		//				<Field name='TestField' type='ShortText'>
		//					<DisplayName>TestField1</DisplayName>
		//				</Field>
		//			</Fields>
		//		</ContentType>";
		//    string contentTypeDef2 = @"<?xml version='1.0' encoding='utf-8'?>
		//		<ContentType name='TestType2' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
		//			<Fields>
		//				<Field name='TestField' type='ShortText'>
		//					<DisplayName>TestField2</DisplayName>
		//				</Field>
		//			</Fields>
		//		</ContentType>";
		//    string contentTypeDef3 = @"<?xml version='1.0' encoding='utf-8'?>
		//		<ContentType name='TestType3' parentType='TestType1' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
		//			<Fields>
		//				<Field name='TestField' type='ShortText'></Field>
		//			</Fields>
		//		</ContentType>";

		//    ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller();
		//    installer.AddContentType(contentTypeDef1);
		//    installer.AddContentType(contentTypeDef2);
		//    installer.AddContentType(contentTypeDef3);
		//    installer.ExecuteBatch();

		//    //-- Step 2: Reinstall TestType3 under TestType2
		//    contentTypeDef3 = @"<?xml version='1.0' encoding='utf-8'?>
		//		<ContentType name='TestType3' parentType='TestType2' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'></ContentType>";

		//    ContentTypeInstaller.InstallContentType(contentTypeDef3);

		//    NodeType nt1 = ActiveSchema.NodeTypes["TestType1"];
		//    NodeType nt2 = ActiveSchema.NodeTypes["TestType2"];
		//    NodeType nt3 = ActiveSchema.NodeTypes["TestType3"];
		//    ContentType ct1 = ContentTypeManager.Current.GetContentTypeByName(nt1.Name);
		//    ContentType ct2 = ContentTypeManager.Current.GetContentTypeByName(nt2.Name);
		//    ContentType ct3 = ContentTypeManager.Current.GetContentTypeByName(nt3.Name);

		//    SNC.Content c3 = SNC.Content.CreateNew("TestType3", this.TestRoot, "ChangeParentTest3");

		//    Assert.IsTrue(ct3.Path == Path.Combine(ct2.Path, ct3.Name));
		//    Assert.IsTrue(c3.Fields["TestField"].Title == "TestField2");
		//}


		//================================================= Tools =================================================

		private string InstallContentType(string contentTypeDefInstall, string contentTypeDefModify)
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();

			ContentTypeManagerAccessor ctmAcc = new ContentTypeManagerAccessor(ContentTypeManager.Current);
			ContentType cts = ctmAcc.LoadOrCreateNew(contentTypeDefInstall);
            if (contentTypeDefModify != null)
            {
                cts.Save(false);
                var parent = ContentType.GetByName(cts.ParentName);
                ContentTypeManager.Current.AddContentType(cts);
            }

			ctmAcc.ApplyChangesInEditor(cts, ed2);

			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();
			ed2Acc.RegisterSchema(ed1, wr);

			if (contentTypeDefModify != null)
			{
				//-- Id-k beallitasa es klonozas
				SchemaEditor ed3 = new SchemaEditor();
				SchemaEditorAccessor ed3Acc = new SchemaEditorAccessor(ed3);
				SchemaItemAccessor schItemAcc;
				int id = 1;
				foreach (PropertyType pt in ed2.PropertyTypes)
				{
					PropertyType clone = ed3.CreatePropertyType(pt.Name, pt.DataType, pt.Mapping);
					schItemAcc = new SchemaItemAccessor(pt);
					schItemAcc.Id = id++;
					schItemAcc = new SchemaItemAccessor(clone);
					schItemAcc.Id = pt.Id;
				}
				id = 1;
				foreach (NodeType nt in ed2.NodeTypes)
				{
					NodeType clone = ed3.CreateNodeType(nt.Parent, nt.Name, nt.ClassName);
					foreach (PropertyType pt in nt.PropertyTypes)
						ed3.AddPropertyTypeToPropertySet(ed3.PropertyTypes[pt.Name], clone);
					schItemAcc = new SchemaItemAccessor(nt);
					schItemAcc.Id = id++;
					schItemAcc = new SchemaItemAccessor(clone);
					schItemAcc.Id = nt.Id;
				}

				cts = ctmAcc.LoadOrCreateNew(contentTypeDefModify);
				ctmAcc.ApplyChangesInEditor(cts, ed3);
				wr = new TestSchemaWriter();
				ed3Acc.RegisterSchema(ed2, wr);
			}

			return wr.Log;
		}
Exemplo n.º 3
0
		public void TypeCollection_RemoveAt()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			tc.RemoveAt(1);

			Assert.IsTrue(tc[0].Name == "NT0");
			Assert.IsTrue(tc[1].Name == "NT2");
			Assert.IsTrue(tc[2].Name == "NT3");
			Assert.IsTrue(tc[3].Name == "NT4");
			Assert.IsTrue(tc.Count == 4);
		}
Exemplo n.º 4
0
		public void TypeCollection_SetItem()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			//-- Content: NT0, NT1, NT2, NT3, NT4
			for (int i = 0; i < 5; i++)
				Assert.IsTrue(tc[i].Name == String.Concat("NT", i));

			tc.RemoveAt(0);

			//-- Content: NT1, NT2, NT3, NT4
			for (int i = 0; i < 4; i++)
				Assert.IsTrue(tc[i].Name == String.Concat("NT", i + 1));

			for (int i = 0; i < 4; i++)
				tc[i] = ed.NodeTypes[i];

			//-- Content: NT0, NT1, NT2, NT3
			for (int i = 0; i < 4; i++)
				Assert.IsTrue(tc[i].Name == String.Concat("NT", i));
		}
Exemplo n.º 5
0
		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");
		}
Exemplo n.º 6
0
		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");
		}
Exemplo n.º 7
0
		public void SchemaEditor_ModifyNodeType_WrongContxt()
		{
			//-- hiba: rossz context
			SchemaEditor editor1 = new SchemaEditor();
			SchemaEditor editor2 = new SchemaEditor();
			NodeType nt = editor1.CreateNodeType(null, "NT");
			editor2.ModifyNodeType(nt, (string)null);
		}
Exemplo n.º 8
0
		public void SchemaEditor_RemovePropertyType_NodeTypeNull()
		{
			//---- hiba: Target item cannot be null
			SchemaEditor editor = new SchemaEditor();
			NodeType nt = editor.CreateNodeType(null, "nt");
			new SchemaEditor().RemovePropertyTypeFromPropertySet(null, nt);
		}
Exemplo n.º 9
0
		public void SchemaEditor_CreateNodeType_Child()
		{
			SchemaEditor editor = new SchemaEditor();
			NodeType nt1 = editor.CreateNodeType(null, "NT1");
			NodeType nt2 = editor.CreateNodeType(null, "NT2");
			NodeType nt3 = editor.CreateNodeType(nt1, "NT3", "NT3class");
			NodeType nt4 = editor.CreateNodeType(null, "NT4");

			Assert.IsTrue(Object.ReferenceEquals(nt1, editor.NodeTypes["NT1"]), "#1");
			Assert.IsTrue(Object.ReferenceEquals(nt2, editor.NodeTypes["NT2"]), "#2");
			Assert.IsTrue(Object.ReferenceEquals(nt3, editor.NodeTypes["NT3"]), "#3");
			Assert.IsTrue(nt1.Children.Count == 1, "#4");
			Assert.IsTrue(nt2.Children.Count == 0, "#5");
			Assert.IsTrue(nt3.Children.Count == 0, "#6");
			Assert.IsTrue(Object.ReferenceEquals(nt3, nt1.Children[0]), "#7");
			Assert.IsTrue(Object.ReferenceEquals(nt1, nt3.Parent), "#8");
			Assert.IsNull(nt1.Parent, "#9");
			Assert.IsNull(nt2.Parent, "#10");

			Assert.IsTrue(nt1.ClassName == null, "#11");
			Assert.IsTrue(nt2.ClassName == null, "#12");
			Assert.IsTrue(nt3.ClassName == "NT3class", "#13");
		}
Exemplo n.º 10
0
		public void SchemaEditor_CreateNodeType()
		{
			SchemaEditor editor = new SchemaEditor();
			PropertyType slot = editor.CreatePropertyType("slot", DataType.String);
			NodeType nt1 = editor.CreateNodeType(null, "NT1");
			editor.AddPropertyTypeToPropertySet(slot, nt1);
			NodeType nt2 = editor.CreateNodeType(nt1, "NT2");
			Assert.IsNotNull(nt2.PropertyTypes["slot"]);
			Assert.IsTrue(nt1.Id == 0, "Id was not 0");
		}
Exemplo n.º 11
0
		public void SchemaEditor_CreateNodeType_WrongContext()
		{
			//-- hiba: rossz context (PropertySlot)
			SchemaEditor editor1 = new SchemaEditor();
			SchemaEditor editor2 = new SchemaEditor();
			NodeType nt1 = editor1.CreateNodeType(null, "NT1");
			editor2.CreateNodeType(nt1, "NT2");
		}
Exemplo n.º 12
0
		public void SchemaEditor_CreateNodeType_TwoNodeWithSameName()
		{
			//-- nevutkozes
			SchemaEditor editor = new SchemaEditor();
			editor.CreateNodeType(null, "NodeType");
			editor.CreateNodeType(null, "NodeType");
		}
Exemplo n.º 13
0
		public void SchemaEditor_RemovePropertySlot()
		{
			SchemaEditor editor = new SchemaEditor();
			PropertyType slot = editor.CreatePropertyType("slot1", DataType.String, 0);
			NodeType nt = editor.CreateNodeType(null, "NodeType1", "class");
			editor.AddPropertyTypeToPropertySet(slot, nt);

			slot = editor.PropertyTypes["slot1"];
			editor.DeletePropertyType(slot);
		}
Exemplo n.º 14
0
		public void SchemaEditor_ModifyPropertySlot_RemoveProtected()
		{
			//-- vedett elem torlese
			SchemaEditor editor = new SchemaEditor();
			PropertyType slot = editor.CreatePropertyType("slot1", DataType.String, 0);
			NodeType nt = editor.CreateNodeType(null, "NodeType1", "class");
			editor.AddPropertyTypeToPropertySet(slot, nt);

			editor.DeletePropertyType(slot);
		}
Exemplo n.º 15
0
		public void SchemaEditor_ModifyNodeType()
		{
			SchemaEditor editor = new SchemaEditor();
			NodeType nt = editor.CreateNodeType(null, "NT1");

			Assert.IsTrue(nt.Name == "NT1" && nt.ClassName == null, "#1");
			editor.ModifyNodeType(nt, "class1");
			Assert.IsTrue(nt.ClassName == "class1", "#2");
			Assert.IsTrue(nt.Id == 0, "Id was not 0");
		}
Exemplo n.º 16
0
		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"]);
		}
Exemplo n.º 17
0
		public void SchemaEditor_ModifyNodeType_Circular()
		{
			SchemaEditor editor = new SchemaEditor();
			NodeType nt = editor.CreateNodeType(null, "NT1");
			editor.ModifyNodeType(nt, nt);
		}
Exemplo n.º 18
0
		public void SchemaEditor_RemovePropertyType_NullPropertyType()
		{
			//---- hiba: Target item cannot be null
			SchemaEditor editor = new SchemaEditor();
			NodeType nt = editor.CreateNodeType(null, "nt");
			PropertyType slot = editor.CreatePropertyType("slot", DataType.String, 0);
			editor.AddPropertyTypeToPropertySet(slot, nt);
			new SchemaEditor().RemovePropertyTypeFromPropertySet(slot, null);
		}
Exemplo n.º 19
0
		public void SchemaEditor_RemoveNodeType_WrongContext()
		{
			//-- hiba: rossz context
			SchemaEditor editor1 = new SchemaEditor();
			SchemaEditor editor2 = new SchemaEditor();
			NodeType nt = editor1.CreateNodeType(null, "NT");
			editor2.DeleteNodeType(nt);
		}
Exemplo n.º 20
0
		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");
		}
Exemplo n.º 21
0
		public void SchemaEditor_RemoveNodeType()
		{
			SchemaEditor editor = new SchemaEditor();

			NodeType nt1 = editor.CreateNodeType(null, "NT1");
			NodeType nt2 = editor.CreateNodeType(nt1, "NT2");
			NodeType nt3 = editor.CreateNodeType(nt2, "NT3");
			PropertyType slot1 = editor.CreatePropertyType("Slot1", DataType.String);
			PropertyType slot2 = editor.CreatePropertyType("Slot2", DataType.String);
			PropertyType slot3 = editor.CreatePropertyType("Slot3", DataType.String);
			editor.AddPropertyTypeToPropertySet(slot1, nt1);
			editor.AddPropertyTypeToPropertySet(slot2, nt2);
			editor.AddPropertyTypeToPropertySet(slot3, nt3);

			editor.DeleteNodeType(editor.NodeTypes["NT2"]);

			Assert.IsTrue(editor.NodeTypes.Count == 1, "#1");

		}
Exemplo n.º 22
0
		private NodeType CreateNodeType(SchemaEditor editor, NodeType parent, string name, string className, int id)
		{
			NodeType nt = editor.CreateNodeType(parent, name, className);
			SetSchemaItemId(nt, id);
			return nt;
		}
Exemplo n.º 23
0
		public void SchemaEditor_CreatePropertyType_WrongPropertySlotContext()
		{
			//-- hiba: rossz context (PropertySlot)
			SchemaEditor editor1 = new SchemaEditor();
			SchemaEditor editor2 = new SchemaEditor();
			editor1.CreatePropertyType("slot", DataType.String);
			editor1.CreateNodeType(null, "nt");
			editor2.CreatePropertyType("slot", DataType.String);
			editor2.CreateNodeType(null, "nt");

			NodeType owner = editor1.NodeTypes["nt"];
			PropertyType slot = editor2.PropertyTypes["slot"];
			editor1.AddPropertyTypeToPropertySet(slot, owner);
		}
Exemplo n.º 24
0
		public void TypeCollection_GetItem()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			for (int i = 0; i < 5; i++)
				Assert.IsTrue(tc[i].Name == String.Concat("NT", i));
		}
Exemplo n.º 25
0
		public void SchemaEditor_AddWrongPropertyToNodeType()
		{
			SchemaEditor editor = new SchemaEditor();
			PropertyType pt1 = editor.CreateContentListPropertyType(DataType.String, 0);
			NodeType nt1 = editor.CreateNodeType(null, "NT1");
			editor.AddPropertyTypeToPropertySet(pt1, nt1);
		}
Exemplo n.º 26
0
		public void TypeCollection_GetItemWithName()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			//-- Content: NT0, NT1, NT2, NT3, NT4
			tc.RemoveAt(0);
			//-- Content: NT1, NT2, NT3, NT4

			Assert.IsTrue(tc["NT2"] == ed.NodeTypes["NT2"]);

		}
Exemplo n.º 27
0
		public void SchemaEditor_AddPropertyToNodeType()
		{
			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");

			editor.AddPropertyTypeToPropertySet(pt1, nt2);

			Assert.IsNull(nt1.PropertyTypes["PT1"]);
			Assert.IsNull(nt1.DeclaredPropertyTypes["PT1"]);
			Assert.IsTrue(Object.ReferenceEquals(nt2.PropertyTypes["PT1"], pt1));
			Assert.IsTrue(Object.ReferenceEquals(nt2.DeclaredPropertyTypes["PT1"], pt1));
			Assert.IsTrue(Object.ReferenceEquals(nt3.PropertyTypes["PT1"], pt1));
			Assert.IsNull(nt3.DeclaredPropertyTypes["PT1"]);
		}
Exemplo n.º 28
0
		public void TypeCollection_ToArray()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			NodeType[] ntArray = tc.ToArray();

			for (int i = 0; i < 5; i++)
				Assert.IsTrue(ntArray[i] == tc[i] && ntArray[i] == ed.NodeTypes[i]);
		}
Exemplo n.º 29
0
		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");
		}
Exemplo n.º 30
0
		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);
				}
			}
		}
Exemplo n.º 31
0
        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);
                }
            }

            // 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);
                }
            }
        }