/// <summary> /// Gets the latest updated threads. Will search through all the forums beneath the supplied root. /// </summary> /// <param name="pageRef">The root page to look for threads under.</param> /// <param name="nrOfThreads">The number of threads to return.</param> /// <returns>A PageDataCollection containing threads.</returns> public static PageDataCollection GetLatestUpdatedThreads(PageReference pageRef, int nrOfThreads) { PropertyCriteriaCollection criterias = new PropertyCriteriaCollection(); criterias.Add("PageTypeName", ThreadContainerPageTypeName, CompareCondition.Equal); PageDataCollection pages = DataFactory.Instance.FindPagesWithCriteria(pageRef, criterias); PageDataCollection threads = new PageDataCollection(); FilterPublished publishedFilter = new FilterPublished(); foreach (PageData threadContainer in pages) { foreach (PageData page in DataFactory.Instance.GetChildren(threadContainer.PageLink, LanguageSelector.AutoDetect(), 0, nrOfThreads)) { if (!publishedFilter.ShouldFilter(page)) { threads.Add(page); } } } new FilterPropertySort("PageChanged", FilterSortDirection.Descending).Filter(threads); new FilterCount(nrOfThreads).Filter(threads); return(threads); }
/// <summary> /// Filters the specified pages. /// </summary> /// <param name="pages">The pages.</param> public void Filter(PageDataCollection pages) { var output = new PageDataCollection(); pages.Where(x => !this.notAllowedPageTypes.Any(k => k == x.PageTypeName)).ToList().ForEach(l => output.Add(l)); pages.Clear(); output.ToList().ForEach(x => pages.Add(x)); }
public PageDataCollection GetPagesByTag(Tag tag, PageReference rootPageReference) { if (tag == null || tag.PermanentLinks == null) { return(null); } IList <PageReference> descendantPageReferences = DataFactory.Instance.GetDescendents(rootPageReference); if (descendantPageReferences == null || descendantPageReferences.Count < 1) { return(null); } var pages = new PageDataCollection(); foreach (Guid pageGuid in tag.PermanentLinks) { var pageReference = TagsHelper.GetContentReference(pageGuid); if (descendantPageReferences.FirstOrDefault(p => p.ID == pageReference.ID) != null) { pages.Add(this._contentLoader.Get <PageData>(pageReference)); } } return(pages); }
private PageDataCollection GetLanguageBranches(PageReference pageLink) { var languages = new PageDataCollection(); languages.Add(GetPage(pageLink)); return(languages); }
protected PageDataCollection SearchRelations() { string CacheKey = CurrentRule.Id.ToString() + "_" + CurrentPage.PageLink.ID + "_" + PageTypesDropDown.SelectedValue + "_" + _ruleDirection.ToString(); PageDataCollection pages = EPiServer.CacheManager.Get(CacheKey) as PageDataCollection; PageDataCollection result = new PageDataCollection(); if (pages == null || 1 == 1) { pages = RuleEngine.Instance.SearchRelations(CurrentRule, CurrentPage.PageLink.ID, SearchKeyWord.Text, IsLeftRule); if (PageTypesDropDown.SelectedValue.Length > 2) { foreach (PageData pd in pages) { if (pd.PageTypeName == PageTypesDropDown.SelectedValue) { result.Add(pd); } } } else { result = pages; } EPiServer.CacheManager.Add(CacheKey, result); } return(result); }
public PageDataCollection GetPagesByTag(Tag tag) { if (tag == null) { return(null); } var pageLinks = new List <Guid>(); if (tag.PermanentLinks == null) { var tempTerm = this._tagService.GetTagByName(tag.Name); if (tempTerm != null) { pageLinks = tempTerm.PermanentLinks.ToList(); } } else { pageLinks = tag.PermanentLinks.ToList(); } var pages = new PageDataCollection(); foreach (Guid pageGuid in pageLinks) { pages.Add(this._contentLoader.Get <PageData>(TagsHelper.GetContentReference(pageGuid))); } return(pages); }
private static PageData FindPageByName(PageReference rootPage, string pageName, string pageType) { PageDataCollection children = DataFactory.Instance.GetChildren(rootPage); children.Add(DataFactory.Instance.GetChildren(rootPage, LanguageSelector.MasterLanguage())); return(children.FirstOrDefault(page => page.PageName.Equals(pageName) && page.PageTypeName.Equals(pageType))); }
public override PageDataCollection SearchRelations(Rule rule, int pageID, string searchKeyWord, PageReference hierarchyStart, bool isLeftRule) { string pageTypes = HttpUtility.UrlDecode(isLeftRule ? rule.PageTypeRight : rule.PageTypeLeft); PageDataCollection result = new PageDataCollection(); if (!string.IsNullOrEmpty(pageTypes)) { string[] pageTypeCollection = pageTypes.Split(';'); PropertyCriteriaCollection pageTypeCriterias = new PropertyCriteriaCollection(); if (hierarchyStart == null || hierarchyStart == PageReference.EmptyReference) { hierarchyStart = PageReference.RootPage; } foreach (string s in pageTypeCollection) { if (!string.IsNullOrEmpty(s)) { PropertyCriteria criteria = new PropertyCriteria(); criteria.Condition = EPiServer.Filters.CompareCondition.Equal; criteria.Name = "PageTypeName"; criteria.Type = PropertyDataType.String; criteria.Value = s; pageTypeCriterias.Add(criteria); } } PageDataCollection pages = DataFactory.Instance.FindPagesWithCriteria(hierarchyStart, pageTypeCriterias); PageData rootPage = DataFactory.Instance.GetPage(hierarchyStart); if (pageTypeCollection.Contains <string>(rootPage.PageTypeName) && !pages.Contains(rootPage)) { pages.Add(rootPage); } new EPiServer.Filters.FilterSort(EPiServer.Filters.FilterSortOrder.Alphabetical).Sort(pages); if (!string.IsNullOrEmpty(searchKeyWord)) { for (int i = 0; i < pages.Count; i++) { if (pages[i].PageName.ToLower().Contains(searchKeyWord.ToLower())) { result.Add(pages[i]); } } } else { result = pages; } } return(result); }
private static PageDataCollection GetAllPages(PageData parent, PageDataCollection allPages) { PageDataCollection children = DataFactory.Instance.GetChildren(parent.ContentLink.ToPageReference()); foreach (PageData pd in children) { allPages.Add(pd); GetAllPages(pd, allPages); } return(allPages); }
/// <summary> /// Gets the changed pages under one subscription root for a specific user. /// </summary> /// <param name="profile">The profile for a user.</param> /// <param name="language">The requested language.</param> /// <param name="subscribedPage">The subscribed subscription root.</param> /// <param name="principal">The principal for the user.</param> /// <returns>A collection of pages that have been changed and are children of the subscribedPage.</returns> protected PageDataCollection GetChangedPages(EPiServerProfile profile, string language, SubscriptionDescriptor subscribedPage, IPrincipal principal) { IList <PageLanguage> pageLanguageList = this._subscriptionDB.PagesChangedAfter(subscribedPage.PageID, profile.SubscriptionInfo.LastMessage, 100); int count = pageLanguageList.Count; int pageID = -1; PageDataCollection pageDataCollection = new PageDataCollection(); IList <string> stringList = (IList <string>) new List <string>(); foreach (PageLanguage pageLanguage in (IEnumerable <PageLanguage>)pageLanguageList) { if (string.Compare(pageLanguage.LanguageID, language, StringComparison.InvariantCultureIgnoreCase) == 0) { if (pageLanguage.PageID != pageID && pageID != -1) { PageData page = this.GetPage(pageID, pageLanguage.LanguageID, principal, true); if (page != null) { pageDataCollection.Add(page); } stringList.Clear(); } stringList.Add(pageLanguage.LanguageID); pageID = pageLanguage.PageID; } } if (pageID != -1) { foreach (string language1 in (IEnumerable <string>)stringList) { PageData page = this.GetPage(pageID, language1, principal, true); if (page != null) { pageDataCollection.Add(page); } } } return(pageDataCollection); }
/* * public static PageDataCollection GetRelatedPagesRoundTripHierarchy(Rule rule, Relation relation, int pageID) * { * PageReference pr = new PageReference(pageID); * PageData origPage = DataFactory.Instance.GetPage(pr); * List<int> relationPages = RelationEngine.GetRelationsForPageRoundTripHierarchy(pageID, rule, relation); * return PageIDListToPages(relationPages); * }*/ /// <summary> /// Helper method for page relation getters to convert relations to pages. /// </summary> /// <param name="pageIDList">Collection of page IDs</param> /// <returns>Collection of pages</returns> public static PageDataCollection PageIDListToPages(List <int> pageIDList) { PageDataCollection pages = new PageDataCollection(); foreach (int pgid in pageIDList) { PageData pd = PageEngine.GetPage(pgid); if (pd != null && !pages.Contains(pd)) { pages.Add(pd); } } return(pages); }
/// <summary> /// Populates the pages. /// </summary> /// <param name="pages">The pages.</param> protected override void PopulatePages(PageDataCollection pages) { PageTreeData data = new PageTreeData(); data.EnableVisibleInMenu = false; data.PageLink = this.PageLink; data.PageSource = this.PageSource; data.ExpandAll = true; foreach (PageData page in data) { pages.Add(page); } base.ExecFilters(pages); }
/// <summary>Unsupported INTERNAL API! Not covered by semantic versioning; might change without notice. Create the Html for the subscription mail body. /// </summary> /// <param name="subscriptionPage">The subscription template page.</param> /// <param name="changedPagesReadOnly">A collection of readonly pages that have changed.</param> /// <returns>The complete Html for the mail body ("<html>.... </html>").</returns> /// <remarks> /// Call the <see cref="M:EPiServer.Personalization.Internal.SubscriptionMail.GetCSSContents" /> function to fetch any CSS data that should be /// included in the html. /// </remarks> /// <exclude /> public virtual string GenerateBody(PageData subscriptionPage, PageDataCollection changedPagesReadOnly) { string cssContents = this.GetCSSContents(); PageDataCollection pages = new PageDataCollection(); foreach (PageData pageData in changedPagesReadOnly) { PageData writableClone = pageData.CreateWritableClone(); SubscriptionMail.log.Debug((object)("4.3.5 Adding page to subscription pageLink=" + (object)writableClone.PageLink)); DateTime changed = writableClone.Changed; DateTime?nullable = writableClone.StartPublish; if ((nullable.HasValue ? (changed > nullable.GetValueOrDefault() ? 1 : 0) : 0) != 0) { writableClone.Property.Add(this._subscriptionMailDatePropertyName, (PropertyData) new PropertyDate(writableClone.Changed)); } else { PropertyDataCollection property = writableClone.Property; string datePropertyName = this._subscriptionMailDatePropertyName; nullable = writableClone != null ? writableClone.StartPublish : new DateTime?(); PropertyDate propertyDate = new PropertyDate(nullable ?? DateTime.MaxValue); property.Add(datePropertyName, (PropertyData)propertyDate); } pages.Add(writableClone); } new FilterPropertySort(this._subscriptionMailDatePropertyName, FilterSortDirection.Descending).Filter((object)this, new FilterEventArgs(pages)); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<html>"); stringBuilder.Append("<head>"); if (cssContents.Length > 0) { stringBuilder.AppendFormat("<style>{0}</style>", (object)cssContents); } stringBuilder.Append("</head>"); stringBuilder.Append("<body>"); if (subscriptionPage["SubscriptionMailBody"] != null) { stringBuilder.Append(subscriptionPage["SubscriptionMailBody"]); } foreach (PageData page in pages) { page.MakeReadOnly(); stringBuilder.Append(this.FormatPageForBody(subscriptionPage, page)); } stringBuilder.Append("</body></html>"); return(stringBuilder.ToString()); }
public PageDataCollection List(PageReference pageLink) { IEnumerable<ContentReference> descendantContentLinks = _contentLoader.GetDescendents(pageLink); var standardPages = new PageDataCollection(); foreach (ContentReference contentLink in descendantContentLinks) { StandardPage standardPage = GetStandardPage(contentLink); if (standardPage != null) { standardPages.Add(standardPage); } } return standardPages; }
public PageDataCollection List(PageReference pageLink) { IEnumerable<ContentReference> descendantContentLinks = _contentLoader.GetDescendents(pageLink); IEnumerable<IContent> allDescendantContent = _contentLoader.GetItems(descendantContentLinks, new LoaderOptions()); var standardPages = new PageDataCollection(); foreach (IContent content in allDescendantContent) { if (IsStandardPage(content)) { standardPages.Add(content); } } return standardPages; }
/// <summary> /// Convert a LinkItemCollection to a PageDataCollection. /// </summary> /// <remarks> /// Author: Frederik Vig /// Link: http://www.frederikvig.com/2009/06/episerver-extension-methods-part-2/ /// </remarks> /// <param name="linkItemCollection">The LinkItemCollection to convert.</param> /// <returns>The resulting PageDataCollection.</returns> public static PageDataCollection ToPageDataCollection(this LinkItemCollection linkItemCollection) { var pageDataCollection = new PageDataCollection(); foreach (var linkItem in linkItemCollection) { var url = new UrlBuilder(linkItem.Href); if (!PermanentLinkMapStore.ToMapped(url)) continue; var page = DataFactory.Instance.GetPage(PermanentLinkUtility.GetPageReference(url)); if (page != null) pageDataCollection.Add(page); } return pageDataCollection; }
public override List <EventPageBase> GetEventPages() { PropertyCriteriaCollection criteria = new PropertyCriteriaCollection(); var pageTypes = ServiceLocator.Current.GetInstance <IContentTypeRepository>().List(); foreach (var pageType in pageTypes) { if (pageType.ModelType != null && typeof(EventPageBase).IsAssignableFrom(pageType.ModelType)) { PropertyCriteria pageTypeCriteria = new PropertyCriteria(); pageTypeCriteria.Condition = CompareCondition.Equal; pageTypeCriteria.Value = pageType.ID.ToString(); pageTypeCriteria.Type = PropertyDataType.PageType; pageTypeCriteria.Name = "PageTypeID"; pageTypeCriteria.Required = false; criteria.Add(pageTypeCriteria); } } List <EventPageBase> eventList = new List <EventPageBase>(); var sites = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <EPiServer.Web.SiteDefinitionRepository>().List(); foreach (SiteDefinition siteDefinition in sites) { PageDataCollection allEvents = new PageDataCollection(); var allLanguages = ServiceLocator.Current.GetInstance <ILanguageBranchRepository>().ListEnabled(); foreach (LanguageBranch languageBranch in allLanguages) { allEvents.Add(DataFactory.Instance.FindAllPagesWithCriteria(siteDefinition.StartPage.ToPageReference(), criteria, languageBranch.LanguageID, new LanguageSelector(languageBranch.LanguageID))); } foreach (PageData currentEvent in allEvents) { if (currentEvent as EventPageBase != null) { eventList.Add(currentEvent as EventPageBase); } } } return(eventList); }
private PageDataCollection GetStandardPageChildren(PageReference parent) { PageDataCollection standardPages = new PageDataCollection(); IEnumerable<PageData> children = _contentLoader.GetChildren<PageData>(parent); foreach (PageData child in children) { var standardPage = child as StandardPage; if (standardPage != null) { standardPages.Add(standardPage); } standardPages.AddRange(GetStandardPageChildren(child.PageLink)); } return standardPages; }
/// <summary> /// Called when a scheduled job executes /// </summary> /// <returns>A status message to be stored in the database log and visible from admin mode</returns> public override string Execute() { //Call OnStatusChanged to periodically notify progress of job for manually started jobs OnStatusChanged(String.Format("Starting execution of {0}", this.GetType())); PropertyCriteriaCollection criteria = new PropertyCriteriaCollection(); PropertyCriteria pageTypeCriteria = new PropertyCriteria(); pageTypeCriteria.Condition = CompareCondition.Equal; pageTypeCriteria.Value = ServiceLocator.Current.GetInstance<IContentTypeRepository>().Load<EventPage>().ID.ToString(); pageTypeCriteria.Type = PropertyDataType.PageType; pageTypeCriteria.Name = "PageTypeID"; pageTypeCriteria.Required = true; criteria.Add(pageTypeCriteria); PageDataCollection allEvents = new PageDataCollection(); PageDataCollection allLanguages = DataFactory.Instance.GetLanguageBranches(PageReference.StartPage); foreach (PageData pageData in allLanguages) { allEvents.Add(DataFactory.Instance.FindPagesWithCriteria(PageReference.RootPage, criteria, pageData.LanguageBranch)); } int cnt = 0; foreach (var eventPage in allEvents) { cnt += UpdateEvent(eventPage as EventPage); } return "Found " + allEvents.Count + " pages, converted "+cnt+"e-mail templates!"; //Add implementation //For long running jobs periodically check if stop is signaled and if so stop execution if (_stopSignaled) { return "Stop of job was called"; } return "Change to message that describes outcome of execution"; }
/// <summary> /// Called when a scheduled job executes /// </summary> /// <returns>A status message to be stored in the database log and visible from admin mode</returns> public override string Execute() { //Call OnStatusChanged to periodically notify progress of job for manually started jobs OnStatusChanged(String.Format("Starting execution of {0}", this.GetType())); PropertyCriteriaCollection criteria = new PropertyCriteriaCollection(); PropertyCriteria pageTypeCriteria = new PropertyCriteria(); pageTypeCriteria.Condition = CompareCondition.Equal; pageTypeCriteria.Value = ServiceLocator.Current.GetInstance <IContentTypeRepository>().Load <EventPageBase>().ID.ToString(); pageTypeCriteria.Type = PropertyDataType.PageType; pageTypeCriteria.Name = "PageTypeID"; pageTypeCriteria.Required = true; criteria.Add(pageTypeCriteria); PageDataCollection allEvents = new PageDataCollection(); PageDataCollection allLanguages = DataFactory.Instance.GetLanguageBranches(ContentReference.StartPage); foreach (PageData pageData in allLanguages) { allEvents.Add(DataFactory.Instance.FindPagesWithCriteria(ContentReference.StartPage, criteria, pageData.LanguageBranch)); } int cnt = 0; foreach (var EventPageBase in allEvents) { cnt += UpdateEvent(EventPageBase as EventPageBase); } return("Found " + allEvents.Count + " pages, converted " + cnt + "e-mail templates!"); //Add implementation //For long running jobs periodically check if stop is signaled and if so stop execution if (_stopSignaled) { return("Stop of job was called"); } return("Change to message that describes outcome of execution"); }
/// <summary> /// Returns a PageDataCollection with a distinct list of pages related through the given rule. Number of relations are added to PageName. /// </summary> /// <param name="allPages">PageDataCollection to create facets from</param> /// <param name="ruleName">Rule used for facet relations</param> /// <param name="direction">Direction of facet relations</param> /// <returns></returns> public static PageDataCollection FacetList(PageDataCollection allPages, string ruleName, Rule.Direction direction) { List <Relation> relations = RelationEngine.Instance.GetAllRelations(ruleName); List <int> facets; if (direction == Rule.Direction.Right) { facets = (from id in relations select id.PageIDRight).Distinct().ToList(); } else { facets = (from id in relations select id.PageIDLeft).Distinct().ToList(); } PageDataCollection facetPages = PageHelper.PageIDListToPages(facets); PageDataCollection facetsWithCount = new PageDataCollection(); foreach (PageData facetPage in facetPages) { PageData writableFacet = facetPage.CreateWritableClone(); if (direction == Rule.Direction.Right) { writableFacet.PageName = writableFacet.PageName + " (" + (from id in relations where id.PageIDRight == facetPage.PageLink.ID select id) .Count() + ")"; } else { writableFacet.PageName = writableFacet.PageName + " (" + (from id in relations where id.PageIDLeft == facetPage.PageLink.ID select id) .Count() + ")"; } facetsWithCount.Add(writableFacet); } new EPiServer.Filters.FilterSort(FilterSortOrder.Alphabetical).Sort(facetsWithCount); return(facetsWithCount); }
protected void PerformSearch_Click(object sender, EventArgs e) { PageDataCollection pdc = SearchRelations(); PageDataCollection result = new PageDataCollection(); if (!string.IsNullOrEmpty(SearchKeyWord.Text)) { foreach (PageData pd in pdc) { if (pd.PageName.ToLower().Contains(SearchKeyWord.Text.ToString().ToLower())) { result.Add(pd); } } } else { result = pdc; } AllRelations.DataSource = result; AllRelations.DataBind(); }
public PageDataCollection GetPagesByTag(Tag tag) { if (tag == null) { return null; } var pageLinks = new List<Guid>(); if (tag.PermanentLinks == null) { var tempTerm = this._tagService.GetTagByName(tag.Name); if (tempTerm != null) { pageLinks = tempTerm.PermanentLinks.ToList(); } } else { pageLinks = tag.PermanentLinks.ToList(); } var pages = new PageDataCollection(); foreach (Guid pageGuid in pageLinks) { pages.Add(DataFactory.Instance.GetPage(TagsHelper.GetPageReference(pageGuid))); } return pages; }
protected void PerformSearch_Click(object sender, EventArgs e) { PageDataCollection pdc = SearchRelations(); PageDataCollection result = new PageDataCollection(); if (!string.IsNullOrEmpty(SearchKeyWord.Text)) { foreach (PageData pd in pdc) { if (pd.PageName.ToLower().Contains(SearchKeyWord.Text.ToString().ToLower())) result.Add(pd); } } else result = pdc; AllRelations.DataSource = result; AllRelations.DataBind(); }
protected override IEnumerable<IContent> GetContent(ContentQueryParameters parameters) { if(HttpContext.Current.Session != null) HttpContext.Current.Session["ValidationResult"] = ""; bool isLeftRule = (HttpUtility.HtmlDecode(parameters.AllParameters["direction"]) == "left"); var queryText = HttpUtility.HtmlDecode(parameters.AllParameters["queryText"]); var relationPageLeft = HttpUtility.HtmlDecode(parameters.AllParameters["relationPageLeft"]); string relationPageRightUrl = HttpUtility.HtmlDecode(parameters.AllParameters["relationPageRight"]); //string relationPageRight = ""; /* if (!string.IsNullOrEmpty(relationPageRightUrl)) { Match match = regex.Match(HttpUtility.HtmlDecode(parameters.AllParameters["relationPageRight"])); if (match.Success) { relationPageRight = (match.Groups[1].Value); } }*/ var relationRule = HttpUtility.HtmlDecode(parameters.AllParameters["relationRule"]); var action = HttpUtility.HtmlDecode(parameters.AllParameters["action"]); PageReference contextPage = (relationPageLeft != null) ? new PageReference(relationPageLeft) : null; PageDataCollection result = new PageDataCollection(); if (contextPage != null && relationPageLeft != null) try { List<int> relations = new List<int>(); if(RuleEngine.Instance.GetRule(relationRule).RuleTextLeft == RuleEngine.Instance.GetRule(relationRule).RuleTextRight) relations = RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule)); else relations = isLeftRule ? RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule), Rule.Direction.Left).Distinct<int>().ToList<int>() : RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule), Rule.Direction.Right).Distinct<int>().ToList<int>(); foreach (int pageid in relations) { try { result.Add(PageEngine.GetPage(pageid)); } catch { Logging.Warning(string.Format("Error fetching page {0} related to {1}", pageid, contextPage.ID)); } } } catch { Logging.Warning(string.Format("Error fetching relations from page {0}", contextPage.ID)); } return result; }
public override List<EventPageBase> GetEventPages() { PropertyCriteriaCollection criteria = new PropertyCriteriaCollection(); var pageTypes = ServiceLocator.Current.GetInstance<IContentTypeRepository>().List(); foreach (var pageType in pageTypes) { if (pageType.ModelType != null && typeof(EventPageBase).IsAssignableFrom(pageType.ModelType)) { PropertyCriteria pageTypeCriteria = new PropertyCriteria(); pageTypeCriteria.Condition = CompareCondition.Equal; pageTypeCriteria.Value = pageType.ID.ToString(); pageTypeCriteria.Type = PropertyDataType.PageType; pageTypeCriteria.Name = "PageTypeID"; pageTypeCriteria.Required = false; criteria.Add(pageTypeCriteria); } } List<EventPageBase> eventList = new List<EventPageBase>(); var sites = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.Web.SiteDefinitionRepository>().List(); foreach (SiteDefinition siteDefinition in sites) { PageDataCollection allEvents = new PageDataCollection(); var allLanguages = ServiceLocator.Current.GetInstance<ILanguageBranchRepository>().ListEnabled(); foreach (LanguageBranch languageBranch in allLanguages) { allEvents.Add(DataFactory.Instance.FindPagesWithCriteria(siteDefinition.StartPage.ToPageReference(), criteria, languageBranch.LanguageID)); } foreach (PageData currentEvent in allEvents) { if (currentEvent as EventPageBase != null) eventList.Add(currentEvent as EventPageBase); } } return eventList; }
protected PageDataCollection SearchRelations() { string CacheKey = CurrentRule.Id.ToString() + "_" + CurrentPage.PageLink.ID+"_"+PageTypesDropDown.SelectedValue+"_"+_ruleDirection.ToString(); PageDataCollection pages = EPiServer.CacheManager.Get(CacheKey) as PageDataCollection; PageDataCollection result = new PageDataCollection(); if (pages == null || 1 == 1) { pages = RuleEngine.Instance.SearchRelations(CurrentRule, CurrentPage.PageLink.ID, SearchKeyWord.Text, IsLeftRule); if (PageTypesDropDown.SelectedValue.Length > 2) { foreach (PageData pd in pages) if (pd.PageTypeName == PageTypesDropDown.SelectedValue) result.Add(pd); } else result = pages; EPiServer.CacheManager.Add(CacheKey, result); } return result; }
protected override IEnumerable <IContent> GetContent(ContentQueryParameters parameters) { if (HttpContext.Current.Session != null) { HttpContext.Current.Session["ValidationResult"] = ""; } bool isLeftRule = (HttpUtility.HtmlDecode(parameters.AllParameters["direction"]) == "left"); var queryText = HttpUtility.HtmlDecode(parameters.AllParameters["queryText"]); var relationPageLeft = HttpUtility.HtmlDecode(parameters.AllParameters["relationPageLeft"]); string relationPageRightUrl = HttpUtility.HtmlDecode(parameters.AllParameters["relationPageRight"]); //string relationPageRight = ""; /* * if (!string.IsNullOrEmpty(relationPageRightUrl)) { * * Match match = regex.Match(HttpUtility.HtmlDecode(parameters.AllParameters["relationPageRight"])); * if (match.Success) * { * relationPageRight = (match.Groups[1].Value); * } * }*/ var relationRule = HttpUtility.HtmlDecode(parameters.AllParameters["relationRule"]); var action = HttpUtility.HtmlDecode(parameters.AllParameters["action"]); PageReference contextPage = (relationPageLeft != null) ? new PageReference(relationPageLeft) : null; PageDataCollection result = new PageDataCollection(); if (contextPage != null && relationPageLeft != null) { try { List <int> relations = new List <int>(); if (RuleEngine.Instance.GetRule(relationRule).RuleTextLeft == RuleEngine.Instance.GetRule(relationRule).RuleTextRight) { relations = RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule)); } else { relations = isLeftRule ? RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule), Rule.Direction.Left).Distinct <int>().ToList <int>() : RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule), Rule.Direction.Right).Distinct <int>().ToList <int>(); } foreach (int pageid in relations) { try { result.Add(PageEngine.GetPage(pageid)); } catch { Logging.Warning(string.Format("Error fetching page {0} related to {1}", pageid, contextPage.ID)); } } } catch { Logging.Warning(string.Format("Error fetching relations from page {0}", contextPage.ID)); } } return(result); }
/* public static PageDataCollection GetRelatedPagesRoundTripHierarchy(Rule rule, Relation relation, int pageID) { PageReference pr = new PageReference(pageID); PageData origPage = DataFactory.Instance.GetPage(pr); List<int> relationPages = RelationEngine.GetRelationsForPageRoundTripHierarchy(pageID, rule, relation); return PageIDListToPages(relationPages); }*/ /// <summary> /// Helper method for page relation getters to convert relations to pages. /// </summary> /// <param name="pageIDList">Collection of page IDs</param> /// <returns>Collection of pages</returns> public static PageDataCollection PageIDListToPages(List<int> pageIDList) { PageDataCollection pages = new PageDataCollection(); foreach (int pgid in pageIDList) { PageData pd = PageEngine.GetPage(pgid); if (pd != null && !pages.Contains(pd)) pages.Add(pd); } return pages; }
private static PageDataCollection GetPages(PageReference root) { //PropertyCriteriaCollection criterias = new PropertyCriteriaCollection(); //PropertyCriteria category = new PropertyCriteria(); //category.Condition = CompareCondition.NotEqual; //category.Value = "-1"; //category.Type = PropertyDataType.PageType; //category.Required = true; //category.Name = "PageTypeID"; //criterias.Add(category); if (!string.IsNullOrEmpty(SiteConfig.Instance.AdminUserName)) { EPiServer.Security.PrincipalInfo.CurrentPrincipal = EPiServer.Security.PrincipalInfo.CreatePrincipal(SiteConfig.Instance.AdminUserName); } // PageDataCollection objCollection = DataFactory.Instance.FindPagesWithCriteria(root, criterias, EPiServer.Security.AccessLevel.NoAccess); PageDataCollection objCollection = new PageDataCollection(); IList<PageReference> prList = DataFactory.Instance.GetDescendents(new PageReference(1)); foreach (PageReference pr in prList) { PageData pd = null; try { pd = DataFactory.Instance.GetPage(pr); if (pd.CheckPublishedStatus(PagePublishedStatus.Published) == true) { objCollection.Add(pd); } } catch (Exception) { } } FilterForVisitor.Filter(objCollection); return objCollection; }
private static Int32 CreateXMLSitemap(int[] rootPages, String path, String timeFormat, string baseUrl) { BaseURL = GetBaseUrl(); String sTimeFormat = timeFormat != String.Empty ? timeFormat : "yyyy-MM-dd"; PageDataCollection objCollection = new PageDataCollection(); foreach (int pageId in rootPages) { // Add root page objCollection.Add(DataFactory.Instance.GetPage(new PageReference(pageId))); foreach (PageData objPageData in GetPages(new PageReference(pageId))) { if (objPageData["PageShortcutType"] == null || (objPageData["PageShortcutType"] != null && ((EPiServer.Core.PageShortcutType)objPageData["PageShortcutType"]) != PageShortcutType.External)) { objCollection.Add(objPageData); } } } if (objCollection.Count == 0) return -1; XmlDocument xDoc = new XmlDocument(); XmlNode xNode = xDoc.CreateXmlDeclaration("1.0", "utf-8", null); xDoc.AppendChild(xNode); XmlNode xUrlSet = xDoc.CreateElement("urlset"); XmlAttribute xXMLNS = xDoc.CreateAttribute("xmlns"); xXMLNS.Value = "http://www.sitemaps.org/schemas/sitemap/0.9"; xUrlSet.Attributes.Append(xXMLNS); xDoc.AppendChild(xUrlSet); Int32 iCounter = 0; foreach (PageData objPageData in objCollection) { foreach (String sLanguage in objPageData.PageLanguages) { XmlNode xURLNode = xDoc.CreateElement("url"); XmlNode xLoc = xDoc.CreateElement("loc"); string friendlyURL = GetFriendlyURL(objPageData, sLanguage, baseUrl); XmlNode xURL = xDoc.CreateTextNode(friendlyURL); xLoc.AppendChild(xURL); xURLNode.AppendChild(xLoc); xUrlSet.AppendChild(xURLNode); XmlNode xPrio = xDoc.CreateElement("priority"); string url = xURL.InnerText; if (iCounter == 0) { xPrio.AppendChild(xDoc.CreateTextNode("1.000")); } //else if (xURL.InnerText == BaseURL + "/Behandlingsstod/" || xURL.InnerText == BaseURL + "/Patientadministration/" || xURL.InnerText == BaseURL + "/AvtalUppdrag/" || xURL.InnerText == BaseURL + "/utbildningutveckling/" || xURL.InnerText == BaseURL + "/AvtalUppdrag/IT-stod-och-e-tjanster/" || xURL.InnerText == BaseURL + "/Nyheter/Prenumerera/") //{ // xPrio.AppendChild(xDoc.CreateTextNode("0.9000")); //} else { xPrio.AppendChild(xDoc.CreateTextNode("0.5000")); } xURLNode.AppendChild(xPrio); iCounter++; } } xDoc.Save(path); //xDoc.Save(@"C:\inetpub\wwwroot\VGG7.local\web\sitemap.xml"); return iCounter; }
public override PageDataCollection SearchRelations(Rule rule, int pageID, string searchKeyWord, PageReference hierarchyStart, bool isLeftRule) { string pageTypes = HttpUtility.UrlDecode(isLeftRule ? rule.PageTypeRight : rule.PageTypeLeft); PageDataCollection result = new PageDataCollection(); if (!string.IsNullOrEmpty(pageTypes)) { string[] pageTypeCollection = pageTypes.Split(';'); PropertyCriteriaCollection pageTypeCriterias = new PropertyCriteriaCollection(); if (hierarchyStart == null || hierarchyStart == PageReference.EmptyReference) hierarchyStart = PageReference.RootPage; foreach (string s in pageTypeCollection) { if (!string.IsNullOrEmpty(s)) { PropertyCriteria criteria = new PropertyCriteria(); criteria.Condition = EPiServer.Filters.CompareCondition.Equal; criteria.Name = "PageTypeName"; criteria.Type = PropertyDataType.String; criteria.Value = s; pageTypeCriterias.Add(criteria); } } PageDataCollection pages = DataFactory.Instance.FindPagesWithCriteria(hierarchyStart, pageTypeCriterias); PageData rootPage = DataFactory.Instance.GetPage(hierarchyStart); if (pageTypeCollection.Contains<string>(rootPage.PageTypeName) && !pages.Contains(rootPage)) pages.Add(rootPage); new EPiServer.Filters.FilterSort(EPiServer.Filters.FilterSortOrder.Alphabetical).Sort(pages); if (!string.IsNullOrEmpty(searchKeyWord)) for (int i = 0; i < pages.Count; i++) { if (pages[i].PageName.ToLower().Contains(searchKeyWord.ToLower())) result.Add(pages[i]); } else result = pages; } return result; }
private static PageDataCollection GetAllPages(PageData parent, PageDataCollection allPages) { PageDataCollection children = DataFactory.Instance.GetChildren(parent.ContentLink.ToPageReference()); foreach (PageData pd in children) { allPages.Add(pd); GetAllPages(pd, allPages); } return allPages; }
public PageDataCollection GetPagesByTag(Tag tag, PageReference rootPageReference) { if (tag == null || tag.PermanentLinks == null) { return null; } IList<PageReference> descendantPageReferences = DataFactory.Instance.GetDescendents(rootPageReference); if (descendantPageReferences == null || descendantPageReferences.Count < 1) { return null; } var pages = new PageDataCollection(); foreach (Guid pageGuid in tag.PermanentLinks) { var pageReference = TagsHelper.GetPageReference(pageGuid); if (descendantPageReferences.FirstOrDefault(p => p.ID == pageReference.ID) != null) { pages.Add(DataFactory.Instance.GetPage(pageReference)); } } return pages; }
public void GetChildren_Generic_WithTwoParameters_ShouldReturnAnEnumerableWOfRequestedType() { using(ShimsContext.Create()) { PageDataCollection pageDataCollection = new PageDataCollection(); int items = DateTime.Now.Millisecond; if(items%2 == 1) items++; for(int i = 0; i < items; i++) { Mock<PageData> pageDataMock = new Mock<PageData>(); if(i%2 == 0) pageDataMock.As<IContentData>(); pageDataCollection.Add(pageDataMock.Object); } ShimDataFactory.StaticConstructor = () => { }; Mock<DataFactoryWrapper> dataFactoryWrapperMock = new Mock<DataFactoryWrapper>(new object[] {new DataFactory(), Mock.Of<IPageDataCaster>(), Mock.Of<IPermanentLinkMapper>()}) {CallBase = true}; dataFactoryWrapperMock.Setup(dataFactoryWrapper => dataFactoryWrapper.GetChildren(It.IsAny<PageReference>(), It.IsAny<ILanguageSelector>())).Returns(pageDataCollection); IEnumerable<IContentData> children = dataFactoryWrapperMock.Object.GetChildren<IContentData>(new ContentReference(DateTime.Now.Millisecond), Mock.Of<ILanguageSelector>()); Assert.AreEqual(items/2, children.Count()); } }
/// <summary> /// Returns a PageDataCollection with a distinct list of pages related through the given rule. Number of relations are added to PageName. /// </summary> /// <param name="allPages">PageDataCollection to create facets from</param> /// <param name="ruleName">Rule used for facet relations</param> /// <param name="direction">Direction of facet relations</param> /// <returns></returns> public static PageDataCollection FacetList(PageDataCollection allPages, string ruleName, Rule.Direction direction) { List<Relation> relations = RelationEngine.Instance.GetAllRelations(ruleName); List<int> facets; if (direction == Rule.Direction.Right) { facets = (from id in relations select id.PageIDRight).Distinct().ToList(); } else { facets = (from id in relations select id.PageIDLeft).Distinct().ToList(); } PageDataCollection facetPages = PageHelper.PageIDListToPages(facets); PageDataCollection facetsWithCount = new PageDataCollection(); foreach (PageData facetPage in facetPages) { PageData writableFacet = facetPage.CreateWritableClone(); if (direction == Rule.Direction.Right) { writableFacet.PageName = writableFacet.PageName + " (" + (from id in relations where id.PageIDRight == facetPage.PageLink.ID select id) .Count() + ")"; } else { writableFacet.PageName = writableFacet.PageName + " (" + (from id in relations where id.PageIDLeft == facetPage.PageLink.ID select id) .Count() + ")"; } facetsWithCount.Add(writableFacet); } new EPiServer.Filters.FilterSort(FilterSortOrder.Alphabetical).Sort(facetsWithCount); return facetsWithCount; }
private PageDataCollection GetItems() { var items = new PageDataCollection(); PageData currentItem = CurrentPage.ToPageData(); AddParentIfRequired(currentItem, items); items.ForVisitor(); if (!ShowPagesNotVisibleInMenu) items.VisibleInMenu(); items.Add(currentItem); return items; }
private static Int32 CreateSitemap(PageReference Start, String Path, String TimeFormat) { BaseURL = GetBaseUrl(); String sTimeFormat = TimeFormat != String.Empty ? TimeFormat : "yyyy-MM-dd"; PageDataCollection objCollection = new PageDataCollection(); // Add start page objCollection.Add(DataFactory.Instance.GetPage(Start)); foreach (PageData objPageData in GetPages()) { if (objPageData["PageShortcutType"] == null || (objPageData["PageShortcutType"] != null && ((EPiServer.Core.PageShortcutType)objPageData["PageShortcutType"]) != PageShortcutType.External)) { objCollection.Add(objPageData); } } XmlDocument xDoc = new XmlDocument(); XmlNode xNode = xDoc.CreateXmlDeclaration("1.0", "utf-8", null); xDoc.AppendChild(xNode); XmlNode xURLSet = xDoc.CreateElement("urlset"); XmlAttribute xXMLNS = xDoc.CreateAttribute("xmlns"); xXMLNS.Value = "http://www.sitemaps.org/schemas/sitemap/0.9"; xURLSet.Attributes.Append(xXMLNS); xDoc.AppendChild(xURLSet); Int32 iCounter = 0; foreach (PageData objPageData in objCollection) { foreach (String sLanguage in objPageData.PageLanguages) { XmlNode xURLNode = xDoc.CreateElement("url"); XmlNode xLoc = xDoc.CreateElement("loc"); XmlNode xURL = xDoc.CreateTextNode(GetFriendlyURL(objPageData, sLanguage)); xLoc.AppendChild(xURL); xURLNode.AppendChild(xLoc); XmlNode xLastMod = xDoc.CreateElement("lastmod"); xLastMod.AppendChild(xDoc.CreateTextNode(objPageData.Saved.ToString(sTimeFormat))); xURLNode.AppendChild(xLastMod); // Optional change frequency if (objPageData["ChangeFrequency"] != null && objPageData["ChangeFrequency"].ToString() != String.Empty) { XmlNode xChangeFrequency = xDoc.CreateElement("changefreq"); xChangeFrequency.AppendChild(xDoc.CreateTextNode(objPageData["ChangeFrequency"].ToString())); xURLNode.AppendChild(xChangeFrequency); } // Optional priority if (objPageData["Priority"] != null && objPageData["Priority"].ToString() != String.Empty) { XmlNode xPriority = xDoc.CreateElement("priority"); xPriority.AppendChild(xDoc.CreateTextNode(objPageData["Priority"].ToString())); xURLNode.AppendChild(xPriority); } xURLSet.AppendChild(xURLNode); iCounter++; } } xDoc.Save(Path); return iCounter; }