Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        /// <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));
        }
Exemplo n.º 4
0
        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);

                    //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;
                    dom.ContentHandler.CreatedBy         = admin;
                    dom.ContentHandler.VersionCreatedBy  = admin;
                    dom.ContentHandler.ModifiedBy        = admin;
                    dom.ContentHandler.VersionModifiedBy = admin;
                    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.VersionCreatedBy = this;
                        profile.DisplayName = this.Name;
                        profile.Save();
                    }
                    catch (Exception ex)
                    {
                        //error during user profile creation
                        Logger.WriteException(ex);
                    }
                }
            }
        }