private ContentListType ManageContentListType(Dictionary <string, FieldDescriptor> fieldInfoList, Dictionary <string, List <string> > oldBindings, bool modify, out List <FieldSetting> fieldSettings) { var attempts = 0; while (true) { try { return(ManageContentListTypeOneAttempt(fieldInfoList, oldBindings, modify, out fieldSettings)); } catch (Exception e) { if (!e.Message.Contains("Storage schema is out of date") || attempts++ >= 42) { throw; } } var timer = Stopwatch.StartNew(); ActiveSchema.Reload(); ContentTypeManager.Reload(); timer.Stop(); var d = timer.Elapsed; var timeString = $"{d.Minutes}:{d.Seconds}.{d.Milliseconds}"; SnLog.WriteInformation( $"Type system is reloaded because it was out of date during managing a list type. Attempt: {attempts}, reloading time: {timeString}", EventId.RepositoryRuntime); } }
public void ContentType_MorePermissiveLoad_MissingContentHandler_Load() { Test(() => { var ctd0 = @"<ContentType name=""MyType1"" parentType=""GenericContent"" handler=""SenseNet.ContentRepository.GenericContent"" xmlns=""http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition""> <Fields> <Field name=""Field1"" type=""ShortText""></Field> </Fields> </ContentType>"; var ctd1 = @"<ContentType name=""MyType1"" parentType=""GenericContent"" handler=""MyType"" xmlns=""http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition""> <Fields> <Field name=""Field1"" type=""ShortText""></Field> </Fields> </ContentType>"; // ARRANGE ContentTypeInstaller.InstallContentType(ctd0); var myType = ContentType.GetByName("MyType1"); Assert.IsNotNull(myType); Assert.IsNotNull(myType.FieldSettings.FirstOrDefault(x => x.Name == "Field1")); HackDatabaseForMorePermissiveLoadTest("MyType1", ctd0, ctd1); // ACTION: Reload schema from the database. Cache.Reset(); ContentTypeManager.Reload(); // ASSERT: the ContentType is loaded but invalid. var myType1 = ContentType.GetByName("MyType1"); Assert.AreEqual(ctd1, myType1.ToXml()); Assert.IsTrue(myType1.IsInvalid); }); }
public void ContentType_MorePermissiveLoad_MissingBinding_Create() { Test(() => { var ctd0 = @"<ContentType name=""MyType1"" parentType=""GenericContent"" handler=""SenseNet.ContentRepository.GenericContent"" xmlns=""http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition""> <Fields> <Field name=""Image2"" type=""Image""></Field> </Fields> </ContentType>"; var ctd1 = @"<ContentType name=""MyType1"" parentType=""GenericContent"" handler=""SenseNet.ContentRepository.GenericContent"" xmlns=""http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition""> <Fields> <Field name=""ImageRef"" type=""Reference""></Field> <Field name=""ImageData"" type=""Binary""></Field> <Field name=""Image2"" type=""Image""> <Bind property=""ImageRef"" /> <Bind property=""ImageData"" /> </Field> </Fields> </ContentType>"; // ACTION-1: Try install an invalid CTD. try { //ContentTypeInstaller.InstallContentType(ctd0); var binaryData = new BinaryData(); binaryData.FileName = "MyType1"; binaryData.SetStream(RepositoryTools.GetStreamFromString(ctd0)); var contentType = new ContentType(ContentType.GetByName("GenericContent")) { Name = "MyType1", Binary = binaryData }; contentType.Save(); Assert.Fail("The expected exception was not thrown."); } catch (ContentRegistrationException e) { // do nothing } // ACTION-2: reinstall without any problem. ContentTypeInstaller.InstallContentType(ctd1); // ACTION-3: Reload schema from the database. Cache.Reset(); ContentTypeManager.Reload(); // ASSERT: the ContentType is loaded and valid. var myType1 = ContentType.GetByName("MyType1"); Assert.AreEqual(ctd1, myType1.ToXml()); Assert.IsFalse(myType1.IsInvalid); Assert.IsNotNull(myType1.FieldSettings.FirstOrDefault(x => x.Name == "Image2")); }); }
private static void SetContentHandlerAndResetManagers(string handlerName, Action action) { // set the handler of the Folder type to an unknown value SetContentHandler("Folder", handlerName); Cache.Reset(); NodeTypeManager.Restart(); ContentTypeManager.Reload(); action(); }
private static void ResetAndFailToCreateContent() { Cache.Reset(); NodeTypeManager.Restart(); ContentTypeManager.Reload(); var parent = Node.Load <GenericContent>("/Root"); // try to create a content with an unknown field ExpectException(() => { var content = Content.CreateNew("Folder", parent, Guid.NewGuid().ToString()); content.Save(); }, typeof(SnNotSupportedException)); // try to create a content with a known handler that has an unknown parent ExpectException(() => { var content = Content.CreateNew("SystemFolder", parent, Guid.NewGuid().ToString()); content.Save(); }, typeof(SnNotSupportedException)); }
public void UnknownHandler_CreateContent_FieldTable() { // This test is necessary because the OData layer calls the field name getter method. Test(() => { var parent = Node.Load <GenericContent>("/Root"); var content = Content.CreateNew("Folder", parent, Guid.NewGuid().ToString()); var fieldNamesBefore = string.Join(",", content.GetFieldNamesInParentTable().OrderBy(fn => fn)); // set the handler of the Folder type to an unknown value SetContentHandler("Folder", "UnknownFieldTable"); Cache.Reset(); NodeTypeManager.Restart(); ContentTypeManager.Reload(); parent = Node.Load <GenericContent>("/Root"); content = Content.CreateNew("Folder", parent, Guid.NewGuid().ToString()); var fieldNamesAfter = string.Join(",", content.GetFieldNamesInParentTable().OrderBy(fn => fn)); Assert.AreEqual(fieldNamesBefore, fieldNamesAfter); }); }