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

            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.º 4
0
        public void SchemaEditor_LoadSchema()
        {
            Test(() =>
            {
                SchemaEditor editor1 = new SchemaEditor();
                editor1.Load();

                editor1.CreatePropertyType("NewProperty", DataType.String); //.CreatePermissionType("PermA");

                string s       = editor1.ToXml();
                XmlDocument xd = new XmlDocument();
                xd.LoadXml(s);

                SchemaEditor editor2 = new SchemaEditor();
                editor2.Load(xd);
                string ss = editor2.ToXml();
            });
        }
Exemplo n.º 5
0
        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");
        }
Exemplo n.º 6
0
        public void SchEd_WriterCalling_CreatePropertyType()
        {
            SchemaEditor         ed1    = new SchemaEditor();
            SchemaEditor         ed2    = new SchemaEditor();
            SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
            TestSchemaWriter     wr     = new TestSchemaWriter();

            //-- edit
            ed2.CreatePropertyType("PT1", DataType.String);

            //-- register
            ed2Acc.RegisterSchema(ed1, wr);

            //-- test
            string log = wr.Log.Replace("\r\n", "");

            Assert.IsTrue(log == "Open();CreatePropertyType(name=<PT1>, dataType=<String>, mapping=<0>, isContentListProperty=<False>);Close();");
        }
Exemplo n.º 7
0
        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);
            });
        }
Exemplo n.º 8
0
        public void SchEd_WriterCalling_ReCreateNodeType()
        {
            Test(() =>
            {
                SchemaEditor ed1            = new SchemaEditor();
                SchemaEditor ed2            = new SchemaEditor();
                SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
                TestSchemaWriter wr         = new TestSchemaWriter();

                //-- create original
                ed1.CreatePropertyType("PT1", DataType.String);
                SetSchemaItemId(ed1.PropertyTypes["PT1"], 1);
                ed1.CreateNodeType(null, "NT1", "T1");
                SetSchemaItemId(ed1.NodeTypes["NT1"], 1);
                ed1.AddPropertyTypeToPropertySet(ed1.PropertyTypes["PT1"], ed1.NodeTypes["NT1"]);
                //-- create current
                ed2.CreatePropertyType("PT1", DataType.String);
                SetSchemaItemId(ed2.PropertyTypes["PT1"], 1);
                ed2.CreateNodeType(null, "NT1", "T1");
                SetSchemaItemId(ed2.NodeTypes["NT1"], 1);
                ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT1"]);

                //-- edit
                ed2.DeleteNodeType(ed2.NodeTypes["NT1"]);
                ed2.CreateNodeType(null, "NT1", "T1");
                ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT1"]);

                //-- register
                ed2Acc.RegisterSchema(ed1, wr);

                //-- test
                string expectedLog = @"
				Open();
				DeleteNodeType(nodeType=<NT1>);
				CreateNodeType(parent=<[null]>, name=<NT1>, className=<T1>);
				AddPropertyTypeToPropertySet(propertyType=<PT1>, owner=<NT1>, isDeclared=<True>);
				Close();
				"                .Replace("\r\n", "").Replace("\t", "").Replace(" ", "");
                string log         = wr.Log.Replace("\r\n", "").Replace(" ", "");
                Assert.IsTrue(log == expectedLog);
            });
        }
Exemplo n.º 9
0
        public PropertyType EnsurePropertyType(string name, DataType dataType)
        {
            if (_editor == null)
            {
                _editor = new SchemaEditor();
            }

            var existing = PropertyTypes.FirstOrDefault(x => x.Name == name);

            if (existing != null)
            {
                if (existing.DataType != dataType)
                {
                    throw new ApplicationException($"DataType mismatch {existing.DataType} <-> {dataType}. PropertyType name: {name}, ");
                }
                return(existing);
            }
            var pt = _editor.CreatePropertyType(name, dataType);

            PropertyTypes.Add(pt);
            return(pt);
        }
