public void CreateStub() { string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); _contentService = new ContentService(unitOfWork, repoFactory); var contentTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); var contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var parentContent = new Content(name, -1, contentType); parentContent.Key = new Guid("{373D1D1C-BD0D-4A8C-9A67-1D513815FE10}"); _contentService.Save(parentContent); var content = new Content(name, parentContent.Id, contentType); content.Key = new Guid("{3F34475B-D744-40E9-BC30-5D33249FA9FE}"); _contentService.Save(content); }
public void CreateStub() { string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; _unitOfWork = Global.CreateUnitOfWork(); _repoFactory = new RepositoryFactory(); var contentService = new ContentService(_unitOfWork, _repoFactory); var contentTypeService = new ContentTypeService(_unitOfWork, _repoFactory, new ContentService(_unitOfWork), new MediaService(_unitOfWork, _repoFactory)); var contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.Key = new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"); contentService.Save(content); contentService.Publish(content); }
public void ConnectionTest() { var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); var service = new ContentService(unitOfWork, repoFactory); var cTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); ContentType cType = new ContentType(-1); cType.Name = "TestType"; cType.Alias = "TestType"; cType.Thumbnail = string.Empty; cTypeService.Save(cType); Console.WriteLine("Ctype " + cType.Id); Assert.Greater(cType.Id, 0); Content content = new Content("METest", -1, cType); service.Save(content); Assert.Greater(content.Id, 0); var content2 = service.GetById(content.Id); Assert.AreEqual(content.Name, content2.Name); }
public void CreateStub() { string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); _contentService = new ContentService(unitOfWork, repoFactory); var contentTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); var contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.Key = new Guid("{263768E1-E958-4B00-BB00-191CC33A3F48}"); _contentService.Save(content); }
public void CreateStub() { string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; _unitOfWork = Global.CreateUnitOfWork(); _repoFactory = new RepositoryFactory(); var contentService = new ContentService(_unitOfWork, _repoFactory); var contentTypeService = new ContentTypeService(_unitOfWork, _repoFactory, new ContentService(_unitOfWork), new MediaService(_unitOfWork, _repoFactory)); var contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var parentContent = new Content(name, -1, contentType); parentContent.Key = new Guid("{4172C94F-52C1-4301-9CDA-FD2142496C95}"); contentService.Save(parentContent); var content = new Content(name, parentContent.Id, contentType); content.Key = new Guid("{C382AE57-D325-4357-A32A-0A959BBD4101}"); contentService.Save(content); }
public void General_RetrieveItemsAndFieldsFromUmbraco_ReturnPopulatedClass() { const string fieldValue = "test field value"; const string name = "Target"; const string contentTypeAlias = "TestType"; const string contentTypeName = "Test Type"; const string contentTypeProperty = "TestProperty"; var context = WindsorContainer.GetContext(); var loader = new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration"); context.Load(loader); IContentType contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; ContentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = DataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea")); var firstDefinition = definitions.FirstOrDefault(); DataTypeService.Save(firstDefinition); var propertyType = new PropertyType(firstDefinition) { Alias = contentTypeProperty }; contentType.AddPropertyType(propertyType); ContentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.SetPropertyValue(contentTypeProperty, fieldValue); ContentService.Save(content); var umbracoService = new UmbracoService(ContentService, context); //Act var result = umbracoService.GetItem <AttributeStub>(content.Id); //Assert Assert.IsNotNull(result); Assert.AreEqual(fieldValue, result.TestProperty); Assert.AreEqual(content.Id, result.Id); Assert.AreEqual(content.Key, result.Key); Assert.AreEqual(name, result.Name); Assert.AreEqual(contentTypeName, result.ContentTypeName); Assert.AreEqual(content.ParentId + "," + content.Id, result.Path); Assert.AreEqual(contentTypeAlias, result.ContentTypeAlias); Assert.AreEqual(content.Version, result.Version); }
public void CreateTestData() { Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // Create and Save ContentType "textpage" -> ContentType.Id ContentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id); ContentTypeService.Save(ContentType); }
public void CreateStub() { bool fieldValue = false; string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); _contentService = new ContentService(unitOfWork, repoFactory); var contentTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); var dataTypeService = new DataTypeService(unitOfWork, repoFactory); var contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("38b352c1-e9f8-4fd8-9324-9a2eab06d97a")); dataTypeService.Save(definitions.FirstOrDefault()); var propertyType = new PropertyType(definitions.FirstOrDefault()); propertyType.Alias = ContentTypeProperty; contentType.AddPropertyType(propertyType); contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.Key = new Guid("{5928EFBB-6DF2-4BB6-A026-BF4938D7ED7A}"); content.SetPropertyValue(ContentTypeProperty, fieldValue); _contentService.Save(content); }
public void CreateStub() { string fieldValue = "test field value"; string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); _contentService = new ContentService(unitOfWork, repoFactory); var contentTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); var dataTypeService = new DataTypeService(unitOfWork, repoFactory); var contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea")); dataTypeService.Save(definitions.FirstOrDefault()); var propertyType = new PropertyType(definitions.FirstOrDefault()); propertyType.Alias = "Property"; contentType.AddPropertyType(propertyType); contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.Key = new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}"); content.SetPropertyValue("Property", fieldValue); _contentService.Save(content); }
public void CreateTestData() { var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // else, FK violation on contentType! var ct = ContentTypeBuilder.CreateSimpleContentType("blah", "Blah", defaultTemplateId: template.Id); ContentTypeService.Save(ct); _content = ContentBuilder.CreateSimpleContent(ct, "Test"); ContentService.Save(_content); }
public void CreateStub() { string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); _contentService = new ContentService(unitOfWork, repoFactory); var contentTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); var dataTypeService = new DataTypeService(unitOfWork, repoFactory); var contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea")); dataTypeService.Save(definitions.FirstOrDefault()); var propertyType = new PropertyType(definitions.FirstOrDefault()); propertyType.Alias = "Property"; contentType.AddPropertyType(propertyType); contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.Key = new Guid("{2867D837-B258-4DF1-90F1-D5E849FCAF84}"); _contentService.Save(content); }
public void Automatically_Track_Relations() { var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type"); MediaTypeService.Save(mt); var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); var m2 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); MediaService.Save(m1); MediaService.Save(m2); var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest", defaultTemplateId: template.Id); ct.AllowedTemplates = Enumerable.Empty <ITemplate>(); ContentTypeService.Save(ct); var c1 = ContentBuilder.CreateTextpageContent(ct, "my content 1", -1); ContentService.Save(c1); var c2 = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1); // 'bodyText' is a property with a RTE property editor which we knows tracks relations c2.Properties["bodyText"].SetValue(@"<p> <img src='/media/12312.jpg' data-udi='umb://media/" + m1.Key.ToString("N") + @"' /> </p><p><img src='/media/234234.jpg' data-udi=""umb://media/" + m2.Key.ToString("N") + @""" /> </p> <p> <a href=""{locallink:umb://document/" + c1.Key.ToString("N") + @"}"">hello</a> </p>"); ContentService.Save(c2); var relations = RelationService.GetByParentId(c2.Id).ToList(); Assert.AreEqual(3, relations.Count); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[0].RelationType.Alias); Assert.AreEqual(m1.Id, relations[0].ChildId); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[1].RelationType.Alias); Assert.AreEqual(m2.Id, relations[1].ChildId); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedDocumentAlias, relations[2].RelationType.Alias); Assert.AreEqual(c1.Id, relations[2].ChildId); }
public void CreateTestData() { var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // else, FK violation on contentType! _contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", defaultTemplateId: template.Id); _contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "tags") { DataTypeId = Constants.DataTypes.Tags }); ContentTypeService.Save(_contentType); }
public virtual void CreateTestData() { // NOTE Maybe not the best way to create/save test data as we are using the services, which are being tested. var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // Create and Save ContentType "umbTextpage" -> 1051 (template), 1052 (content type) ContentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); ContentType.Key = new Guid("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"); ContentTypeService.Save(ContentType); // Create and Save Content "Homepage" based on "umbTextpage" -> 1053 Textpage = ContentBuilder.CreateSimpleContent(ContentType); Textpage.Key = new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0"); ContentService.Save(Textpage, 0); // Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054 Subpage = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 1", Textpage.Id); var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null); ContentService.Save(Subpage, 0, contentSchedule); // Create and Save Content "Text Page 1" based on "umbTextpage" -> 1055 Subpage2 = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 2", Textpage.Id); ContentService.Save(Subpage2, 0); Subpage3 = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 3", Textpage.Id); ContentService.Save(Subpage3, 0); // Create and Save Content "Text Page Deleted" based on "umbTextpage" -> 1056 Trashed = ContentBuilder.CreateSimpleContent(ContentType, "Text Page Deleted", -20); Trashed.Trashed = true; ContentService.Save(Trashed, 0); }
public void Process(IEnumerable <DocumentTypeMetadata> types) { var contentTypes = new List <IContentType>(); var dataTypeDefinitions = DataTypeService.GetAllDataTypeDefinitions().ToArray(); foreach (var type in types) { var ct = ContentTypeService.GetContentType(type.Alias) ?? new ContentType(-1); ct.Name = type.Name; ct.Alias = type.Alias; ct.AllowedAsRoot = type.AllowAsRoot; ct.Description = type.Description; ct.Icon = type.Icon; ct.Thumbnail = type.Thumbnail; var properties = ct.PropertyTypes.ToArray(); var newProperties = type.Properties.Where(p => !properties.Any(x => x.Alias == p.Alias)); foreach (var property in newProperties) { var p = new PropertyType(dataTypeDefinitions.First(dtd => dtd.Name == property.DataType)) { Name = property.Name, Alias = property.Alias, Description = property.Description }; if (property.Tab == null) { ct.AddPropertyType(p); } else { ct.AddPropertyType(p, property.Tab.ToString()); } } var modifiedProperties = type.Properties.Join(properties, p => p.Alias, p => p.Alias, (meta, p) => new { Metadata = meta, PropertyType = p }); foreach (var property in modifiedProperties) { var p = property.PropertyType; var meta = property.Metadata; p.Name = meta.Name; p.DataTypeDefinitionId = dataTypeDefinitions.First(dtd => dtd.Name == meta.DataType).Id; p.Description = meta.Description; //the following hack is brought to you be the letter F var fn = p.GetType().GetProperty("PropertyGroupId", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(p) as System.Lazy <int>; if (fn != null) { var tabId = fn.Value; var tab = ct.PropertyGroups.FirstOrDefault(t => t.Id == tabId); var newTabName = meta.Tab.ToString(); var newTab = ct.PropertyGroups.FirstOrDefault(t => t.Name == newTabName); if (tab != null && tab.Name != newTabName) { if (newTab == null) { ct.AddPropertyGroup(newTabName); } ct.MovePropertyType(p.Alias, newTabName); } } } contentTypes.Add(ct); } ContentTypeService.Save(contentTypes); var preprocessedData = contentTypes .Join(types, x => x.Alias, x => x.Alias, (ct, m) => new { ct, m }) .ToDictionary(x => x.ct, x => x.m); SetupAllowedChildren(preprocessedData); SetupTemplates(preprocessedData); ContentTypeService.Save(contentTypes); }
public void Retrieving_All_Content_In_Site() { // NOTE: Doing this the old 1 by 1 way and based on the results of the ContentServicePerformanceTest.Retrieving_All_Content_In_Site // the old way takes 143795ms, the new above way takes: // 14249ms // // ... NOPE, made some new changes, it is now.... // 5290ms !!!!!! // // that is a 96% savings of processing and sql calls! // // ... NOPE, made even more nice changes, it is now... // 4452ms !!!!!!! Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); ContentType contentType1 = ContentTypeBuilder.CreateTextPageContentType("test1", "test1", defaultTemplateId: template.Id); ContentType contentType2 = ContentTypeBuilder.CreateTextPageContentType("test2", "test2", defaultTemplateId: template.Id); ContentType contentType3 = ContentTypeBuilder.CreateTextPageContentType("test3", "test3", defaultTemplateId: template.Id); ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 }); contentType1.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType2.Id), 0, contentType2.Alias), new ContentTypeSort(new Lazy <int>(() => contentType3.Id), 1, contentType3.Alias) }; contentType2.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType1.Id), 0, contentType1.Alias), new ContentTypeSort(new Lazy <int>(() => contentType3.Id), 1, contentType3.Alias) }; contentType3.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType1.Id), 0, contentType1.Alias), new ContentTypeSort(new Lazy <int>(() => contentType2.Id), 1, contentType2.Alias) }; ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 }); IEnumerable <Content> roots = ContentBuilder.CreateTextpageContent(contentType1, -1, 10); ContentService.Save(roots); foreach (Content root in roots) { IEnumerable <Content> item1 = ContentBuilder.CreateTextpageContent(contentType1, root.Id, 10); IEnumerable <Content> item2 = ContentBuilder.CreateTextpageContent(contentType2, root.Id, 10); IEnumerable <Content> item3 = ContentBuilder.CreateTextpageContent(contentType3, root.Id, 10); ContentService.Save(item1.Concat(item2).Concat(item3)); } var total = new List <IContent>(); using (GetTestProfilingLogger().TraceDuration <ContentServicePerformanceTest>("Getting all content in site")) { TestProfiler.Enable(); total.AddRange(ContentService.GetRootContent()); foreach (IContent content in total.ToArray()) { total.AddRange(ContentService.GetPagedDescendants(content.Id, 0, int.MaxValue, out long _)); } TestProfiler.Disable(); StaticApplicationLogging.Logger.LogInformation("Returned {Total} items", total.Count); } }
public void General_RetrieveContentAndPropertiesFromUmbraco_ReturnPopulatedClass() { //Assign string fieldValue = "test field value"; string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; string contentTypeProperty = "TestProperty"; var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); var contentService = new ContentService(unitOfWork, repoFactory); var contentTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); var dataTypeService = new DataTypeService(unitOfWork, repoFactory); var context = WindsorContainer.GetContext(); var loader = new UmbracoFluentConfigurationLoader(); var stubConfig = loader.Add <Stub>(); stubConfig.Configure(x => { x.Id(y => y.Id); x.Id(y => y.Key); x.Property(y => y.TestProperty); x.Info(y => y.Name).InfoType(UmbracoInfoType.Name); x.Info(y => y.ContentTypeName).InfoType(UmbracoInfoType.ContentTypeName); x.Info(y => y.ContentTypeAlias).InfoType(UmbracoInfoType.ContentTypeAlias); x.Info(y => y.Path).InfoType(UmbracoInfoType.Path); x.Info(y => y.Version).InfoType(UmbracoInfoType.Version); x.Info(y => y.CreateDate).InfoType(UmbracoInfoType.CreateDate); x.Info(y => y.UpdateDate).InfoType(UmbracoInfoType.UpdateDate); x.Info(y => y.Creator).InfoType(UmbracoInfoType.Creator); x.Delegate(y => y.Delegated).GetValue(GetDelegatedValue); }); context.Load(loader); IContentType contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea")); dataTypeService.Save(definitions.FirstOrDefault()); var propertyType = new PropertyType(definitions.FirstOrDefault()); propertyType.Alias = contentTypeProperty; contentType.AddPropertyType(propertyType); contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.SetPropertyValue(contentTypeProperty, fieldValue); contentService.Save(content); var umbracoService = new UmbracoService(contentService, context); //Act var result = umbracoService.GetItem <Stub>(content.Id); //Assert Assert.IsNotNull(result); Assert.AreEqual(fieldValue, result.TestProperty); Assert.AreEqual(content.Id, result.Id); Assert.AreEqual(content.Key, result.Key); Assert.AreEqual(name, result.Name); Assert.AreEqual(contentTypeName, result.ContentTypeName); Assert.AreEqual(content.ParentId + "," + content.Id, result.Path); Assert.AreEqual(contentTypeAlias, result.ContentTypeAlias); Assert.AreEqual(content.Version, result.Version); Assert.AreEqual(content.CreateDate, result.CreateDate); Assert.AreEqual(content.UpdateDate, result.UpdateDate); Assert.AreEqual("admin", result.Creator); Assert.AreEqual("happy", result.Delegated); }
public static void AddSocialMediaChannelMediaType() { MediaType mediaType = new MediaType(-1); mediaType.AllowedAsRoot = true; mediaType.Name = SOCIAL_MEDIA_THEME_NAME; mediaType.Description = "Container for the Social Media Channel Theme Images"; mediaType.IsContainer = true; mediaType.Icon = "icon-picture"; mediaType.Alias = SOCIAL_MEDIA_THEME_ALIAS; //Allowed child nodes var children = new List <ContentTypeSort> { new ContentTypeSort(FOLDER_ID, 0), new ContentTypeSort(IMAGE_ID, 1) }; mediaType.AllowedContentTypes = children; //Add properties DataTypeService dataTypeService = (DataTypeService)ApplicationContext.Current.Services.DataTypeService; var name = new PropertyType(dataTypeService.GetDataTypeDefinitionById(TEXT_ID), "themeName"); name.Name = "Theme Name"; name.Description = "Name for the theme"; name.SortOrder = 0; var url = new PropertyType(dataTypeService.GetDataTypeDefinitionById(TEXT_ID), "themeUrl"); url.Name = "Theme Url"; url.Description = "Url for the original theme"; url.SortOrder = 1; var createdBy = new PropertyType(dataTypeService.GetDataTypeDefinitionById(TEXT_ID), "createdBy"); createdBy.Name = "Created By"; createdBy.Description = "Theme Author"; createdBy.SortOrder = 2; var createdDate = new PropertyType(dataTypeService.GetDataTypeDefinitionById(DATE_ID), "createdDate"); createdDate.Name = "Created Date"; createdDate.Description = "Date the Theme was created"; createdDate.SortOrder = 3; var upload = new PropertyType(dataTypeService.GetDataTypeDefinitionById(UPLOAD_ID), "umbracoFile"); upload.Name = "Upload Image"; upload.Description = "Theme Thumbnail"; upload.SortOrder = 4; var width = new PropertyType(dataTypeService.GetDataTypeDefinitionById(LABEL_ID), "umbracoWidth"); width.Name = "Image Width"; width.SortOrder = 5; var height = new PropertyType(dataTypeService.GetDataTypeDefinitionById(LABEL_ID), "umbracoHeight"); height.Name = "Image Height"; height.SortOrder = 5; var size = new PropertyType(dataTypeService.GetDataTypeDefinitionById(LABEL_ID), "umbracoBytes"); size.Name = "Image Size"; size.SortOrder = 5; var extension = new PropertyType(dataTypeService.GetDataTypeDefinitionById(LABEL_ID), "umbracoExtension"); extension.Name = "Image Extension"; extension.SortOrder = 5; mediaType.AddPropertyType(name, "Theme"); mediaType.AddPropertyType(url, "Theme"); mediaType.AddPropertyType(createdBy, "Theme"); mediaType.AddPropertyType(createdDate, "Theme"); mediaType.AddPropertyType(upload, "Theme"); mediaType.AddPropertyType(width, "Theme"); mediaType.AddPropertyType(height, "Theme"); mediaType.AddPropertyType(size, "Theme"); mediaType.AddPropertyType(extension, "Theme"); //Save new media type ContentTypeService contentTypeService = (ContentTypeService)ApplicationContext.Current.Services.ContentTypeService; contentTypeService.Save(mediaType); }
/// <summary> /// Save changes to this document type, includes any changes to properties. /// </summary> /// <returns></returns> public DocumentType Save() { ContentTypeService.Save(UmbracoContentType); return(this); }