Esempio 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);
            }
        }
Esempio n. 2
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);
                    }
                }
            }
        }