public void Setup()
        {
            MockSettings();

            expected           = CreateCodeGenDocumentType();
            umbracoContentType = CreateUmbracoContentType();
        }
        public static ContentType CreateMetaContentType()
        {
            var contentType = new ContentType(-1)
                                  {
                                      Alias = "meta",
                                      Name = "Meta",
                                      Description = "ContentType used for Meta tags",
                                      Icon = ".sprTreeDoc3",
                                      Thumbnail = "doc.png",
                                      SortOrder = 1,
                                      CreatorId = 0,
                                      Trashed = false
                                  };

            var metaCollection = new PropertyTypeCollection();
            metaCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "metakeywords", Name = "Meta Keywords", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
            metaCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "metadescription", Name = "Meta Description", Description = "", HelpText = "", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -89 });

            contentType.PropertyGroups.Add(new PropertyGroup(metaCollection) { Name = "Meta", SortOrder = 2 });

            //ensure that nothing is marked as dirty
            contentType.ResetDirtyProperties(false);

            return contentType;
        }
        public void Can_Save_ContentType_Structure_And_Create_Content_Based_On_It()
        {
            // Arrange
            var cs = ServiceContext.ContentService;
            var cts = ServiceContext.ContentTypeService;
            var dtdYesNo = ServiceContext.DataTypeService.GetDataTypeDefinitionById(-49);
            var ctBase = new ContentType(-1) { Name = "Base", Alias = "Base", Icon = "folder.gif", Thumbnail = "folder.png" };
            ctBase.AddPropertyType(new PropertyType(dtdYesNo) { Name = "Hide From Navigation", Alias = "umbracoNaviHide" } /*,"Navigation"*/ );
            cts.Save(ctBase);

            var ctHomePage = new ContentType(ctBase) { Name = "Home Page", Alias = "HomePage", Icon = "settingDomain.gif", Thumbnail = "folder.png", AllowedAsRoot = true };
            bool addedContentType = ctHomePage.AddContentType(ctBase);
            ctHomePage.AddPropertyType(new PropertyType(dtdYesNo) { Name = "Some property", Alias = "someProperty" }  /*,"Navigation"*/ );
            cts.Save(ctHomePage);

            // Act
            var homeDoc = cs.CreateContent("Home Page", -1, "HomePage");
            cs.SaveAndPublish(homeDoc);

            // Assert
            Assert.That(ctBase.HasIdentity, Is.True);
            Assert.That(ctHomePage.HasIdentity, Is.True);
            Assert.That(homeDoc.HasIdentity, Is.True);
            Assert.That(homeDoc.ContentTypeId, Is.EqualTo(ctHomePage.Id));
            Assert.That(addedContentType, Is.True);
        }
        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 static ContentType CreateTextpageContentType()
        {
            var contentType = new ContentType(-1)
                                  {
                                      Alias = "textPage",
                                      Name = "Text Page",
                                      Description = "ContentType used for Text pages",
                                      Icon = ".sprTreeDoc3",
                                      Thumbnail = "doc.png",
                                      SortOrder = 1,
                                      CreatorId = 0,
                                      Trashed = false
                                  };

            var contentCollection = new PropertyTypeCollection();
            contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "title", Name = "Title", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
            contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Description = "", HelpText = "", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -87 });

            var metaCollection = new PropertyTypeCollection();
            metaCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "keywords", Name = "Meta Keywords", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
            metaCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "metaDescription", Name = "Meta Description", Description = "", HelpText = "", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -89 });

            contentType.PropertyGroups.Add(new PropertyGroup(contentCollection) { Name = "Content", SortOrder = 1 });
            contentType.PropertyGroups.Add(new PropertyGroup(metaCollection) { Name = "Meta", SortOrder = 2 });

            return contentType;
        }
        public static ContentType CreateSimpleContentType()
        {
            var contentType = new ContentType(-1)
                                  {
                                      Alias = "simple",
                                      Name = "Simple Page",
                                      Description = "ContentType used for simple text pages",
                                      Icon = ".sprTreeDoc3",
                                      Thumbnail = "doc.png",
                                      SortOrder = 1,
                                      CreatorId = 0,
                                      Trashed = false
                                  };

            var contentCollection = new PropertyTypeCollection();
            contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "title", Name = "Title", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
            contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Description = "", HelpText = "", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -87 });
            contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "author", Name = "Author", Description = "Name of the author", HelpText = "", Mandatory = false, SortOrder = 3, DataTypeDefinitionId = -88 });

            contentType.PropertyGroups.Add(new PropertyGroup(contentCollection) { Name = "Content", SortOrder = 1 });

            //ensure that nothing is marked as dirty
            contentType.ResetDirtyProperties(false);

            return contentType;
        }
        public static ContentType CreateTextpageContentType(string alias = "textPage", string name = "Text Page")
        {
            var contentType = new ContentType(-1)
                                  {
                                      Alias = alias,
                                      Name = name,
                                      Description = "ContentType used for Text pages",
                                      Icon = ".sprTreeDoc3",
                                      Thumbnail = "doc.png",
                                      SortOrder = 1,
                                      CreatorId = 0,
                                      Trashed = false
                                  };

            var contentCollection = new PropertyTypeCollection();
            contentCollection.Add(new PropertyType("test", DataTypeDatabaseType.Ntext) { Alias = "title", Name = "Title", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
            contentCollection.Add(new PropertyType("test", DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Description = "", HelpText = "", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -87 });

            var metaCollection = new PropertyTypeCollection();
            metaCollection.Add(new PropertyType("test", DataTypeDatabaseType.Ntext) { Alias = "keywords", Name = "Meta Keywords", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
            metaCollection.Add(new PropertyType("test", DataTypeDatabaseType.Ntext) { Alias = "metaDescription", Name = "Meta Description", Description = "", HelpText = "", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -89 });

            contentType.PropertyGroups.Add(new PropertyGroup(contentCollection) { Name = "Content", SortOrder = 1 });
            contentType.PropertyGroups.Add(new PropertyGroup(metaCollection) { Name = "Meta", SortOrder = 2 });

            //ensure that nothing is marked as dirty
            contentType.ResetDirtyProperties(false);

            return contentType;
        }
		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 static SimpleContentType FromContentType(ContentType contentType, bool recurse = true) {
			if (contentType == null) return null;

			var result = new SimpleContentType() {
				Id = contentType.Id,
				Alias = contentType.Alias
			};

			if (recurse) {
				result.Parent = FromContentType(contentType.ParentId);
			}

			return result;
		}
        /// <summary>
        /// This method is called when the Content Type declared in the attribute hasn't been found in Umbraco
        /// </summary>
        /// <param name="contentTypeService"></param>
        /// <param name="fileService"></param>
        /// <param name="attribute"></param>
        /// <param name="type"></param>
        /// <param name="dataTypeService"></param>
        private static void CreateContentType(IContentTypeService contentTypeService, IFileService fileService,
            UmbracoContentTypeAttribute attribute, Type type, IDataTypeService dataTypeService)
        {
            IContentType newContentType;
            Type parentType = type.BaseType;
            if (parentType != null && parentType != typeof(UmbracoGeneratedBase) && parentType.GetBaseTypes(false).Any(x => x == typeof(UmbracoGeneratedBase)))
            {
                UmbracoContentTypeAttribute parentAttribute = parentType.GetCustomAttribute<UmbracoContentTypeAttribute>();
                if (parentAttribute != null)
                {
                    string parentAlias = parentAttribute.ContentTypeAlias;
                    IContentType parentContentType = contentTypeService.GetContentType(parentAlias);
                    newContentType = new ContentType(parentContentType);
                }
                else
                {
                    throw new Exception("The given base class has no UmbracoContentTypeAttribute");
                }
            }
            else
            {
                newContentType = new ContentType(-1);
            }

            newContentType.Name = attribute.ContentTypeName;
            newContentType.Alias = attribute.ContentTypeAlias;
            newContentType.Icon = attribute.Icon;

            if (attribute.CreateMatchingView)
            {
                CreateMatchingView(fileService, attribute, type, newContentType);
            }

            newContentType.AllowedAsRoot = attribute.AllowedAtRoot;
            newContentType.IsContainer = attribute.EnableListView;
            newContentType.AllowedContentTypes = FetchAllowedContentTypes(attribute.AllowedChildren, contentTypeService);

            //create tabs
            CreateTabs(newContentType, type, dataTypeService);

            //create properties on the generic tab
            var propertiesOfRoot = type.GetProperties().Where(x => x.GetCustomAttribute<UmbracoPropertyAttribute>() != null);
            foreach (var item in propertiesOfRoot)
            {
                CreateProperty(newContentType, null, dataTypeService, true, item);
            }

            //Save and persist the content Type
            contentTypeService.Save(newContentType, 0);
        }
        public static DocumentType MakeNew(User u, string Text)
        {
            var contentType = new Umbraco.Core.Models.ContentType(-1)
            {
                Name = Text, Alias = Text, CreatorId = u.Id, Thumbnail = "icon-folder", Icon = "icon-folder"
            };

            ApplicationContext.Current.Services.ContentTypeService.Save(contentType, u.Id);
            var newDt = new DocumentType(contentType);

            //event
            NewEventArgs e = new NewEventArgs();

            newDt.OnNew(e);

            return(newDt);
        }
		public void Setup()
		{
			IOC.UnitTest();
			_contentServiceMock = new IOCBuilder<IContentService>().SetupNewMock(); //  IOC.ContentService.SetupNewMock();
			_mockContentTypeService = new IOCBuilder<IContentTypeService>().SetupNewMock(); //IOC.ContentTypeService.SetupNewMock();

			var productInfo = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(995, 1);
			productInfo.DocTypeAlias = "uwbsProductCustom";
			productInfo.Title = "Nikes";
			_orderInfo = DefaultFactoriesAndSharedFunctionality.CreateOrderInfo(productInfo);
			_orderInfo.OrderNumber = "2013001";
			var contentType = new ContentType(1) {Id = 1234};
			_mockContentTypeService.Setup(m => m.GetContentType(Order.OrderRepositoryNodeAlias)).Returns(contentType);
			_contentServiceMock.Setup(m => m.GetContentOfContentType(1234)).Returns(new List<IContent> {new Content("", 1, contentType)});
			_contentServiceMock.Setup(m => m.GetChildren(It.IsAny<int>())).Returns(new List<IContent>());
			_contentServiceMock.Setup(m => m.CreateContent("2013001", It.IsAny<IContent>(), It.IsAny<string>(), It.IsAny<int>())).Returns(new Content("2013001", 1, contentType));
			_contentServiceMock.Setup(m => m.CreateContent("Nikes", It.IsAny<IContent>(), It.IsAny<string>(), It.IsAny<int>())).Returns(new Content("Nikes", 1, contentType));
		}
示例#13
0
        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);
        }
示例#14
0
        public ActionResult Install()
        {
            var dataTypeService = ApplicationContext.Current.Services.DataTypeService;
            
            var dataType = dataTypeService.GetDataTypeDefinitionById(Constants.System.DefaultContentListViewDataTypeId);
            var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id);
            var dict = preVals.FormatAsDictionary();
            
            if (!dict.ContainsKey("pageSize")) dict["pageSize"] = new PreValue("10");
            dict["pageSize"].Value = "200";
            dataTypeService.SavePreValues(dataType, dict);

            var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
            
            var contentType = new ContentType(-1)
            {
                Alias = _contentAlias,
                Name = "LoadTest Content",
                Description = "Content for LoadTest",
                Icon = "icon-document"
            };
            var def = ApplicationContext.Current.Services.DataTypeService.GetDataTypeDefinitionById(_textboxDefinitionId);
            contentType.AddPropertyType(new PropertyType(def)
            {
                Name = "Origin",
                Alias = "origin",
                Description = "The origin of the content.",
            });
            contentTypeService.Save(contentType);

            var containerTemplate = ImportTemplate(ApplicationContext.Current.Services,
                "~/Views/LoadTestContainer.cshtml", "LoadTestContainer", "LoadTestContainer", _containerTemplateText);
            
            var containerType = new ContentType(-1)
            {
                Alias = _containerAlias,
                Name = "LoadTest Container",
                Description = "Container for LoadTest content",
                Icon = "icon-document",
                AllowedAsRoot = true,
                IsContainer = true
            };
            containerType.AllowedContentTypes = containerType.AllowedContentTypes.Union(new[]
            {
                new ContentTypeSort(new Lazy<int>(() => contentType.Id), 0, contentType.Alias),
            });
            containerType.AllowedTemplates = containerType.AllowedTemplates.Union(new[] { containerTemplate });
            containerType.SetDefaultTemplate(containerTemplate);
            contentTypeService.Save(containerType);
                        
            var contentService = ApplicationContext.Current.Services.ContentService;
            var content = contentService.CreateContent("LoadTestContainer", -1, _containerAlias);
            contentService.SaveAndPublishWithStatus(content);
            
            return ContentHtml("Installed.");
        }
        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);
        }
        private void SynchronizeDocumentType(Type typeDocType, Type baseTypeDocType)
        {
            // Get DocumentTypeAttribute attribute for typeDocType
            DocumentTypeAttribute docTypeAttr = GetDocumentTypeAttribute(typeDocType);
            string docTypeName = string.IsNullOrEmpty(docTypeAttr.Name) ? typeDocType.Name : docTypeAttr.Name;

            string docTypeAlias = string.Empty;
            if (!String.IsNullOrEmpty(docTypeAttr.Alias))
            {
                docTypeAlias = docTypeAttr.Alias;
            }
            else
            {
                docTypeAlias = typeDocType.Name;
            }

            DocumentTypes.Add(docTypeAlias, typeDocType);

            // If document type is not changed, skip update
            if (DocumentTypesComparisonSummary.Exists(dt => (dt.DocumentTypeStatus == Status.Same) && (dt.Alias == docTypeAlias)))
            {
                return;
            }

            try
            {
                AddToSynchronized(typeDocType.Name, docTypeAlias, typeDocType);
            }
            catch (ArgumentException exc)
            {
                throw new Exception(string.Format("Document type with alias '{0}' already exists! Please use unique class names as class name is used as alias. Document type causing the problem: '{1}' (assembly: '{2}'). Error message: {3}",
                    docTypeAlias, typeDocType.FullName, typeDocType.Assembly.FullName, exc.Message));
            }

            // If parent is some other DT, retrieve parentID; otherwise it's -1
            int parentId = -1;
            if (baseTypeDocType != typeof(DocumentTypeBase))
            {
                parentId = GetDocumentTypeId(baseTypeDocType);
            }

            // Get DT with same alias from Umbraco if exists
            IContentType contentType = ContentTypeService.GetContentType(docTypeAlias);

            if (contentType == null)
            {
                // New DT
                if (parentId != -1)
                {
                    IContentType parentType = ContentTypeService.GetContentType(parentId);
                    contentType = new ContentType(parentType);
                }
                else
                {
                    contentType = new ContentType(parentId);
                }
            }
            else
            {
                // Existing DT
                if (contentType.ParentId != parentId)
                {
                    IContentType newContentType = null;
                    IContentType originalContentType = null;

                    if (parentId != -1)
                    {
                        newContentType = ContentTypeService.GetContentType(parentId);
                    }

                    if (contentType.ParentId != -1)
                    {
                        originalContentType = ContentTypeService.GetContentType(contentType.ParentId);
                    }

                    if (originalContentType != null)
                    {
                        contentType.RemoveContentType(originalContentType.Alias);
                    }

                    if (newContentType != null)
                    {
                        contentType.AddContentType(newContentType);
                    }

                    contentType.ParentId = parentId;
                }
            }

            contentType.Name = docTypeName;
            contentType.Alias = docTypeAlias;
            contentType.Icon = docTypeAttr.IconUrl;
            contentType.Thumbnail = docTypeAttr.Thumbnail;
            contentType.Description = docTypeAttr.Description;
            contentType.AllowedAsRoot = docTypeAttr.AllowAtRoot;

            SetAllowedTemplates(contentType, docTypeAttr, typeDocType);

            SynchronizeDocumentTypeProperties(typeDocType, contentType, docTypeAttr);

            ContentTypeService.Save(contentType);

            // store node id for new document types in dictionary (to avoid unnecessary API calls)
            if (DocumentTypesId.ContainsKey(contentType.Alias) == false)
            {
                DocumentTypesId.Add(contentType.Alias, contentType.Id);
            }
        }
        public static ContentType CreateSimpleContentType(string alias, string name, PropertyTypeCollection collection)
        {
            var contentType = new ContentType(-1)
                                  {
                                      Alias = alias,
                                      Name = name,
                                      Description = "ContentType used for simple text pages",
                                      Icon = ".sprTreeDoc3",
                                      Thumbnail = "doc3.png",
                                      SortOrder = 1,
                                      CreatorId = 0,
                                      Trashed = false
                                  };

            contentType.PropertyGroups.Add(new PropertyGroup(collection) { Name = "Content", SortOrder = 1 });

            return contentType;
        }