Exemplo n.º 10
0
        public void SchemaWriter_AddPropertyTypeToNodeType_Inherited()
        {
            //Assert.Inconclusive();
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var nodeTypeName1 = "NT1-" + Guid.NewGuid();
                var nodeTypeName2 = "NT2-" + Guid.NewGuid();
                var ptName1       = "PT1-" + Guid.NewGuid();
                var ptName2       = "PT2-" + Guid.NewGuid();
                var nt1           = ed.CreateNodeType(null, nodeTypeName1, "NT0Class");
                var ___           = ed.CreateNodeType(nt1, nodeTypeName2, "NT1Class");
                var pt1           = ed.CreatePropertyType(ptName1, DataType.String, GetNextMapping(ed, false));
                nt1.AddPropertyType(pt1);
                ed.Register();
                // ASSERT-BEFORE
                Assert.AreEqual(1, StorageSchema.NodeTypes[nodeTypeName2].PropertyTypes.Count);
                var schema  = DP.LoadSchemaAsync(CancellationToken.None).GetAwaiter().GetResult();
                var ntData2 = schema.NodeTypes.First(x => x.Name == nodeTypeName2);
                Assert.AreEqual(0, ntData2.Properties.Count);

                // ACTION
                ed = new SchemaEditor();
                ed.Load();
                var nt2 = ed.NodeTypes[nodeTypeName2];
                pt1     = ed.PropertyTypes[ptName1];
                nt2.AddPropertyType(pt1);
                ed.Register();

                // ASSERT-AFTER
                Assert.AreEqual(1, StorageSchema.NodeTypes[nodeTypeName2].PropertyTypes.Count);
                schema  = DP.LoadSchemaAsync(CancellationToken.None).GetAwaiter().GetResult();
                ntData2 = schema.NodeTypes.First(x => x.Name == nodeTypeName2);
                Assert.AreEqual(1, ntData2.Properties.Count);
            });
        }
Exemplo n.º 11
0
        public void SchEd_WriterCalling_DeletePropertyType()
        {
            SchemaEditor         ed1    = new SchemaEditor();
            SchemaEditor         ed2    = new SchemaEditor();
            SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
            TestSchemaWriter     wr     = new TestSchemaWriter();

            //-- create original
            ed1.CreatePropertyType("PT1", DataType.String);
            SetSchemaItemId(ed1.PropertyTypes["PT1"], 1);
            //-- create current
            ed2.CreatePropertyType("PT1", DataType.String);
            SetSchemaItemId(ed2.PropertyTypes["PT1"], 1);

            //-- edit
            ed2.DeletePropertyType(ed2.PropertyTypes["PT1"]);
            //-- register
            ed2Acc.RegisterSchema(ed1, wr);

            //-- test
            string log = wr.Log.Replace("\r\n", "");

            Assert.IsTrue(log == "Open();DeletePropertyType(propertyType=<PT1>);Close();");
        }
Exemplo n.º 12
0
		public void SchemaEditor_CreatePropertySlot()
		{
			//-- 
			SchemaEditor editor = new SchemaEditor();
			PropertyType slot = editor.CreatePropertyType("NewSlot1", DataType.String, 1);
			Assert.IsTrue(slot.Id == 0, "Id was not 0");
		}
Exemplo n.º 13
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.º 14
0
		public void SchemaEditor_CreatePropertySlot_WithTheSameName()
		{
			//-- hiba: nevutkozes
			SchemaEditor editor = new SchemaEditor();
			PropertyType slot1 = editor.CreatePropertyType("NewSlot", DataType.String);
			PropertyType slot2 = editor.CreatePropertyType("NewSlot", DataType.String);
		}
Exemplo n.º 15
0
		public void SchemaEditor_CreatePropertySlot_WithTheSameMapping()
		{
			//-- hiba: mapping utkozes
			SchemaEditor editor = new SchemaEditor();
			PropertyType slot1 = editor.CreatePropertyType("NewSlot1", DataType.String, 0);
			PropertyType slot2 = editor.CreatePropertyType("NewSlot2", DataType.String, 0);
		}
Exemplo n.º 16
0
		public void SchEd_WriterCalling_CreatePropertyType()
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();
			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();

			//-- edit
			ed2.CreatePropertyType("PT1", DataType.String);

			//-- register
			ed2Acc.RegisterSchema(ed1, wr);

			//-- test
			string log = wr.Log.Replace("\r\n", "");
			Assert.IsTrue(log == "Open();CreatePropertyType(name=<PT1>, dataType=<String>, mapping=<0>, isContentListProperty=<False>);Close();");
		}
