Example #1
0
        private int createFolderScructure(DateTime dt, DynamicNode stream)
        {
            var names = new string[] {dt.Year.ToString(), dt.Month.ToString(), dt.Day.ToString()};

            var cs = new ContentService();
            var current = stream;
            var lookUp = true;

            foreach (var name in names)
            {
                if (lookUp)
                {

                    var exists = current.Children.Where(x => x.Name == name).FirstOrDefault();
                    if (exists == null)
                    {
                        lookUp = false;
                        var node = cs.CreateContent(name, current.Id, "Folder");
                        cs.SaveAndPublish(node);

                        Thread.Sleep(2000);
                        current = current.Children.Where(x => x.Name == name).FirstOrDefault();
                    }
                }
                else
                {
                    var node = cs.CreateContent(name, current.Id, "Folder");
                    cs.SaveAndPublish(node);
                    current = current.Children.Where(x => x.Name == name).FirstOrDefault();
                }
            }

            return current.Id;
        }
Example #2
0
        private void CreateAndPublish(Post p)
        {
            var stream = getStream();

            if (stream != null)
            {
                var cs = new ContentService();
                int postId;
                IContent post;

                if (TryGetPostId(p, out postId))
                    post = cs.GetById(postId);
                else
                {
                    var parent = createFolderScructure(p.Date, stream);
                    post = cs.CreateContent(p.Name, parent, PostTypeAlias);
                }

                MarkdownSharp.Markdown md = new Markdown();
                post.SetValue("bodyText", md.Transform(p.Content));

               post.SetValue("postDate", p.Date);

                if (p.Draft)
                    cs.Save(post);
                else
                    cs.SaveAndPublish(post);
            }
        }
        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);
        }
Example #4
0
 //Updates a Match document
 public Match Put(Match match)
 {
     var cs = new ContentService();
     var content = cs.GetById(match.Id);
     content.Name = match.Name;
     cs.SaveAndPublish(content);
     return match;
 }
Example #5
0
 //Creates a new Match document under the specified parent
 public Match Post(Match match, int parentId)
 {
     var cs = new ContentService();
     var content = cs.CreateContent(match.Name, parentId, "Match");
     content.Name = match.Name;
     cs.SaveAndPublish(content);
     match.Id = content.Id;
     return match;
 }
Example #6
0
 public void Delete(Post p)
 {
     int id;
     if (TryGetPostId(p, out id))
     {
         var cs = new ContentService();
         var post = cs.GetById(id);
         cs.UnPublish(post);
         cs.Delete(post);
     }
 }
        public void MapToProperty_ConfigurationSetupCorrectly_CallsCreateClassOnService()
        {
            //Assign
            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content = contentService.GetById(new Guid("{C382AE57-D325-4357-A32A-0A959BBD4101}"));
            var service = Substitute.For<IUmbracoService>();
            service.ContentService.Returns(contentService);
            var context = new UmbracoDataMappingContext(null, content, service);

            var config = new UmbracoParentConfiguration();
            config.PropertyInfo = typeof(Stub).GetProperty("Property");

            var mapper = new UmbracoParentMapper();
            mapper.Setup(new DataMapperResolverArgs(null, config));

            //Act
            mapper.MapToProperty(context);

            //Assert
            //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails.
            service.Received().CreateType(config.PropertyInfo.PropertyType, Arg.Is<IContent>(x => x.Id == content.ParentId), false, false);
        }
