public void ContentType_FullInstall_InheritedClass_ChangeHandlers2() { //-- Step 1: Install TestNode10 and TestNode11 content types with TestNode10 and TestNode11 handlers string contentTypeADef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode10' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='X' type='Integer' /> </Fields> </ContentType>" ; string contentTypeBDef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode11' parentType='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode11' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='Y' type='Integer' /> </Fields> </ContentType>" ; ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(contentTypeADef); installer.AddContentType(contentTypeBDef); installer.ExecuteBatch(); //-- Step 2: change handler of TestNode10 to unknown in the database directly ContentTypeManager.Reset(); Content content = Content.CreateNew("TestNode10", this.TestRoot, "TestNode10unknown"); }
public static void InstallContentTypes(IEnumerable <string> contentTypeDefinitions) { var installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); foreach (var contentTypeDefinition in contentTypeDefinitions) { installer.AddContentType(contentTypeDefinition); } installer.ExecuteBatch(); }
public void CreateStartStructure() { ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); for (int level = 1; level < 6; level++) { installer.AddContentType(CreateCtd(level, false, false)); } installer.ExecuteBatch(); }
public static void InitializePlayground(TestContext testContext) { if (ActiveSchema.NodeTypes["RepositoryTest_TestNodeWithBinaryProperty"] == null) { ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(TestNodeWithBinaryProperty.ContentTypeDefinition); installer.ExecuteBatch(); } }
public void ContentType_FullInstall_DataTypeCollision_Inherited() { var ct = ContentType.GetByName("DataTypeCollisionTestHandler"); if (ct != null) { ContentTypeInstaller.RemoveContentType(ct); } string ctd1 = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='DataTypeCollisionTestHandler' parentType='GenericContent' handler='SenseNet.ContentRepository.Tests.ContentHandlers.DataTypeCollisionTestHandler' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='TestString' type='ShortText'> <Bind property='TestString' /> </Field> </Fields> </ContentType>" ; string ctd2 = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='DataTypeCollisionTestHandler1' parentType='DataTypeCollisionTestHandler' handler='SenseNet.ContentRepository.Tests.ContentHandlers.DataTypeCollisionTestHandler' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='TestString' type='LongText'> <Bind property='TestString' /> </Field> </Fields> </ContentType>" ; ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(ctd2); installer.AddContentType(ctd1); var thrown = false; try { installer.ExecuteBatch(); } catch (RegistrationException) { thrown = true; } catch (ContentRegistrationException) { thrown = true; } Assert.IsTrue(thrown); }
public void CreateStartStructure() { var ct = ContentType.GetByName("T1"); if (ct != null) { ct.Delete(); ContentTypeManager.Reset(); } ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); for (int level = 1; level < 6; level++) { installer.AddContentType(CreateCtd(level, false, false)); } installer.ExecuteBatch(); }
private static void InstallContentTypeDefinitions(string ctdPath) { if (IO.File.Exists(ctdPath)) { LogWrite("Installing content type "); LogWrite(Path.GetFileName(ctdPath)); LogWriteLine("..."); FileStream stream = new FileStream(ctdPath, FileMode.Open, FileAccess.Read); ContentTypeInstaller.InstallContentType(stream); } else { LogWriteLine("Loading content types..."); ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); foreach (string ctdFilePath in Directory.GetFiles(ctdPath, "*.xml")) { LogWrite(Path.GetFileName(ctdFilePath)); LogWrite(" ..."); FileStream stream = new FileStream(ctdFilePath, FileMode.Open, FileAccess.Read); try { installer.AddContentType(stream); } catch (ApplicationException e) { _exceptions++; LogWriteLine(" SKIPPED: " + e.Message); } LogWriteLine(" Ok"); } LogWriteLine(); LogWrite("Installing content types..."); installer.ExecuteBatch(); } LogWriteLine(" Ok"); LogWriteLine(); }
public void ContentType_FullInstall_InheritedClass_ChangeHandlers1() { //-- Step 1: Install TestNode10 and TestNode11 content types with TestNode10 and TestNode11 handlers string contentTypeADef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode10' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='X' type='Integer' /> </Fields> </ContentType>" ; string contentTypeBDef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode11' parentType='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode11' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='Y' type='Integer' /> </Fields> </ContentType>" ; ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(contentTypeADef); installer.AddContentType(contentTypeBDef); installer.ExecuteBatch(); //-- Step 2: Reinstall TestNode10 content type with an unknown handler contentTypeADef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode10' handler='Unknown' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='A' type='Integer'><DisplayName>A</DisplayName></Field> <Field name='B' type='Integer'><DisplayName>B</DisplayName></Field> <Field name='C' type='Integer'><DisplayName>C</DisplayName></Field> </Fields> </ContentType>" ; installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(contentTypeADef); installer.AddContentType(contentTypeBDef); installer.ExecuteBatch(); }
public void ContentType_FullInstall_InheritedClass() { string contentTypeADef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode10' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='X' type='Integer' /> </Fields> </ContentType>" ; string contentTypeBDef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode11' parentType='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode11' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='Y' type='Integer' /> </Fields> </ContentType>" ; ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(contentTypeADef); installer.AddContentType(contentTypeBDef); installer.ExecuteBatch(); NodeType testNodeType10 = ActiveSchema.NodeTypes["TestNode10"]; NodeType testNodeType11 = ActiveSchema.NodeTypes["TestNode11"]; Content content = Content.CreateNew("TestNode11", this.TestRoot, "TestNode11-1"); ContentType contentType10 = ContentTypeManager.Current.GetContentTypeByName("TestNode10"); ContentType contentType11 = ContentTypeManager.Current.GetContentTypeByName("TestNode11"); ContentType contentTypeByHandler = ContentTypeManager.Current.GetContentTypeByHandler(content.ContentHandler); ContentType contentTypeByHandlerTypeName = ContentTypeManager.Current.GetContentTypeByName(content.ContentHandler.NodeType.Name); Assert.IsNotNull(testNodeType10, "#1"); Assert.IsNotNull(testNodeType11, "#2"); Assert.IsTrue(testNodeType11.Parent == testNodeType10, "#3"); Assert.IsNotNull(content.Fields["Y"], "#4"); Assert.IsNotNull(content.Fields["X"], "#5"); Assert.IsTrue(ReferenceEquals(contentTypeByHandler, contentTypeByHandlerTypeName), "#6"); Assert.IsTrue(ReferenceEquals(contentType11, contentTypeByHandlerTypeName), "#7"); Assert.IsTrue(ReferenceEquals(contentType11.ParentType, contentType10), "#8"); }
public void ContentType_FullInstall_InheritedClass_ChangeHandlers() { //-- Step 1: Install TestNode10 and TestNode11 content types with TestNode10 and TestNode11 handlers string contentTypeADef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode10' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='X' type='Integer' /> </Fields> </ContentType>" ; string contentTypeBDef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode11' parentType='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode11' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='Y' type='Integer' /> </Fields> </ContentType>" ; ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(contentTypeADef); installer.AddContentType(contentTypeBDef); installer.ExecuteBatch(); //-- Step 2: Reinstall TestNode10 and TestNode11 content types with TestNode12 and TestNode13 handlers contentTypeADef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode12' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='A' type='Integer'><DisplayName>A</DisplayName></Field> <Field name='B' type='Integer'><DisplayName>B</DisplayName></Field> <Field name='C' type='Integer'><DisplayName>C</DisplayName></Field> </Fields> </ContentType>" ; contentTypeBDef = @"<?xml version='1.0' encoding='utf-8'?> <ContentType name='TestNode11' parentType='TestNode10' handler='SenseNet.ContentRepository.Tests.ContentHandlers.TestNode13' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'> <Fields> <!-- <Field name='B' override='true' type='Integer' /> <Field name='C' override='true' type='Integer'><DisplayName>CC</DisplayName></Field> --> <Field name='B' type='Integer' /> <Field name='C' type='Integer'><DisplayName>CC</DisplayName></Field> <Field name='D' type='Integer'><DisplayName>D</DisplayName></Field> </Fields> </ContentType>" ; installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(contentTypeADef); installer.AddContentType(contentTypeBDef); installer.ExecuteBatch(); NodeType testNodeType10 = ActiveSchema.NodeTypes["TestNode10"]; NodeType testNodeType11 = ActiveSchema.NodeTypes["TestNode11"]; Content content = Content.CreateNew("TestNode11", this.TestRoot, "TestNode11-1"); ContentType contentType10 = ContentTypeManager.Current.GetContentTypeByName("TestNode10"); ContentType contentType11 = ContentTypeManager.Current.GetContentTypeByName("TestNode11"); ContentType contentTypeByHandler = ContentTypeManager.Current.GetContentTypeByHandler(content.ContentHandler); ContentType contentTypeByHandlerTypeName = ContentTypeManager.Current.GetContentTypeByName(content.ContentHandler.NodeType.Name); Assert.IsNotNull(testNodeType10, "#1"); Assert.IsNotNull(testNodeType11, "#2"); Assert.IsTrue(testNodeType11.Parent == testNodeType10, "#3"); Assert.IsTrue(ReferenceEquals(contentTypeByHandler, contentTypeByHandlerTypeName), "#4"); Assert.IsTrue(ReferenceEquals(contentType11, contentTypeByHandlerTypeName), "#5"); Assert.IsTrue(ReferenceEquals(contentType11.ParentType, contentType10), "#6"); Assert.IsTrue(content.Fields.Count == 4, "#7"); Assert.IsTrue(content.Fields["A"].DisplayName == "A", "#8"); Assert.IsTrue(content.Fields["B"].DisplayName == "B", "#9"); Assert.IsTrue(content.Fields["C"].DisplayName == "CC", "#10"); Assert.IsTrue(content.Fields["D"].DisplayName == "D", "#11"); }
public void ContentList_AvailableFields() { ContentType c = ContentType.GetByName("CT_Root"); if (c != null) { ContentTypeInstaller.RemoveContentType(c); } ContentTypeManager.Reset(); ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); installer.AddContentType(@"<?xml version='1.0' encoding='utf-8'?> <ContentType name='CT_Root' parentType='GenericContent' handler='ContentRepository.GenericContent' xmlns='http://schemas.com/ContentRepository/ContentTypeDefinition'> <Fields> <Field name='InheritanceTest' type='Integer'> <Configuration><MinValue>-5</MinValue><MaxValue>7</MaxValue></Configuration> </Field> </Fields> </ContentType>" ); installer.AddContentType("<ContentType name='CT_A' parentType='CT_Root' handler='ContentRepository.GenericContent' xmlns='http://schemas.com/ContentRepository/ContentTypeDefinition'><Fields><Field name='InheritanceTest' type='Integer'><Configuration><MinValue>0</MinValue><MaxValue>10</MaxValue></Configuration></Field></Fields></ContentType>"); installer.AddContentType("<ContentType name='CT_A_A' parentType='CT_A' handler='ContentRepository.GenericContent' xmlns='http://schemas.com/ContentRepository/ContentTypeDefinition'><Fields><Field name='InheritanceTest' type='Integer'><Configuration><MinValue>1</MinValue><MaxValue>20</MaxValue></Configuration></Field></Fields></ContentType>"); installer.AddContentType("<ContentType name='CT_B' parentType='CT_Root' handler='ContentRepository.GenericContent' xmlns='http://schemas.com/ContentRepository/ContentTypeDefinition'><Fields><Field name='InheritanceTest' type='Integer'><Configuration><MinValue>2</MinValue><MaxValue>30</MaxValue></Configuration></Field></Fields></ContentType>"); installer.AddContentType("<ContentType name='CT_B_B' parentType='CT_B' handler='ContentRepository.GenericContent' xmlns='http://schemas.com/ContentRepository/ContentTypeDefinition'><Fields><Field name='InheritanceTest' type='Integer'><Configuration><MinValue>3</MinValue><MaxValue>40</MaxValue></Configuration></Field></Fields></ContentType>"); installer.ExecuteBatch(); string listDef = @"<?xml version='1.0' encoding='utf-8'?> <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'> <DisplayName>Cars title</DisplayName> <Description>Cars description</Description> <Icon>automobile.gif</Icon> <Fields> <ContentListField name='#ListField1' type='ShortText'> <DisplayName>ContentListField1</DisplayName> <Description>ContentListField1 Description</Description> <Icon>icon.gif</Icon> <Configuration> <MaxLength>100</MaxLength> </Configuration> </ContentListField> <ContentListField name='#ListField2' type='WhoAndWhen'> <DisplayName>ContentListField2</DisplayName> <Description>ContentListField2 Description</Description> <Icon>icon.gif</Icon> <Configuration> </Configuration> </ContentListField> <ContentListField name='#ListField3' type='ShortText'> <DisplayName>ContentListField3</DisplayName> <Description>ContentListField3 Description</Description> <Icon>icon.gif</Icon> <Configuration> <MaxLength>200</MaxLength> </Configuration> </ContentListField> </Fields> </ContentListDefinition> "; var b = new bool[21]; ContentType CT_Root = ContentType.GetByName("CT_Root"); FieldSetting FS_Root = CT_Root.FieldSettings[0]; ContentType CT_A = ContentType.GetByName("CT_A"); ContentType CT_B = ContentType.GetByName("CT_B"); FieldSetting FS_A = CT_A.FieldSettings[0]; ContentType CT_A_A = ContentType.GetByName("CT_A_A"); FieldSetting FS_A_A = CT_A_A.FieldSettings[0]; string path = RepositoryPath.Combine(this.TestRoot.Path, "Cars"); if (Node.Exists(path)) { Node.ForceDelete(path); } var list = new ContentList(this.TestRoot); list.Name = "Cars"; list.ContentListDefinition = listDef; list.AllowedChildTypes = new[] { CT_A, CT_B }; list.Save(); b[0] = FS_Root.ParentFieldSetting == null; b[1] = FS_A.ParentFieldSetting == FS_Root; b[2] = FS_A_A.ParentFieldSetting == FS_A; var fields = list.GetAvailableFields(); }
public void ImportContentTypeDefinitionsAndAspects(string ctdPath, string aspectsPath) { Log(ImportLogLevel.Info, "Importing content types:"); if (ctdPath != null) { ContentTypeInstaller importer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); var ctdFiles = IO.Directory.GetFiles(ctdPath, "*.xml"); foreach (var ctdFilePath in ctdFiles) { using (var stream = new IO.FileStream(ctdFilePath, IO.FileMode.Open, IO.FileAccess.Read)) { try { Log(ImportLogLevel.Verbose, " " + System.IO.Path.GetFileName(ctdFilePath)); importer.AddContentType(stream); } catch (ApplicationException e) { Logger.Errors++; Log(ImportLogLevel.Info, " SKIPPED: " + e.Message); } } } Log(ImportLogLevel.Progress, " " + ctdFiles.Length + " file loaded..."); using (CreateProgressBar()) importer.ExecuteBatch(); Log(ImportLogLevel.Info, " " + ctdFiles.Length + " CTD imported."); Log(ImportLogLevel.Progress, "Ok"); } else { Log(ImportLogLevel.Info, "CTDs not changed"); } //============================================================== if (aspectsPath != null) { if (!Node.Exists(Repository.AspectsFolderPath)) { Log(ImportLogLevel.Info, "Creating aspect container (" + Repository.AspectsFolderPath + ")..."); Content.CreateNew(typeof(SystemFolder).Name, Repository.SchemaFolder, "Aspects").Save(); Log(ImportLogLevel.Info, " Ok"); } var aspectFiles = System.IO.Directory.GetFiles(aspectsPath, "*.content"); Log(ImportLogLevel.Info, "Importing aspects:"); ImportContents(aspectsPath, Repository.AspectsFolderPath, true); Log(ImportLogLevel.Info, " " + aspectFiles.Length + " aspect" + (aspectFiles.Length > 1 ? "s" : "") + " imported."); Log(ImportLogLevel.Progress, "Ok"); } else { Log(ImportLogLevel.Info, "Aspects not changed."); } }
public void InstallContentTypeDefinitionsAndAspects(string ctdPath, string aspectsPath) { LogWriteLine("Loading content types..."); if (ctdPath != null) { ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller(); foreach (string ctdFilePath in Directory.GetFiles(ctdPath, "*.xml")) { LogWrite(Path.GetFileName(ctdFilePath)); LogWrite(" ..."); using (var stream = new FileStream(ctdFilePath, FileMode.Open, FileAccess.Read)) { try { installer.AddContentType(stream); } catch (ApplicationException e) { _exceptions++; LogWriteLine(" SKIPPED: " + e.Message); } } LogWriteLine(" Ok"); } LogWriteLine(); LogWrite("Installing content types..."); installer.ExecuteBatch(); LogWriteLine(" Ok"); LogWriteLine(); } else { LogWriteLine("CTDs not changed"); } //============================================================== LogWriteLine("---------------------------------------"); LogWriteLine(); if (aspectsPath != null) { if (!Node.Exists(Repository.AspectsFolderPath)) { LogWrite("Creating aspect container (", Repository.AspectsFolderPath, ")..."); Content.CreateNew(typeof(SystemFolder).Name, Repository.SchemaFolder, "Aspects").Save(); LogWriteLine("Ok"); } LogWriteLine("Installing aspects..."); ImportContents(aspectsPath, Repository.AspectsFolderPath, true, true); LogWriteLine("Ok"); } else { LogWriteLine("Aspects not changed."); } LogWriteLine("======================================="); LogWriteLine(); LogWrite("Schema import finished"); LogWriteLine(); //============================================================== }