Exemplo n.º 17
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.º 18
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.º 19
0
		public void SchemaEditor_RemovePropertySlot_WrongContext()
		{
			//-- hiba: rossz context (ket SchemaEditor)
			SchemaEditor editor1 = new SchemaEditor();
			SchemaEditor editor2 = new SchemaEditor();
			editor1.CreatePropertyType("slot", DataType.String, 0);
			editor2.CreatePropertyType("slot", DataType.String, 1);
			PropertyType slot = editor1.PropertyTypes["slot"];
			editor2.DeletePropertyType(slot);
		}
Exemplo n.º 20
0
        public void SearchOrder_Constructor_SlotAndDirectionDesc()
        {
            SchemaEditor ed = new SchemaEditor();
            PropertyType slot = ed.CreatePropertyType("slot", DataType.String);

            SearchOrder target = new SearchOrder(slot, OrderDirection.Desc);
            //SearchOrderAccessor acc = new SearchOrderAccessor(target);

            Assert.IsTrue(target.Direction == OrderDirection.Desc, "#1");
            Assert.IsTrue(target.PropertyToOrder.IsSlot == true, "#2");
            Assert.IsTrue(Object.ReferenceEquals(target.PropertyToOrder.PropertySlot, slot), "#3");
        }
Exemplo n.º 21
0
		private PropertyType CreatePropertyType(SchemaEditor editor, string name, DataType dataType, int id)
		{
			PropertyType pt = editor.CreatePropertyType(name, dataType);
			SetSchemaItemId(pt, id);
			return pt;
		}
Exemplo n.º 22
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.º 23
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.º 24
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.º 25
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.º 26
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.º 27
0
		public void SchEd_WriterCalling_ModifyNodeType_ChangeParent()
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();
			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();

			//-- create original
			ed1.CreatePropertyType("PT1", DataType.String); SetSchemaItemId(ed1.PropertyTypes["PT1"], 1);
			ed1.CreatePropertyType("PT2", DataType.String); SetSchemaItemId(ed1.PropertyTypes["PT1"], 2);
			ed1.CreatePropertyType("PT3", DataType.String); SetSchemaItemId(ed1.PropertyTypes["PT1"], 3);
			NodeType nt1 = ed1.CreateNodeType(null, "NT1"); SetSchemaItemId(ed1.NodeTypes["NT1"], 1);
			NodeType nt2 = ed1.CreateNodeType(null, "NT2"); SetSchemaItemId(ed1.NodeTypes["NT2"], 2);
			NodeType nt3 = ed1.CreateNodeType(nt1, "NT3"); SetSchemaItemId(ed1.NodeTypes["NT3"], 3);
			ed1.AddPropertyTypeToPropertySet(ed1.PropertyTypes["PT1"], ed1.NodeTypes["NT1"]);
			ed1.AddPropertyTypeToPropertySet(ed1.PropertyTypes["PT2"], ed1.NodeTypes["NT2"]);
			ed1.AddPropertyTypeToPropertySet(ed1.PropertyTypes["PT3"], ed1.NodeTypes["NT3"]);

			//-- create current
			ed2.CreatePropertyType("PT1", DataType.String); SetSchemaItemId(ed2.PropertyTypes["PT1"], 1);
			ed2.CreatePropertyType("PT2", DataType.String); SetSchemaItemId(ed2.PropertyTypes["PT1"], 2);
			ed2.CreatePropertyType("PT3", DataType.String); SetSchemaItemId(ed2.PropertyTypes["PT1"], 3);
			nt1 = ed2.CreateNodeType(null, "NT1"); SetSchemaItemId(ed2.NodeTypes["NT1"], 1);
			nt2 = ed2.CreateNodeType(null, "NT2"); SetSchemaItemId(ed2.NodeTypes["NT2"], 2);
			nt3 = ed2.CreateNodeType(nt1, "NT3"); SetSchemaItemId(ed2.NodeTypes["NT3"], 3);
			ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT1"]);
			ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["PT2"], ed2.NodeTypes["NT2"]);
			ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["PT3"], ed2.NodeTypes["NT3"]);

			//-- edit
			ed2.ModifyNodeType(ed2.NodeTypes["NT3"], ed2.NodeTypes["NT2"]);

			//-- register
			ed2Acc.RegisterSchema(ed1, wr);

			//-- test
			string expectedLog = @"
				Open();
				ModifyNodeType(nodeType=<NT3>, parent=<NT2>, className=<>);
				RemovePropertyTypeFromPropertySet(propertyType=<PT1>, owner=<NT3>);
				AddPropertyTypeToPropertySet(propertyType=<PT2>, owner=<NT3>, isDeclared=<True>);
				Close();
				".Replace("\r\n", "").Replace("\t", "").Replace(" ", "");
			string log = wr.Log.Replace("\r\n", "").Replace(" ", "");
			Assert.IsTrue(log == expectedLog, "#1");
			Assert.IsNull(nt1.Parent, "#2");
			Assert.IsNull(nt2.Parent, "#3");
			Assert.IsTrue(nt3.Parent == nt2, "#4");
			Assert.IsTrue(nt1.PropertyTypes.Count == 1, "#5");
			Assert.IsTrue(nt2.PropertyTypes.Count == 1, "#6");
			Assert.IsTrue(nt3.PropertyTypes.Count == 2, "#7");
			Assert.IsNotNull(nt1.PropertyTypes["PT1"], "#8");
			Assert.IsNotNull(nt2.PropertyTypes["PT2"], "#9");
			Assert.IsNotNull(nt3.PropertyTypes["PT3"], "#10");
			Assert.IsNull(nt3.PropertyTypes["PT1"], "#11");
			Assert.IsNotNull(nt3.PropertyTypes["PT2"], "#12");
		}