Example #8
0
        private int Plant(int rootDocId)
        {
            var contentService = new ContentService();
            var rootDoc = contentService.GetById(rootDocId);

            if (rootDoc.Level <= _maxDepth)
            {
                var allowedContentTypes = rootDoc.ContentType.AllowedContentTypes.ToArray();

                if (!allowedContentTypes.Any())
                    return 0;

                foreach (var docType in allowedContentTypes)
                {
                    for (int i = 0; i < _numberOfEachDocTypeToCreate; i++)
                    {
                        var newContent = contentService.CreateContent("Forrester Created Content", rootDoc, docType.Alias, User.Id);
                        SetDynamicNodeName(newContent);

                        if (_publish)
                        {
                            contentService.SaveAndPublish(newContent);
                        }
                        else
                        {
                            contentService.Save(newContent);
                        }

                        _nodesCreated++;
                        Plant(newContent.Id);
                    }
                }
            }

            return _nodesCreated;
        }
        public void MapToProperty_UmbracoInfoType_GetsExpectedValueFromUmbraco(
            [Values(
                //UmbracoInfoType.Url,
                UmbracoInfoType.ContentTypeAlias,
                UmbracoInfoType.ContentTypeName,
                UmbracoInfoType.Name,
                UmbracoInfoType.Creator
                )] UmbracoInfoType type,
            [Values(
                //"target", //Url
                "TestType", //ContentTypeAlias
                "Test Type", //ContentTypeName
                "Target", //Name
                "admin" //Creator
                )] object expected
            )
        {
            //Assign
            var mapper = new UmbracoInfoMapper();
            var config = new UmbracoInfoConfiguration();
            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");
            var dataContext = new UmbracoDataMappingContext(null, content, null);

            //Act
            var value = mapper.MapToProperty(dataContext);
            Console.WriteLine(type);

            //Assert
            Assert.AreEqual(expected, value);
        }
        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);
            });

            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);
        }
Example #11
0
 //Deletes a Match document
 public void Delete(int matchId)
 {
     var cs = new ContentService();
     var content = cs.GetById(matchId);
     cs.Delete(content);
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Find Pages (homepage, etc)

        if (!Page.IsPostBack)
        {

            Umbraco.Core.Services.ContentService contentService = new Umbraco.Core.Services.ContentService();
            Umbraco.Core.Services.FileService fileService = new Umbraco.Core.Services.FileService();

            var root = contentService.GetRootContent().Where(x => x.Name == "Home").FirstOrDefault();

            //Document root = Document.GetRootDocuments().Where(x => x.Text == "Home").FirstOrDefault();

            // Add Public Permissions
            int clientAreaId = -1;
            int loginPageId = -1;
            int errorPageId = -1;
            int contentPanelsId = -1;
            int slideShowId = -1;

            root.SetValue("primaryNavigation", root.Id + "");
            root.SetValue("headerNavigation", "");
            root.SetValue("slideshow", "");

            foreach (var doc in contentService.GetChildren(root.Id))
            {
                // Update Navigation
                if (doc.Name == "Home" ||
                    doc.Name == "About" ||
                    doc.Name == "Products" ||
                    doc.Name == "News" ||
                    doc.Name == "Clients" ||
                    doc.Name == "Contact Us")
                {
                    if (root.GetValue<string>("primaryNavigation") == null ||
                        root.GetValue<string>("primaryNavigation").Length == 0)
                    {
                        root.SetValue("primaryNavigation", doc.Id + "");
                    }
                    else
                    {
                        root.SetValue("primaryNavigation", root.GetValue<string>("primaryNavigation") + "," + doc.Id);
                    }

                }

                if (doc.Name == "Sitemap" ||
                   doc.Name == "Client Area")
                {
                    if (root.GetValue<string>("headerNavigation") == null ||
                        root.GetValue<string>("headerNavigation").Length == 0)
                    {
                        root.SetValue("headerNavigation", doc.Id + "");
                    }
                    else
                    {
                        root.SetValue("headerNavigation", root.GetValue<string>("headerNavigation") + "," + doc.Id);
                    }

                }

                if (doc.Name == "Slideshow")
                {
                    foreach (var slide in contentService.GetChildren(doc.Id))
                    {
                        if (root.GetValue<string>("slideshow") == null ||
                            root.GetValue<string>("slideshow").Length == 0)
                        {
                            root.SetValue("slideshow", slide.Id + "");
                        }
                        else
                        {
                            root.SetValue("slideshow", root.GetValue<string>("slideshow") + "," + slide.Id);
                        }
                    }
                }

                // Fix templates
                if (doc.Name == "Search")
                {
                    doc.Template = fileService.GetTemplate("Search");
                    contentService.Save(doc);
                }

                if (doc.Name == "News")
                {
                    doc.Template = fileService.GetTemplate("Articles");
                    contentService.Save(doc);
                }

                if (doc.Name == "Sitemap")
                {
                    doc.Template = fileService.GetTemplate("Sitemap");
                    contentService.Save(doc);
                }

                if (doc.Name == "Login")
                {
                    doc.Template = fileService.GetTemplate("Login");
                    contentService.Save(doc);
                }

                // Store values for updating Ultimate picker
                if (doc.Name == "Client Area")
                {
                    clientAreaId = doc.Id;
                }
                else if (doc.Name == "Login")
                {
                    loginPageId = doc.Id;
                }
                else if (doc.Name == "Insufficent Access")
                {
                    errorPageId = doc.Id;
                }
                else if (doc.Name == "Content Panels")
                {
                    contentPanelsId = doc.Id;
                }
                else if (doc.Name == "Slideshow")
                {
                    slideShowId = doc.Id;
                }

            }

            // Republish all nodes
            contentService.SaveAndPublish(root);
            contentService.PublishWithChildren(root);
            //root.PublishWithChildrenWithResult(new User(0));

            umbraco.library.RefreshContent();

            // Move favicon
            try
            {
                File.Move(Server.MapPath("~/images").TrimEnd('\\') + "\\favicon.ico", Server.MapPath("~/").TrimEnd('\\') + "\\favicon.ico");
            }
            catch (Exception ex)
            {
            }

            // Setup Client area
            SetupClientArea(clientAreaId, loginPageId, errorPageId);

            // Reindex Examine
            ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].RebuildIndex();
        }
    }