示例#18
0
        /// <summary>
        /// Import
        /// </summary>
        /// <param name="content">content</param>
        /// <param name="umbApplication">umb Application</param>
        /// <param name="appContext">app Context</param>
        /// <returns></returns>
        public void Import(Site site, ApplicationContext appContext)
        {
            references.Clear();
            
            var mediaService = appContext.Services.MediaService;
            var cts = appContext.Services.ContentTypeService;
            
            var folderTypeID = cts.GetMediaType(Constants.Conventions.MediaTypes.Folder).Id;
            var folders = mediaService.GetMediaOfMediaType(folderTypeID);
            foreach (var folder in folders)
            {
                if (folder.Name == site.Name)
                {
                    foreach (var media in mediaService.GetChildren(folder.Id))
                    {
                        mediaService.Delete(media);
                    }

                    mediaService.Delete(folder);
                    break;
                }
            }
            
            var serializer = new SiteSerializer();

            //Accents removal
            byte[] tempBytes;
            tempBytes = System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(site.Name.ToLowerInvariant());            
            string siteAlias = System.Text.Encoding.UTF8.GetString(tempBytes);
            siteAlias = siteAlias.Replace(" ", string.Empty);
            //site.Root.Name = site.Name;

            var fileService = appContext.Services.FileService;
                        
            var scriptPath = HostingEnvironment.MapPath("/scripts") + Path.DirectorySeparatorChar;
            var cssPath = HostingEnvironment.MapPath("/css") + Path.DirectorySeparatorChar;
            var resourcePath = site.Name + '/';
            
            var mediaParent = mediaService.CreateMediaWithIdentity(site.Name, -1, Constants.Conventions.MediaTypes.Folder);

            foreach (var resource in site.Resources)
            {
                var filePath = resource.TextData;
                
                if (resource.ResourceType == ResourceType.Javascript)
                {
                    try
                    {
                        var scripts = fileService.GetScripts(resource.TextData.ToLowerInvariant());
                        if (scripts != null && scripts.Any())
                        {
                            foreach (var item in scripts)
                            {
                                fileService.DeleteScript(item.Name);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.StackTrace);
                    }

                    var newPath = scriptPath + Path.GetFileName(filePath);
                    if (!newPath.EndsWith(".js"))
                    {
                        newPath = newPath + ".js";
                    }
                    
                    var script = new Script(filePath);
                    fileService.SaveScript(script);
                    System.IO.File.Copy(filePath, newPath, true);
                    AddToReferences(resource.TemplateReference, newPath, true);
                }
                else if (resource.ResourceType == ResourceType.Stylesheet)
                {
                    try
                    {
                        var stylesheets = fileService.GetStylesheets(resource.TextData.ToLowerInvariant());
                        if (stylesheets != null && stylesheets.Any())
                        {
                            foreach (var item in stylesheets)
                            {
                                fileService.DeleteStylesheet(item.Name);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.StackTrace);
                    }

                    var newPath = cssPath + Path.GetFileName(filePath);
                    if (!newPath.EndsWith(".css"))
                    {
                        newPath = newPath + ".css";
                    }
                    var stylesheet = new Stylesheet(newPath);
                    fileService.SaveStylesheet(stylesheet);
                    System.IO.File.Copy(filePath, newPath, true);
                    AddToReferences(resource.TemplateReference, newPath, true);
                }
                else if (resource.ResourceType == ResourceType.Image)
                {                    
                    var media = mediaService.CreateMedia(resource.FileName, mediaParent.Id, Constants.Conventions.MediaTypes.Image);
                    using (var fs = System.IO.File.OpenRead(filePath))
                    {
                        media.SetValue(Constants.Conventions.Media.File, resource.FileName, fs);
                    }
                    mediaService.Save(media);
                    AddToReferences(resource.TemplateReference, media.GetValue<string>(Constants.Conventions.Media.File));
                }
                else if (resource.ResourceType == ResourceType.File)
                {
                    var media = mediaService.CreateMedia(resource.FileName, mediaParent.Id, Constants.Conventions.MediaTypes.File);
                    using (var fs = System.IO.File.OpenRead(filePath))
                    {
                        media.SetValue(Constants.Conventions.Media.File, resource.FileName, fs);
                    }
                    mediaService.Save(media);
                    AddToReferences(resource.TemplateReference, media.GetValue<string>(Constants.Conventions.Media.File));
                }
            }


            var rootCT = new ContentType(-1);
            rootCT.Name = site.Name;
            rootCT.Alias = siteAlias;

            var oldCT = cts.GetContentType(rootCT.Alias);

            if (oldCT != null)
            {
                foreach (var child in cts.GetContentTypeChildren(oldCT.Id))
                {
                    cts.Delete(child);
                }

                cts.Delete(oldCT);
            }

            cts.Save(rootCT);
            
            var templatePathFormat = HostingEnvironment
                    .MapPath("/Views") + Path.DirectorySeparatorChar + "{0}.cshtml";

            var templates = new Dictionary<Guid, ITemplate>();
            var templateTexts = new Dictionary<Guid, string>();
            foreach (var template in site.Templates.WhereNotNull())
            {
                var templateAlias = siteAlias + template.Name.ToLowerInvariant();
                if (fileService.GetTemplate(templateAlias) != null)
	            {
                    fileService.DeleteTemplate(templateAlias);
	            }

                var templatePath = string.Format(templatePathFormat, templateAlias);
                var templateModel = new Umbraco.Core.Models.Template(templatePath, template.Name, templateAlias);

                fileService.SaveTemplate(templateModel);

                templateTexts.Add(template.ID, template.Text);
                templates.Add(template.ID, templateModel);
            }
                        
            var contentTypes = new Dictionary<Guid, ContentType>();
            foreach (var pageType in site.PageTypes)
            {
                var contentType = new ContentType(rootCT);
                contentType.Name = pageType.Name;
                contentType.Alias = siteAlias + pageType.Name;
                contentType.Icon = "icon-umb-content";

                cts.Save(contentType);

                contentType.AddPropertyGroup(site.Name);
                var propertyGroup = contentType.PropertyGroups[site.Name];

                bool hasTemplate = pageType.TemplateID != Guid.Empty;

                string templateBody = null;
                ITemplate contentTypeTemplate = null; 
                if (hasTemplate)
                {
                    contentTypeTemplate = templates[pageType.TemplateID];
                    templateBody = templateTexts[pageType.TemplateID];   
                }

                foreach (var definition in pageType.Definitions)
                {
                    var def = appContext.Services.DataTypeService
                        .GetDataTypeDefinitionByPropertyEditorAlias(Constants.PropertyEditors.TinyMCEAlias)
                        .First();
                    var pt = new PropertyType(def);
                    pt.Alias = siteAlias + definition.Name;
                    pt.Name = definition.Name;
                    contentType.AddPropertyType(pt, site.Name);
                    if (hasTemplate)
                    {
                        templateBody = templateBody.Replace(definition.TemplateReference, "@Umbraco.Field(\"" + pt.Alias + "\")");   
                    }
                }

                if (hasTemplate)
                {
                    contentTypeTemplate.Content = templateBody;
                    contentType.AllowedTemplates = contentTypeTemplate.AsEnumerableOfOne();
                    contentType.SetDefaultTemplate(contentTypeTemplate);

                    var templatePath = string.Format(templatePathFormat, contentTypeTemplate.Alias);
                    System.IO.File.WriteAllText(templatePath, templateBody, Encoding.UTF8);
                }
                
                cts.Save(contentType);
                contentTypes.Add(pageType.ID, contentType);
            }

            IContent root = null;
            var cs = appContext.Services.ContentService;
            var pages = new Dictionary<Guid, IContent>();
            var pageReferences = new Dictionary<string, IContent>();
            foreach (var page in site.Root.GetDescendantsAndSelf())
            {
                if(page.Name == null)
                {
                    page.Name = "unknown";
                }
                var parentID = page.ParentID == Guid.Empty ? -1 : pages[page.ParentID].Id;
                var cnt = cs.CreateContent(page.Name, parentID, contentTypes[page.PageTypeID].Alias);
                pages.Add(page.ID, cnt);
                foreach (var prop in page.Properties)
                {
                    //Accents removal
                    tempBytes = System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(prop.Name);
                    string propName = System.Text.Encoding.UTF8.GetString(tempBytes);
                    propName = propName.Replace(" ", string.Empty);
                    cnt.Properties[siteAlias + propName].Value = prop.Value;
                }
                cs.Save(cnt);
                if (page.ParentID == Guid.Empty)
	            {
		            root = cnt;
	            }
                if (!string.IsNullOrWhiteSpace(page.TemplateReference))
                {
                    pageReferences.Add(page.TemplateReference, cnt);   
                }
            }

            var pageRegex = new Regex(@"(@Raw\(Model\.Page\d+\))", RegexOptions.Compiled | RegexOptions.Multiline);
            var resourceRegex = new Regex(@"(@Raw\(Model\.Resource\d+\))", RegexOptions.Compiled | RegexOptions.Multiline);
            foreach (var page in root.Descendants().Where(c => c.Template != null))
	        {
		        foreach (var property in page.Properties)
	            {
                    var value = property.Value != null ? property.Value.ToString() : "";
                    value = pageRegex.Replace(value, m => "/{localLink:" + pageReferences[m.Value].Id + "}");
                    property.Value = resourceRegex.Replace(value, m => references[m.Value]);
	            }
                cs.Save(page);
	        }
            cs.PublishWithChildrenWithStatus(root, includeUnpublished: true);
            foreach (var template in templates.Values)
            {
                var sb = new StringBuilder();
                var templatePath = string.Format(templatePathFormat, template.Alias);
                var newContent = pageRegex.Replace(template.Content, m => string.Format("@Umbraco.NiceUrl({0})", pageReferences[m.Value].Id));
                newContent = resourceRegex.Replace(newContent, m => references[m.Value]);
                System.IO.File.WriteAllText(templatePath, templatePrefix + newContent, Encoding.UTF8);
            }
        }
		private void InitializeInheritedContentTypes()
		{
			ctx = GetUmbracoContext("/", 1, null, true);
			if (createContentTypes)
			{
				var contentTypeService = ctx.Application.Services.ContentTypeService;
				var baseType = new ContentType(-1) {Alias = "base", Name = "Base"};
				var inheritedType = new ContentType(baseType) {Alias = "inherited", Name = "Inherited"};
				contentTypeService.Save(baseType);
				contentTypeService.Save(inheritedType);
				createContentTypes = false;
			}
			#region setup xml content
			xmlContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
<!DOCTYPE root[ 
<!ELEMENT inherited ANY>
<!ATTLIST inherited id ID #REQUIRED>
]>
<root id=""-1"">
	<inherited id=""1100"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1"" sortOrder=""1"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc=""""/>
</root>";
			#endregion
		}
        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 static SimpleContentType FromContentType(int contentTypeId, bool recurse = true) {
			if (contentTypeId <= 0) return null;

			var dt = new ContentType(contentTypeId);
			return FromContentType(dt, recurse);
		}
        public static ContentType CreateAllTypesContentType(string alias, string name)
        {
            var contentType = new ContentType(-1)
                              {
                                  Alias = alias,
                                  Name = name,
                                  Description = "ContentType containing all standard DataTypes",
                                  Icon = ".sprTreeDoc3",
                                  Thumbnail = "doc.png",
                                  SortOrder = 1,
                                  CreatorId = 0,
                                  Trashed = false
                              };

            var contentCollection = new PropertyTypeCollection();
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.TrueFalse), DataTypeDatabaseType.Integer) { Alias = "isTrue", Name = "Is True or False", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -49 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.Integer), DataTypeDatabaseType.Integer) { Alias = "number", Name = "Number", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -51 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.TinyMCEv3), DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Mandatory = false, SortOrder = 3, DataTypeDefinitionId = -87 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.Textbox), DataTypeDatabaseType.Nvarchar) { Alias = "singleLineText", Name = "Text String", Mandatory = false, SortOrder = 4, DataTypeDefinitionId = -88 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.TextboxMultiple), DataTypeDatabaseType.Ntext) { Alias = "multilineText", Name = "Multiple Text Strings", Mandatory = false, SortOrder = 5, DataTypeDefinitionId = -89 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.UploadField), DataTypeDatabaseType.Nvarchar) { Alias = "upload", Name = "Upload Field", Mandatory = false, SortOrder = 6, DataTypeDefinitionId = -90 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.NoEdit), DataTypeDatabaseType.Nvarchar) { Alias = "label", Name = "Label", Mandatory = false, SortOrder = 7, DataTypeDefinitionId = -92 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.DateTime), DataTypeDatabaseType.Date) { Alias = "dateTime", Name = "Date Time", Mandatory = false, SortOrder = 8, DataTypeDefinitionId = -36 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.ColorPicker), DataTypeDatabaseType.Nvarchar) { Alias = "colorPicker", Name = "Color Picker", Mandatory = false, SortOrder = 9, DataTypeDefinitionId = -37 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.FolderBrowser), DataTypeDatabaseType.Nvarchar) { Alias = "folderBrowser", Name = "Folder Browser", Mandatory = false, SortOrder = 10, DataTypeDefinitionId = -38 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.DropDownListMultiple), DataTypeDatabaseType.Nvarchar) { Alias = "ddlMultiple", Name = "Dropdown List Multiple", Mandatory = false, SortOrder = 11, DataTypeDefinitionId = -39 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.RadioButtonList), DataTypeDatabaseType.Nvarchar) { Alias = "rbList", Name = "Radio Button List", Mandatory = false, SortOrder = 12, DataTypeDefinitionId = -40 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.Date), DataTypeDatabaseType.Date) { Alias = "date", Name = "Date", Mandatory = false, SortOrder = 13, DataTypeDefinitionId = -41 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.DropDownList), DataTypeDatabaseType.Integer) { Alias = "ddl", Name = "Dropdown List", Mandatory = false, SortOrder = 14, DataTypeDefinitionId = -42 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.CheckBoxList), DataTypeDatabaseType.Nvarchar) { Alias = "chklist", Name = "Checkbox List", Mandatory = false, SortOrder = 15, DataTypeDefinitionId = -43 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.ContentPicker), DataTypeDatabaseType.Integer) { Alias = "contentPicker", Name = "Content Picker", Mandatory = false, SortOrder = 16, DataTypeDefinitionId = 1034 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.MediaPicker), DataTypeDatabaseType.Integer) { Alias = "mediaPicker", Name = "Media Picker", Mandatory = false, SortOrder = 17, DataTypeDefinitionId = 1035 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.MemberPicker), DataTypeDatabaseType.Integer) { Alias = "memberPicker", Name = "Member Picker", Mandatory = false, SortOrder = 18, DataTypeDefinitionId = 1036 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.UltraSimpleEditor), DataTypeDatabaseType.Ntext) { Alias = "simpleEditor", Name = "Ultra Simple Editor", Mandatory = false, SortOrder = 19, DataTypeDefinitionId = 1038 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.UltimatePicker), DataTypeDatabaseType.Ntext) { Alias = "ultimatePicker", Name = "Ultimate Picker", Mandatory = false, SortOrder = 20, DataTypeDefinitionId = 1039 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.RelatedLinks), DataTypeDatabaseType.Ntext) { Alias = "relatedLinks", Name = "Related Links", Mandatory = false, SortOrder = 21, DataTypeDefinitionId = 1040 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.Tags), DataTypeDatabaseType.Ntext) { Alias = "tags", Name = "Tags", Mandatory = false, SortOrder = 22, DataTypeDefinitionId = 1041 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.MacroContainer), DataTypeDatabaseType.Ntext) { Alias = "macroContainer", Name = "Macro Container", Mandatory = false, SortOrder = 23, DataTypeDefinitionId = 1042 });
            contentCollection.Add(new PropertyType(new Guid(Constants.PropertyEditors.ImageCropper), DataTypeDatabaseType.Ntext) { Alias = "imgCropper", Name = "Image Cropper", Mandatory = false, SortOrder = 24, DataTypeDefinitionId = 1043 });

            contentType.PropertyGroups.Add(new PropertyGroup(contentCollection) { Name = "Content", SortOrder = 1 });

            return contentType;
        }
示例#23
0
 private void SetupMediaForTree(Guid uniqueId, int level, int parentId, int user, string path,
                                   string text, DateTime createDate, string icon, bool hasChildren, string contentTypeAlias, string contentTypeThumb,
                                     string contentTypeDesc, int? masterContentType, int contentTypeId, bool isContainer)
 {
     SetupNodeForTree(uniqueId, _objectType, level, parentId, user, path, text, createDate, hasChildren);
     ContentType = new ContentType(contentTypeId, contentTypeAlias, icon, contentTypeThumb, masterContentType, isContainer);
     ContentTypeIcon = icon;
 }
        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);
        }
示例#25
0
        private void SetupDocumentForTree(Guid uniqueId, int level, int parentId, int creator, int writer, bool publish, string path,
                                         string text, DateTime createDate, DateTime updateDate,
                                         DateTime versionDate, string icon, bool hasChildren, string contentTypeAlias, string contentTypeThumb,
                                           string contentTypeDesc, int? masterContentType, int contentTypeId, int templateId, bool isContainer)
        {
            SetupNodeForTree(uniqueId, _objectType, level, parentId, creator, path, text, createDate, hasChildren);

            _writerId = writer;
            _published = publish;
            _updated = updateDate;
            _template = templateId;
            ContentType = new ContentType(contentTypeId, contentTypeAlias, icon, contentTypeThumb, null, isContainer);
            ContentTypeIcon = icon;
            VersionDate = versionDate;
        }
        /// <summary>
        /// Convention that converts a class decorated with the ContentTypeAttribute to an initial ContentType
        /// </summary>
        /// <param name="attribute"><see cref="ContentTypeAttribute"/> to use for mapping a <see cref="IContentType"/></param>
        /// <param name="modelType">Type of the current class</param>
        /// <param name="existing"> </param>
        /// <returns>A Lazy <see cref="IContentType"/></returns>
        private static Lazy<IContentType> ContentTypeConvention(ContentTypeAttribute attribute, Type modelType, IContentType existing)
        {
            var children = attribute.AllowedChildContentTypes == null
                               ? new List<ContentTypeSort>()
                               : AllowedChildContentTypesConvention(
                                   attribute.AllowedChildContentTypes, modelType);
            
            var templates = attribute.AllowedTemplates == null
                                ? new List<ITemplate>()
                                : AllowedTemplatesConvention(attribute.AllowedTemplates);

            if(existing != null)
            {
                if (children.Any())
                    existing.AllowedContentTypes = children;
                
                if (templates.Any())
                    existing.AllowedTemplates = templates;

                return new Lazy<IContentType>(() => existing);
            }

            var contentType = new ContentType(-1)
                                  {
                                      Alias = attribute.Alias,
                                      Description = attribute.Description,
                                      Icon = attribute.IconUrl,
                                      Thumbnail = attribute.Thumbnail,
                                      Name = string.IsNullOrEmpty(attribute.Name)
                                                 ? modelType.Name.SplitPascalCasing()
                                                 : attribute.Name,
                                      AllowedContentTypes = children,
                                      AllowedTemplates = templates
                                  };

            return new Lazy<IContentType>(() => contentType);
        }
        public static ContentType CreateSimpleContentType(string alias, string name, bool mandatory)
        {
            var contentType = new ContentType(-1)
            {
                Alias = alias,
                Name = name,
                Description = "ContentType used for simple text pages",
                Icon = ".sprTreeDoc3",
                Thumbnail = "doc2.png",
                SortOrder = 1,
                CreatorId = 0,
                Trashed = false
            };

            var contentCollection = new PropertyTypeCollection();
            contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "title", Name = "Title", Description = "", HelpText = "", Mandatory = mandatory, SortOrder = 1, DataTypeDefinitionId = -88 });
            contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Description = "", HelpText = "", Mandatory = mandatory, SortOrder = 2, DataTypeDefinitionId = -87 });
            contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "author", Name = "Author", Description = "Name of the author", HelpText = "", Mandatory = mandatory, SortOrder = 3, DataTypeDefinitionId = -88 });

            contentType.PropertyGroups.Add(new PropertyGroup(contentCollection) { Name = "Content", SortOrder = 1 });

            return contentType;
        }
        /// <summary>
        /// Convention that converts a simple POCO to an initial ContentType
        /// </summary>
        /// <param name="modelType">Type of the object to map to a <see cref="IContentType"/></param>
        /// <param name="existing"> </param>
        /// <returns>A Lazy <see cref="IContentType"/></returns>
        private static Lazy<IContentType> PlainPocoConvention(Type modelType, IContentType existing)
        {
            if(existing != null)
                return new Lazy<IContentType>(() => existing);

            var contentType = new ContentType(-1)
                                  {
                                      Alias = modelType.Name.ToUmbracoAlias(),
                                      Description = string.Empty,
                                      Icon = "folder.gif",
                                      Thumbnail = "folder.png",
                                      Name = modelType.Name.SplitPascalCasing(),
                                      AllowedTemplates = new List<ITemplate>(),
                                      AllowedContentTypes = new List<ContentTypeSort>()
                                  };

            return new Lazy<IContentType>(() => 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 = "TestProperty";
            contentType.AddPropertyType(propertyType);
            contentTypeService.Save(contentType);
            Assert.Greater(contentType.Id, 0);

            var content = new Content(name, -1, contentType);
            content.Key = new Guid("{5F6D851E-46C0-40C7-A93A-EC3F6D7EBA3E}");
            content.SetPropertyValue("TestProperty", fieldValue);
            _contentService.Save(content);
        }
示例#31
0
        public static DocumentType MakeNew(User u, string Text)
        {
            var contentType = new Umbraco.Core.Models.ContentType(-1) { Name = Text, Alias = Text, CreatorId = u.Id, Thumbnail = "folder.png", Icon = "folder.gif" };
            ApplicationContext.Current.Services.ContentTypeService.Save(contentType, u.Id);
            var newDt = new DocumentType(contentType);

            //event
            NewEventArgs e = new NewEventArgs();
            newDt.OnNew(e);

            return newDt;
        }
        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);
        }