Exemplo n.º 28
0
        public void SchemaEditor_AddWrongPropertyToContentListType()
		{
			SchemaEditor editor = new SchemaEditor();
			PropertyType pt1 = editor.CreatePropertyType("PT1", DataType.String);
            var lt1 = editor.CreateContentListType("LT1");
			editor.AddPropertyTypeToPropertySet(pt1, lt1);
		}
Exemplo n.º 29
0
        public void NodeQuery_BuildFromXml()
        {
            SchemaEditor editor        = new SchemaEditor();
            NodeType     nodeType1     = editor.CreateNodeType(null, "nodeType1");
            NodeType     nodeType2     = editor.CreateNodeType(null, "nodeType2");
            PropertyType stringSlot1   = editor.CreatePropertyType("stringSlot1", DataType.String);
            PropertyType stringSlot2   = editor.CreatePropertyType("stringSlot2", DataType.String);
            PropertyType intSlot1      = editor.CreatePropertyType("intSlot1", DataType.Int);
            PropertyType intSlot2      = editor.CreatePropertyType("intSlot2", DataType.Int);
            PropertyType dateTimeSlot1 = editor.CreatePropertyType("dateTimeSlot1", DataType.DateTime);
            PropertyType dateTimeSlot2 = editor.CreatePropertyType("dateTimeSlot2", DataType.DateTime);
            PropertyType currencySlot1 = editor.CreatePropertyType("currencySlot1", DataType.Currency);
            PropertyType currencySlot2 = editor.CreatePropertyType("currencySlot2", DataType.Currency);
            PropertyType refSlot1      = editor.CreatePropertyType("refSlot1", DataType.Reference);
            PropertyType refSlot2      = editor.CreatePropertyType("refSlot2", DataType.Reference);

            NodeQuery query = new NodeQuery();

            //==== Operators
            ExpressionList strOpExp = new ExpressionList(ChainOperator.Or);

            query.Add(strOpExp);
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.Contains, "{path}"));
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.EndsWith, "{path}"));
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.Equal, "{path}"));
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.GreaterThan, "{path}"));
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.GreaterThanOrEqual, "{path}"));
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.LessThan, "{path}"));
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.LessThanOrEqual, "{path}"));
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.NotEqual, "{path}"));
            strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "{path}"));

            //==== StringExpression
            ExpressionList strExp = new ExpressionList(ChainOperator.Or);

            query.Add(strExp);
            strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, "{value}"));
            strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, stringSlot2));
            strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, StringAttribute.Path));
            strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, (string)null));
            strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, "{value}"));
            strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, stringSlot2));
            strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, StringAttribute.Path));
            strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, (string)null));

            //==== IntExpression
            ExpressionList intExp = new ExpressionList(ChainOperator.Or);

            query.Add(intExp);
            intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, 123));
            intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, IntAttribute.MajorVersion));
            intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, intSlot2));
            intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, (int?)null));
            intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, 123));
            intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, IntAttribute.MajorVersion));
            intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, intSlot2));
            intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, (int?)null));

            //==== DateTimeExpression
            ExpressionList dtExp = new ExpressionList(ChainOperator.Or);

            query.Add(dtExp);
            dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, DateTime.Now));
            dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, DateTimeAttribute.ModificationDate));
            dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, dateTimeSlot2));
            dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, (DateTime?)null));
            dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, DateTime.Now));
            dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, DateTimeAttribute.ModificationDate));
            dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, dateTimeSlot2));
            dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, (DateTime?)null));

            //==== CurrencyExpression
            ExpressionList curExp = new ExpressionList(ChainOperator.Or);

            query.Add(curExp);
            curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, (decimal)123.456));
            curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, currencySlot2));
            curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, (decimal?)null));

            //==== ReferenceExpression
            ExpressionList subExp = new ExpressionList(ChainOperator.And);

            subExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.GreaterThan, 123));
            subExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.GreaterThan, DateTime.Now));
            ExpressionList refExp = new ExpressionList(ChainOperator.Or);

            query.Add(refExp);
            refExp.Add(new ReferenceExpression(refSlot1));
            refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy));
            refExp.Add(new ReferenceExpression(refSlot1, (Node)null));
            refExp.Add(new ReferenceExpression(refSlot1, Repository.Root));
            refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, (Node)null));
            refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, Repository.Root));
            refExp.Add(new ReferenceExpression(refSlot1, subExp));
            refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, subExp));

            //==== TypeExpression
            ExpressionList typeExp = new ExpressionList(ChainOperator.Or);

            query.Add(typeExp);
            typeExp.Add(new TypeExpression(nodeType1));
            typeExp.Add(new TypeExpression(nodeType2, true));

            //==== Negation
            Expression negExp = new NotExpression(
                new ExpressionList(ChainOperator.And,
                                   new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "/Root1/"),
                                   new StringExpression(StringAttribute.Name, StringOperator.NotEqual, "name")
                                   ));

            query.Add(negExp);

            //==== Orders
            query.Orders.Add(new SearchOrder(DateTimeAttribute.ModificationDate, OrderDirection.Desc));
            query.Orders.Add(new SearchOrder(IntAttribute.MajorVersion, OrderDirection.Asc));
            query.Orders.Add(new SearchOrder(StringAttribute.Name, OrderDirection.Asc));

            //==== Paging
            query.PageSize   = 123;
            query.StartIndex = 987;

            string            queryString    = query.ToXml();
            NodeQueryAccessor queryAcc       = new NodeQueryAccessor(new NodeQuery());
            NodeQuery         newQuery       = queryAcc.Parse(queryString, editor);
            string            newQueryString = newQuery.ToXml();

            Assert.IsTrue(queryString != null && queryString == newQueryString);
        }
