示例#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);
            }
        }
示例#2
0
        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);
                    }
                }
            }
        }
示例#3
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);

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