コード例 #1
0
        protected void RemoveSiteAttributes(SiteInfo siteInfo)
        {
            Item sFolder = MasterDB.GetItem(Constants.Paths.Sites);

            if (sFolder != null)
            {
                Item siteItem = sFolder.Axes.GetChild(siteInfo.Name);
                //set login url on the site node
                using (new EditContext(siteItem)) {
                    siteItem[Sitecore.Extranet.Core.Constants.ExtranetAttributes.LoginPage] = string.Empty;
                }

                IEnumerable <Item> atts = siteItem.Axes.GetDescendants().Where(a => a.Template.IsID(Constants.TemplateIDs.SiteAttribute) && Sitecore.Extranet.Core.Constants.ExtranetAttributes.Keys.Contains(a.Key));
                if (atts != null && atts.Any())
                {
                    foreach (Item a in atts)
                    {
                        a.Recycle();
                    }
                }

                SitecoreUtility.PublishContent(siteItem, true);
            }
            else
            {
                FileUtility.RemoveFile(string.Format(Sitecore.Extranet.Core.Wizards.ExtranetSetupWizard.Constants.FilePatterns.ExtranetSiteConfig, siteInfo.Name));
            }
        }
コード例 #2
0
        /// <summary>
        /// Builds a country site in the Sitecore Master database. Performs clean up if the creation fails.
        /// </summary>
        /// <param name="data">Contains parameters to configure the construction. See Lookup.Parameters for detailed information.</param>
        /// <returns>A message indicating the status of the action</returns>
        public override void CoreExecute()
        {
            string   siteName = InputData.Get <string>(Constants.Keys.Site);
            SiteInfo SiteItem = Factory.GetSiteInfo(siteName);

            IEnumerable <ListItem> langs         = InputData.Get <IEnumerable <ListItem> >(Constants.Keys.Languages);
            IEnumerable <Language> selectedLangs = (from val in MasterDB.Languages
                                                    where langs.Any(a => a.Value.Equals(val.Name))
                                                    select val);

            string pageID   = InputData.Get <string>(Constants.Keys.Page);
            Item   PageItem = MasterDB.GetItem(pageID);

            //status
            SetStatus(1, "Building extranet pages.");

            //create extranet pages from branch
            Item extranetFolder = BuildExtranetPages(SiteItem, selectedLangs);

            //status
            SetStatus(2, "Configuring Security.");

            //create role
            CreateRole(SiteItem);

            //move login page to child of secure page
            Item LoginPage = ConfigureLoginPage(extranetFolder, PageItem, siteName);

            //update site login settings and attributes
            SetupSiteAttributes(SiteItem, LoginPage);
        }
コード例 #3
0
        private bool ValidateBranch()
        {
            bool          valid = true;
            StringBuilder sb    = new StringBuilder();

            string eID = ExtranetBranch.Value;

            if (!string.IsNullOrEmpty(eID) && Sitecore.Data.ID.IsID(eID))               // Content Branch
            {
                Item ci = MasterDB.GetItem(eID);
                if (ci == null)
                {
                    valid = false;
                    sb.Append("The extranet branch item you chose is null.").Append("<br/>");
                }
                else if (!ci.TemplateName.Equals("Branch"))
                {
                    valid = false;
                    sb.Append("Please select a extranet branch item whose template type is a branch.").Append("<br/>");
                }
            }
            else
            {
                valid = false;
                sb.Append("The extranet branch selected is producing an empty string or bad ID.").Append("<br/>");
            }

            if (!valid)
            {
                BranchErrorMessage.Text = sb.ToString();
            }

            return(valid);
        }