Example #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);
        }
        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()
        {
            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 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 MapToProperty_UmbracoInfoTypeUpdateDate_ReturnsUpdateDateAsDateTime()
        {
            //Assign
            var type = UmbracoInfoType.UpdateDate;

            var mapper = new UmbracoInfoMapper();
            var config = new UmbracoInfoConfiguration();
            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));
            var expected = content.UpdateDate;

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");
            var dataContext = new UmbracoDataMappingContext(null, content, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            Assert.AreEqual(expected, value);
        }
        public void MapToProperty_UmbracoInfoTypeNotSet_ThrowsException()
        {
            //Assign
            UmbracoInfoType type = UmbracoInfoType.NotSet;

            var mapper = new UmbracoInfoMapper();
            var config = new UmbracoInfoConfiguration();
            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");
            var dataContext = new UmbracoDataMappingContext(null, content, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            //No asserts expect exception
        }
        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);
        }
Example #20
0
 private void Commentable_saved(IContentService sender, SaveEventArgs<IContent> e)
 {
     foreach (IContent node in e.SavedEntities)
       {
     if (node.ContentType.AllowedContentTypes.Where(x => x.Alias == "Commenttree").Any() &&
     !node.Children().Where(x => x.ContentType.Alias == "Commenttree").Any())
     {
       IContentService cs = new ContentService();
       IContent comment_tree = cs.CreateContent("comments", node, "Commenttree");
       cs.Save(comment_tree);
     }
       }
 }
        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 MapToCms_SavingName_UpdatesTheItemName()
        {
            //Assign
            var type = UmbracoInfoType.Name;
            var expected = "new name";

            var mapper = new UmbracoInfoMapper();
            var config = new UmbracoInfoConfiguration();
            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));
            var oldName = content.Name;

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");

            var context = Context.Create(DependencyResolver.CreateStandardResolver());
            var dataContext = new UmbracoDataMappingContext(null, content, new UmbracoService(contentService, context));
            dataContext.PropertyValue = expected;

            string actual = string.Empty;

            //Act
            mapper.MapToCms(dataContext);
            content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));
            actual = content.Name;

            //Assert
            Assert.AreEqual(expected, actual);
            
            content.Name = oldName;
            contentService.Save(content);
        }
