public static Content CreateTemplated(Node parent, Node template, string nameBase) { if (parent == null) { throw new ArgumentNullException("parent"); } if (template == null) { throw new ArgumentNullException("template"); } //if (nameBase == null) throw new ArgumentNullException("nameBase"); using (var traceOperation = Logger.TraceOperation("Content.CreateTemplated")) { var name = ContentNamingHelper.GetNewName(nameBase, ((GenericContent)template).GetContentType(), parent); var content = Content.Create(ContentTemplate.CreateFromTemplate(parent, template, name)); var realUser = (User)User.LoggedInUser; var now = DateTime.UtcNow; var node = content.ContentHandler; node.CreatedBy = realUser; node.VersionCreatedBy = realUser; node.NodeOperation = NodeOperation.TemplateCreation; traceOperation.IsSuccessful = true; return(content); } }
/// <summary> /// Creates a template under the specified path using the given template. /// </summary> /// <param name="parentPath">Target location where the templates are copied to.</param> /// <param name="templatePath">The template is to be copied.</param> /// <returns></returns> public static Content CreateTemplated(string parentPath, string templatePath) { if (parentPath == null) { throw new ArgumentNullException("parentPath"); } if (templatePath == null) { throw new ArgumentNullException("templatePath"); } var parentNode = Node.LoadNode(parentPath); if (parentNode == null) { throw new InvalidOperationException(String.Format("Couldn't create a content from a template. ParentNode couldn't be loaded from {0} path.", parentPath)); } var templateNode = Node.LoadNode(templatePath); if (templateNode == null) { throw new InvalidOperationException(String.Format("Couldn't create a content from a template. TemplateNode couldn't be loaded from {0} path.", templatePath)); } return(ContentTemplate.CreateTemplated(parentNode, templateNode, null)); }
/// <summary> /// Creates a template with the specified parameter based upon the contenttypename and /// </summary> /// <param name="contentTypeName">Specifies a CTD name.</param> /// <param name="templateName">Specified a template name for the CTD.</param> /// <param name="targetPath">Specifies a path of the target location where the template is copied to.</param> /// <returns></returns> public static Content CreateTemplated(string contentTypeName, string templateName, string targetPath) { if (String.IsNullOrEmpty(contentTypeName)) { throw new ArgumentException("contentTypeName"); } if (String.IsNullOrEmpty(templateName)) { throw new ArgumentException("templateName"); } if (String.IsNullOrEmpty(targetPath)) { throw new ArgumentException("targetPath"); } var targetNode = Node.LoadNode(targetPath); if (targetNode == null) { throw new InvalidOperationException(String.Format("{0} node couldn't be loaded.", targetPath)); } var templatesForContentType = GetTemplatesForType <Node>(contentTypeName); var template = from t in templatesForContentType where t.Name.Equals(templateName) select t; if (template.Count() < 1) { throw new InvalidOperationException(String.Format("There is no template with {0} name for {1} contentType.", templateName, contentTypeName)); } var templateNode = template.FirstOrDefault(); return(ContentTemplate.CreateTemplated(targetNode, templateNode, null)); }
public void CreateProfile(Node template = null) { if (!IdentityManagement.UserProfilesEnabled) { return; } var upPath = ProfilePath; using (new SystemAccount()) { if (Node.Exists(upPath)) { return; } var profileDomainPath = GetProfileParentPath(); var profiles = Node.LoadNode(GetProfilesPath()); if (profiles == null) { var profilesTarget = Node.LoadNode(GetProfilesTargetPath()); profiles = Content.CreateNew(Profiles, profilesTarget, Profiles).ContentHandler; profiles.Save(); } Content profile = null; var profileDomain = Node.LoadNode(profileDomainPath); Content domain; if (profileDomain == null) { // create domain if not present var domName = this.Domain ?? IdentityManagement.BuiltInDomainName; domain = Content.CreateNew("ProfileDomain", profiles, domName); // We set creator and modifier to Administrator here to avoid // cases when a simple user becomes an author of a whole domain. var admin = User.Administrator; domain.ContentHandler.CreatedBy = admin; domain.ContentHandler.VersionCreatedBy = admin; domain.ContentHandler.Owner = admin; domain.ContentHandler.ModifiedBy = admin; domain.ContentHandler.VersionModifiedBy = admin; domain.DisplayName = domName; try { domain.Save(); profileDomain = domain.ContentHandler; } catch (NodeAlreadyExistsException) { // no problem, somebody else already created this domain in the meantime profileDomain = Node.LoadNode(profileDomainPath); } } template = template ?? ContentTemplate.GetNamedTemplate("UserProfile", GetProfileTemplateName()); if (template == null) { profile = Content.CreateNew("UserProfile", profileDomain, GetProfileName()); } else { var profNode = ContentTemplate.CreateFromTemplate(profileDomain, template, GetProfileName()); if (profNode != null) { profile = Content.Create(profNode); } } if (profile != null) { try { profile.ContentHandler.CreatedBy = this; profile.ContentHandler.VersionCreatedBy = this; profile.ContentHandler.Owner = this; profile.DisplayName = this.Name; profile.Save(); Profile = profile.ContentHandler as UserProfile; Save(SavingMode.KeepVersion); } catch (Exception ex) { // error during user profile creation SnLog.WriteException(ex); } } } }
public void CreateProfile(Node template) { if (!Repository.UserProfilesEnabled) { return; } var upPath = GetProfilePath(); using (new SystemAccount()) { if (Node.Exists(upPath)) { return; } var uDomainPath = GetProfileParentPath(); var profiles = Node.LoadNode(Repository.UserProfilePath); if (profiles == null) { profiles = Content.CreateNew("Profiles", Repository.Root, "Profiles").ContentHandler; profiles.Save(); } Content profile = null; var profileDomain = Node.LoadNode(uDomainPath); if (profileDomain == null) { //create domain if not present var domName = this.Domain ?? RepositoryConfiguration.BuiltInDomainName; var dom = Content.CreateNew("ProfileDomain", profiles, domName); dom.DisplayName = domName; dom.Save(); profileDomain = dom.ContentHandler; } if (template == null) { template = ContentTemplate.GetTemplate("UserProfile"); } if (template == null) { profile = Content.CreateNew("UserProfile", profileDomain, GetProfileName()); } else { var profNode = ContentTemplate.CreateFromTemplate(profileDomain, template, GetProfileName()); if (profNode != null) { profile = Content.Create(profNode); } } if (profile != null) { try { //profile["CreatedBy"] = this; profile.ContentHandler.CreatedBy = this; profile.ContentHandler.NodeCreatedBy = this; profile.DisplayName = this.Name; profile.Save(); } catch (Exception ex) { //error during user profile creation Logger.WriteException(ex); } } } }