Exemplo n.º 30
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.º 31
0
		public void SchEd_WriterCalling_ReCreateNodeType()
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();
			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();

			//-- create original
			ed1.CreatePropertyType("PT1", DataType.String);
			SetSchemaItemId(ed1.PropertyTypes["PT1"], 1);
			ed1.CreateNodeType(null, "NT1");
			SetSchemaItemId(ed1.NodeTypes["NT1"], 1);
			ed1.AddPropertyTypeToPropertySet(ed1.PropertyTypes["PT1"], ed1.NodeTypes["NT1"]);
			//-- create current
			ed2.CreatePropertyType("PT1", DataType.String);
			SetSchemaItemId(ed2.PropertyTypes["PT1"], 1);
			ed2.CreateNodeType(null, "NT1");
			SetSchemaItemId(ed2.NodeTypes["NT1"], 1);
			ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT1"]);

			//-- edit
			ed2.DeleteNodeType(ed2.NodeTypes["NT1"]);
			ed2.CreateNodeType(null, "NT1");
			ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT1"]);

			//-- register
			ed2Acc.RegisterSchema(ed1, wr);

			//-- test
			string expectedLog = @"
				Open();
				DeleteNodeType(nodeType=<NT1>);
				CreateNodeType(parent=<[null]>, name=<NT1>, className=<>);
				AddPropertyTypeToPropertySet(propertyType=<PT1>, owner=<NT1>, isDeclared=<True>);
				Close();
				".Replace("\r\n", "").Replace("\t", "").Replace(" ", "");
			string log = wr.Log.Replace("\r\n", "").Replace(" ", "");
			Assert.IsTrue(log == expectedLog);
		}