Example #23
0
 private void Commentable_published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
 {
     foreach (IContent node in e.PublishedEntities)
       {
     if (node.ContentType.AllowedContentTypes.Where(x => x.Alias == "Commenttree").Any())
     {
       IContentService cs = new ContentService();
       IContent comment_tree = node.Children().Where(x => x.ContentType.Alias == "Commenttree").First();
       if (comment_tree != null)
     cs.SaveAndPublishWithStatus(comment_tree);
     }
       }
 }
        public int CreateOrderItemInDbFromMailQueueModel(MailQueueModel model, bool doReindex = true, bool doSignal = true)
        {
            IContentService cs = new Umbraco.Core.Services.ContentService();

            // Temporary OrderId with MD5 Hash
            var orderId     = "cthb-" + Helpers.CalculateMD5Hash(DateTime.Now.Ticks.ToString());
            var contentName = orderId;

            // Create the OrderItem
            var      uh      = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
            IContent content = cs.CreateContent(contentName, uh.TypedContentAtXPath("//" + ConfigurationManager.AppSettings["umbracoOrderListContentDocumentType"]).First().Id, "ChalmersILLOrderItem");

            // Set properties
            var originalOrder = UrlDecodeAndEscapeAllLinks(model.OriginalOrder);

            content.SetValue("originalOrder", originalOrder);
            content.SetValue("reference", originalOrder);
            content.SetValue("patronName", model.PatronName);
            content.SetValue("patronEmail", model.PatronEmail);
            content.SetValue("patronCardNo", model.PatronCardNo);
            content.SetValue("followUpDate", DateTime.Now);
            content.SetValue("editedBy", "");
            content.SetValue("status", _umbraco.DataTypePrevalueId(ConfigurationManager.AppSettings["umbracoOrderStatusDataTypeDefinitionName"], "01:Ny"));
            content.SetValue("pType", model.SierraPatronInfo.ptype);
            content.SetValue("homeLibrary", model.SierraPatronInfo.home_library);
            content.SetValue("log", JsonConvert.SerializeObject(new List <LogItem>()));
            content.SetValue("attachments", JsonConvert.SerializeObject(new List <OrderAttachment>()));
            content.SetValue("sierraInfo", JsonConvert.SerializeObject(model.SierraPatronInfo));
            content.SetValue("sierraPatronRecordId", model.SierraPatronInfo.record_id);
            content.SetValue("dueDate", DateTime.Now);
            content.SetValue("providerDueDate", DateTime.Now);
            content.SetValue("deliveryDate", new DateTime(1970, 1, 1));
            content.SetValue("bookId", "");
            content.SetValue("providerInformation", "");
            content.SetValue("readOnlyAtLibrary", "0");

            if (!String.IsNullOrEmpty(model.SierraPatronInfo.home_library))
            {
                if (model.SierraPatronInfo.home_library.ToLower() == "hbib")
                {
                    content.SetValue("deliveryLibrary", _umbraco.DataTypePrevalueId(ConfigurationManager.AppSettings["umbracoOrderDeliveryLibraryDataTypeDefinitionName"], "Huvudbiblioteket"));
                }
                else if (model.SierraPatronInfo.home_library.ToLower() == "abib")
                {
                    content.SetValue("deliveryLibrary", _umbraco.DataTypePrevalueId(ConfigurationManager.AppSettings["umbracoOrderDeliveryLibraryDataTypeDefinitionName"], "Arkitekturbiblioteket"));
                }
                else if (model.SierraPatronInfo.home_library.ToLower() == "lbib")
                {
                    content.SetValue("deliveryLibrary", _umbraco.DataTypePrevalueId(ConfigurationManager.AppSettings["umbracoOrderDeliveryLibraryDataTypeDefinitionName"], "Lindholmenbiblioteket"));
                }
                else
                {
                    content.SetValue("deliveryLibrary", "");
                }
            }

            // Set Type directly if "IsPurchaseRequest" is true
            if (model.IsPurchaseRequest)
            {
                content.SetValue("type", _umbraco.DataTypePrevalueId(ConfigurationManager.AppSettings["umbracoOrderTypeDataTypeDefinitionName"], "Inköpsförslag"));
            }

            // Save the OrderItem to get an Id
            SaveWithoutEventsAndWithSynchronousReindexing(content, false, false);

            // Shorten the OrderId and include the NodeId
            content.SetValue("orderId", orderId.Substring(0, 13) + "-" + content.Id.ToString());
            content.Name = orderId.Substring(0, 13) + "-" + content.Id.ToString();

            // Save
            SaveWithoutEventsAndWithSynchronousReindexing(content, doReindex, doSignal);

            return(content.Id);
        }