コード例 #4
0
        protected void SetupSiteAttributes(SiteInfo siteInfo, Item loginPage)
        {
            string siteName    = siteInfo.Name;
            string loginUrl    = string.Format("{0}.aspx", loginPage.Paths.ContentPath.Replace(string.Format("/{0}/Home", siteName), ""));
            string secProvider = "sitecore";
            string fromEmail   = InputData.Get <string>(Sitecore.Extranet.Core.Constants.ExtranetAttributes.FromEmail);
            string loginCount  = InputData.Get <string>(Sitecore.Extranet.Core.Constants.ExtranetAttributes.LoginCount);

            //if you've got the multisite manager installed then you'll handle this differently
            Item sFolder = MasterDB.GetItem(Constants.Paths.Sites);

            if (sFolder != null)
            {
                //setup site drop downs
                IEnumerable <Item> siteRes = sFolder.GetChildren().Where(a => a.DisplayName.Equals(siteName));
                if (!siteRes.Any())
                {
                    return;
                }
                Item siteItem = siteRes.First();

                using (new EditContext(siteItem))                 //set login url on the site node
                    siteItem[Sitecore.Extranet.Core.Constants.ExtranetAttributes.LoginPage] = loginUrl;

                //set extranet user prefix attributes on site node: ExtranetUserPrefix and ExtranetRole
                TemplateItem sa = GetItem(Constants.TemplateIDs.SiteAttribute);
                if (sa != null)
                {
                    Item uPrefix = siteItem.Add(Sitecore.Extranet.Core.Constants.ExtranetAttributes.UserPrefix, sa);
                    SetValue(uPrefix, string.Format("{0}_", siteName));
                    Item roleName = siteItem.Add(Sitecore.Extranet.Core.Constants.ExtranetAttributes.Role, sa);
                    SetValue(roleName, string.Format("{0} Extranet", siteName));
                    Item fEmail = siteItem.Add(Sitecore.Extranet.Core.Constants.ExtranetAttributes.FromEmail, sa);
                    SetValue(fEmail, fromEmail);
                    Item lCount = siteItem.Add(Sitecore.Extranet.Core.Constants.ExtranetAttributes.LoginCount, sa);
                    SetValue(lCount, loginCount);
                }
            }
            else
            {
                StringBuilder fc = new StringBuilder();
                fc.AppendLine("<configuration xmlns:patch=\"http://www.sitecore.net/xmlconfig/\">");
                fc.AppendLine("	<sitecore>");
                fc.AppendLine("		<sites>");
                fc.AppendFormat("		<site name=\"{0}\">", siteName).AppendLine();
                fc.AppendFormat("			<patch:attribute name=\"{0}\">{1}</patch:attribute>", Sitecore.Extranet.Core.Constants.ExtranetAttributes.LoginPage, loginUrl).AppendLine();
                fc.AppendFormat("			<patch:attribute name=\"{0}\">{1}_</patch:attribute>", Sitecore.Extranet.Core.Constants.ExtranetAttributes.UserPrefix, siteName).AppendLine();
                fc.AppendFormat("			<patch:attribute name=\"{0}\">{1} Extranet</patch:attribute>", Sitecore.Extranet.Core.Constants.ExtranetAttributes.Role, siteName).AppendLine();
                fc.AppendFormat("			<patch:attribute name=\"{0}\">{1}</patch:attribute>", Sitecore.Extranet.Core.Constants.ExtranetAttributes.FromEmail, fromEmail).AppendLine();
                fc.AppendFormat("			<patch:attribute name=\"{0}\">{1}</patch:attribute>", Sitecore.Extranet.Core.Constants.ExtranetAttributes.LoginCount, loginCount).AppendLine();
                fc.AppendLine("			</site>");
                fc.AppendLine("		</sites>");
                fc.AppendLine("	</sitecore>");
                fc.AppendLine("</configuration>");

                FileUtility.MakeFile(string.Format(Constants.FilePatterns.ExtranetSiteConfig, siteName), fc.ToString());
            }
        }