Exemplo n.º 32
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);
                }

                // 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);
                }
            }
        }
Exemplo n.º 33
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.º 34
0
		public void SchEd_WriterCalling_ModifyNodeType()
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();
			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();

			//-- create original
			ed1.CreatePropertyType("PT1", DataType.String);
			SetSchemaItemId(ed1.PropertyTypes["PT1"], 1);
			ed1.CreateNodeType(null, "NT1");
			SetSchemaItemId(ed1.NodeTypes["NT1"], 1);
			ed1.AddPropertyTypeToPropertySet(ed1.PropertyTypes["PT1"], ed1.NodeTypes["NT1"]);
			//-- create current
			ed2.CreatePropertyType("PT1", DataType.String);
			SetSchemaItemId(ed2.PropertyTypes["PT1"], 1);
			ed2.CreateNodeType(null, "NT1");
			SetSchemaItemId(ed2.NodeTypes["NT1"], 1);
			ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["PT1"], ed2.NodeTypes["NT1"]);

			//-- edit
			ed2.ModifyNodeType(ed2.NodeTypes["NT1"], "ClassName2");

			//-- register
			ed2Acc.RegisterSchema(ed1, wr);

			//-- test
			string log = wr.Log.Replace("\r\n", "");
			Assert.IsTrue(log == "Open();ModifyNodeType(nodeType=<NT1>, parent=<[null]>, className=<ClassName2>);Close();");

		}