Example #25
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Find Pages (homepage, etc)

        if (!Page.IsPostBack)
        {
            Umbraco.Core.Services.ContentService contentService = new Umbraco.Core.Services.ContentService();
            Umbraco.Core.Services.FileService    fileService    = new Umbraco.Core.Services.FileService();

            var root = contentService.GetRootContent().Where(x => x.Name == "Home").FirstOrDefault();

            //Document root = Document.GetRootDocuments().Where(x => x.Text == "Home").FirstOrDefault();

            // Add Public Permissions
            int clientAreaId    = -1;
            int loginPageId     = -1;
            int errorPageId     = -1;
            int contentPanelsId = -1;
            int slideShowId     = -1;

            root.SetValue("primaryNavigation", root.Id + "");
            root.SetValue("headerNavigation", "");
            root.SetValue("slideshow", "");

            foreach (var doc in contentService.GetChildren(root.Id))
            {
                // Update Navigation
                if (doc.Name == "Home" ||
                    doc.Name == "About" ||
                    doc.Name == "Products" ||
                    doc.Name == "News" ||
                    doc.Name == "Clients" ||
                    doc.Name == "Contact Us")
                {
                    if (root.GetValue <string>("primaryNavigation") == null ||
                        root.GetValue <string>("primaryNavigation").Length == 0)
                    {
                        root.SetValue("primaryNavigation", doc.Id + "");
                    }
                    else
                    {
                        root.SetValue("primaryNavigation", root.GetValue <string>("primaryNavigation") + "," + doc.Id);
                    }
                }

                if (doc.Name == "Sitemap" ||
                    doc.Name == "Client Area")
                {
                    if (root.GetValue <string>("headerNavigation") == null ||
                        root.GetValue <string>("headerNavigation").Length == 0)
                    {
                        root.SetValue("headerNavigation", doc.Id + "");
                    }
                    else
                    {
                        root.SetValue("headerNavigation", root.GetValue <string>("headerNavigation") + "," + doc.Id);
                    }
                }

                if (doc.Name == "Slideshow")
                {
                    foreach (var slide in contentService.GetChildren(doc.Id))
                    {
                        if (root.GetValue <string>("slideshow") == null ||
                            root.GetValue <string>("slideshow").Length == 0)
                        {
                            root.SetValue("slideshow", slide.Id + "");
                        }
                        else
                        {
                            root.SetValue("slideshow", root.GetValue <string>("slideshow") + "," + slide.Id);
                        }
                    }
                }

                // Fix templates
                if (doc.Name == "Search")
                {
                    doc.Template = fileService.GetTemplate("Search");
                    contentService.Save(doc);
                }

                if (doc.Name == "News")
                {
                    doc.Template = fileService.GetTemplate("Articles");
                    contentService.Save(doc);
                }

                if (doc.Name == "Sitemap")
                {
                    doc.Template = fileService.GetTemplate("Sitemap");
                    contentService.Save(doc);
                }

                if (doc.Name == "Login")
                {
                    doc.Template = fileService.GetTemplate("Login");
                    contentService.Save(doc);
                }


                // Store values for updating Ultimate picker
                if (doc.Name == "Client Area")
                {
                    clientAreaId = doc.Id;
                }
                else if (doc.Name == "Login")
                {
                    loginPageId = doc.Id;
                }
                else if (doc.Name == "Insufficent Access")
                {
                    errorPageId = doc.Id;
                }
                else if (doc.Name == "Content Panels")
                {
                    contentPanelsId = doc.Id;
                }
                else if (doc.Name == "Slideshow")
                {
                    slideShowId = doc.Id;
                }
            }

            // Republish all nodes
            contentService.SaveAndPublish(root);
            contentService.PublishWithChildren(root);
            //root.PublishWithChildrenWithResult(new User(0));

            umbraco.library.RefreshContent();


            // Move favicon
            try
            {
                File.Move(Server.MapPath("~/images").TrimEnd('\\') + "\\favicon.ico", Server.MapPath("~/").TrimEnd('\\') + "\\favicon.ico");
            }
            catch (Exception ex)
            {
            }

            // Setup Client area
            SetupClientArea(clientAreaId, loginPageId, errorPageId);

            // Reindex Examine
            ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].RebuildIndex();
        }
    }
        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);
        }