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); } }
//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; }
//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; }
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; }
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; }
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(); } }
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(); } }