//================================================= 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); }
private void SetSchemaItemId(SchemaItem item, int id) { SchemaItemAccessor slotAcc = new SchemaItemAccessor(item); slotAcc.Id = id; }
//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; }