コード例 #5
0
        protected Item BuildExtranetPages(SiteInfo siteItem, IEnumerable <Language> selectedLangs)
        {
            LangCur   = 1;
            LangTotal = selectedLangs.Count();
            Item extranetFolder = null;

            foreach (Language targetLang in selectedLangs)
            {
                using (new LanguageSwitcher(targetLang)) {
                    //get content and media branch and branch ancestor info
                    BranchItem extranetBranch = MasterDB.GetItem(InputData.Get <string>(Constants.Keys.ExtranetBranch));

                    //if adding multiple languages, determines if this is the first language added or not
                    bool firstRun = (LangCur == 1);

                    if (firstRun)                       // if adding multiple languages you only want to do this once
                    //status
                    {
                        BuildJob.Status.Messages.Add(string.Format("Building {0} content from branch.", targetLang.CultureInfo.DisplayName));

                        Item HomeItem = MasterDB.GetItem(string.Format("{0}{1}", siteItem.RootPath, siteItem.StartItem));
                        extranetFolder = HomeItem.Add("extranet", extranetBranch);

                        CleanupList.Add(extranetFolder);                         // Register website for cleanup if creation fails.
                    }
                    else
                    {
                        // All content items including website item
                        IEnumerable <Item> contentItems = new Item[] { extranetFolder }.Concat(extranetFolder.Axes.GetDescendants());

                        //add new version for language and update referential links
                        ItemCur   = 1;
                        ItemTotal = contentItems.Count();
                        foreach (Item newItem in contentItems)
                        {
                            BuildJob.Status.Messages.Add(string.Format("Language {0} of {1}<br/>Item {2} of {3}", LangCur, LangTotal, ItemCur, ItemTotal));

                            //create a version of the current language for all the content under website
                            Item langVersion = MasterDB.GetItem(newItem.ID, targetLang);
                            langVersion = langVersion.Versions.AddVersion();

                            ItemCur++;
                        }
                    }
                }
                LangCur++;
            }
            return(extranetFolder);
        }
コード例 #6
0
        protected Item GetItem(string IDstr)
        {
            string saIDstr = Constants.TemplateIDs.SiteAttribute;

            if (!Sitecore.Data.ID.IsID(saIDstr))
            {
                return(null);
            }
            ID saID = null;

            if (!ID.TryParse(saIDstr, out saID))
            {
                return(null);
            }
            return(MasterDB.GetItem(saID));
        }
コード例 #7
0
        protected void RemoveExtranetPages(SiteInfo siteItem)
        {
            Item HomeItem            = MasterDB.GetItem(string.Format("{0}{1}", siteItem.RootPath, siteItem.StartItem));
            IEnumerable <Item> pages = HomeItem.Axes.GetDescendants().Where(a => a.Template.IsID(Constants.TemplateIDs.ExtranetFolder) || a.Template.Is(Constants.TempateName.ExtranetLogin));

            if (pages == null || !pages.Any())
            {
                return;
            }
            foreach (Item p in pages)
            {
                Item par = p.Parent;
                p.Recycle();

                SitecoreUtility.PublishContent(par, true);
            }
        }
コード例 #8
0
        private bool ValidatePage()
        {
            bool          valid = true;
            StringBuilder sb    = new StringBuilder();

            string cID = PageTree.Value;

            if (!string.IsNullOrEmpty(cID) && Sitecore.Data.ID.IsID(cID))               // Content Branch
            {
                Item ci = MasterDB.GetItem(cID);
                if (ci == null)
                {
                    valid = false;
                    sb.Append("The item you selected is null.").Append("<br/>");
                }
            }
            else
            {
                valid = false;
                sb.Append("The item selected is producing an empty string or bad ID.").Append("<br/>");
            }

            if (string.IsNullOrEmpty(FromEmail.Value))
            {
                valid = false;
                sb.Append("You need to provide a 'From' email address.").Append("<br/>");
            }

            int count = -1;

            if (string.IsNullOrEmpty(LoginCount.Value) || !int.TryParse(LoginCount.Value, out count))
            {
                valid = false;
                sb.Append("You need to provide a number for the login count.").Append("<br/>");
            }

            if (!valid)
            {
                PageErrorMessage.Text = sb.ToString();
            }

            return(valid);
        }