Exemplo n.º 35
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.º 36
0
		public void NodeQuery_BuildFromXml()
		{
			SchemaEditor editor = new SchemaEditor();
			NodeType nodeType1 = editor.CreateNodeType(null, "nodeType1");
			NodeType nodeType2 = editor.CreateNodeType(null, "nodeType2");
			PropertyType stringSlot1 = editor.CreatePropertyType("stringSlot1", DataType.String);
			PropertyType stringSlot2 = editor.CreatePropertyType("stringSlot2", DataType.String);
			PropertyType intSlot1 = editor.CreatePropertyType("intSlot1", DataType.Int);
			PropertyType intSlot2 = editor.CreatePropertyType("intSlot2", DataType.Int);
			PropertyType dateTimeSlot1 = editor.CreatePropertyType("dateTimeSlot1", DataType.DateTime);
			PropertyType dateTimeSlot2 = editor.CreatePropertyType("dateTimeSlot2", DataType.DateTime);
			PropertyType currencySlot1 = editor.CreatePropertyType("currencySlot1", DataType.Currency);
			PropertyType currencySlot2 = editor.CreatePropertyType("currencySlot2", DataType.Currency);
			PropertyType refSlot1 = editor.CreatePropertyType("refSlot1", DataType.Reference);
			PropertyType refSlot2 = editor.CreatePropertyType("refSlot2", DataType.Reference);

			NodeQuery query = new NodeQuery();

			//==== Operators
			ExpressionList strOpExp = new ExpressionList(ChainOperator.Or);
			query.Add(strOpExp);
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.Contains, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.EndsWith, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.Equal, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.GreaterThan, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.GreaterThanOrEqual, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.LessThan, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.LessThanOrEqual, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.NotEqual, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "{path}"));

			//==== StringExpression
			ExpressionList strExp = new ExpressionList(ChainOperator.Or);
			query.Add(strExp);
			strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, "{value}"));
			strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, stringSlot2));
			strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, StringAttribute.Path));
			strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, (string)null));
			strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, "{value}"));
			strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, stringSlot2));
			strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, StringAttribute.Path));
			strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, (string)null));

			//==== IntExpression
			ExpressionList intExp = new ExpressionList(ChainOperator.Or);
			query.Add(intExp);
			intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, 123));
			intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, IntAttribute.MajorVersion));
			intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, intSlot2));
			intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, (int?)null));
			intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, 123));
			intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, IntAttribute.MajorVersion));
			intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, intSlot2));
			intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, (int?)null));

			//==== DateTimeExpression
			ExpressionList dtExp = new ExpressionList(ChainOperator.Or);
			query.Add(dtExp);
			dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, DateTime.Now));
			dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, DateTimeAttribute.ModificationDate));
			dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, dateTimeSlot2));
			dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, (DateTime?)null));
			dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, DateTime.Now));
			dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, DateTimeAttribute.ModificationDate));
			dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, dateTimeSlot2));
			dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, (DateTime?)null));

			//==== CurrencyExpression
			ExpressionList curExp = new ExpressionList(ChainOperator.Or);
			query.Add(curExp);
			curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, (decimal)123.456));
			curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, currencySlot2));
			curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, (decimal?)null));

			//==== ReferenceExpression
			ExpressionList subExp = new ExpressionList(ChainOperator.And);
			subExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.GreaterThan, 123));
			subExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.GreaterThan, DateTime.Now));
			ExpressionList refExp = new ExpressionList(ChainOperator.Or);
			query.Add(refExp);
			refExp.Add(new ReferenceExpression(refSlot1));
			refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy));
			refExp.Add(new ReferenceExpression(refSlot1, (Node)null));
			refExp.Add(new ReferenceExpression(refSlot1, Repository.Root));
			refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, (Node)null));
			refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, Repository.Root));
			refExp.Add(new ReferenceExpression(refSlot1, subExp));
			refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, subExp));

			//==== TypeExpression
			ExpressionList typeExp = new ExpressionList(ChainOperator.Or);
			query.Add(typeExp);
			typeExp.Add(new TypeExpression(nodeType1));
			typeExp.Add(new TypeExpression(nodeType2, true));

			//==== Negation
			Expression negExp = new NotExpression(
				new ExpressionList(ChainOperator.And,
					new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "/Root1/"),
					new StringExpression(StringAttribute.Name, StringOperator.NotEqual, "name")
					));
			query.Add(negExp);

			//==== Orders
			query.Orders.Add(new SearchOrder(DateTimeAttribute.ModificationDate, OrderDirection.Desc));
			query.Orders.Add(new SearchOrder(IntAttribute.MajorVersion, OrderDirection.Asc));
			query.Orders.Add(new SearchOrder(StringAttribute.Name, OrderDirection.Asc));

			//==== Paging
			query.PageSize = 123;
			query.StartIndex = 987;

			string queryString = query.ToXml();
			NodeQueryAccessor queryAcc = new NodeQueryAccessor(new NodeQuery());
			NodeQuery newQuery = queryAcc.Parse(queryString, editor);
			string newQueryString = newQuery.ToXml();

			Assert.IsTrue(queryString != null && queryString == newQueryString);
		}
Exemplo n.º 37
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.º 38
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.º 39
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.º 40
0
		public void SchEd_WriterCalling_DeletePropertyType()
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();
			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();

			//-- create original
			ed1.CreatePropertyType("PT1", DataType.String);
			SetSchemaItemId(ed1.PropertyTypes["PT1"], 1);
			//-- create current
			ed2.CreatePropertyType("PT1", DataType.String);
			SetSchemaItemId(ed2.PropertyTypes["PT1"], 1);

			//-- edit
			ed2.DeletePropertyType(ed2.PropertyTypes["PT1"]);
			//-- register
			ed2Acc.RegisterSchema(ed1, wr);

			//-- test
			string log = wr.Log.Replace("\r\n", "");
			Assert.IsTrue(log == "Open();DeletePropertyType(propertyType=<PT1>);Close();");
		}