public void Test_can_map_query_condition_to_property_criteria() { // Arrange CmsqlQueryCondition condition = new CmsqlQueryCondition { Identifier = "PageName", Operator = EqualityOperator.GreaterThan, Value = "5" }; CmsqlExpressionVisitorContext context = new CmsqlExpressionVisitorContext(new ContentType()); CmsqlExpressionVisitor cmsqlExpressionVisitor = new CmsqlExpressionVisitor( new QueryConditionToPropertyCriteriaMapper( new PropertyDataTypeResolver(new ContentType())), context); // Act cmsqlExpressionVisitor.VisitQueryCondition(condition); PropertyCriteriaCollection propertyCriteriaCollection = context.GetCriteria().Single(); PropertyCriteria propertyCriteria = propertyCriteriaCollection.Last(); // Assert propertyCriteria.Value.ShouldBeEquivalentTo(condition.Value); propertyCriteria.Condition.ShouldBeEquivalentTo(CompareCondition.GreaterThan); propertyCriteria.Name.ShouldBeEquivalentTo(condition.Identifier); }
public static IEnumerable <T> GetDescendants <T>(this PageData page) { var repository = ServiceLocator.Current.GetInstance <IContentTypeRepository>(); var contentType = repository.Load(typeof(T)); int?pageTypeID = contentType.ID; if (pageTypeID.HasValue) { PropertyCriteria pageTypeCriteria = new PropertyCriteria { Condition = CompareCondition.Equal, Name = "PageTypeID", Type = PropertyDataType.PageType, Value = pageTypeID.Value.ToString() }; PropertyCriteriaCollection criterias = new PropertyCriteriaCollection { pageTypeCriteria }; var pageCriteriaQueryService = ServiceLocator.Current .GetInstance <IPageCriteriaQueryService>(); var descendants = pageCriteriaQueryService .FindPagesWithCriteria(page.ContentLink.ToPageReference(), criterias).Cast <T>(); return(descendants); } return(null); }
public NotificationSettings GetNotificationSettings(string language = null) { var contentTypeRepository = ServiceLocator.Current.GetInstance <EPiServer.DataAbstraction.IContentTypeRepository>(); var pageCriteriaQueryService = ServiceLocator.Current.GetInstance <IPageCriteriaQueryService>(); var criterias = new PropertyCriteriaCollection(); var criteria = new PropertyCriteria(); criteria.Condition = EPiServer.Filters.CompareCondition.Equal; criteria.Name = "PageTypeID"; criteria.Type = PropertyDataType.PageType; criteria.Value = contentTypeRepository.Load("NotificationSettings").ID.ToString(); criteria.Required = true; criterias.Add(criteria); // TODO: We should not search for settings, point to it from the start page instead. PageData page; if (language == null) { page = pageCriteriaQueryService.FindPagesWithCriteria(ContentReference.StartPage, criterias).FirstOrDefault(); } else { page = pageCriteriaQueryService.FindPagesWithCriteria(ContentReference.StartPage, criterias, language).FirstOrDefault(); } if (page is NotificationSettings) { return((NotificationSettings)page); } return(null); }
internal bool TryMap(CmsqlQueryCondition condition, out PropertyCriteria criteria) { criteria = null; if (condition == null) { return(false); } if (!_propertyDataTypeResolver.TryResolve(condition.Identifier, out PropertyDataType propertyDataType)) { return(false); } CompareCondition compareCondition = MapEqualityOperatorToCompareCondition(condition.Operator); criteria = new PropertyCriteria { Condition = compareCondition, Value = condition.Value, Name = condition.Identifier, Type = propertyDataType, Required = true }; return(true); }
public virtual PageDataCollection List(PageReference pageLink) { // Using functionality from // http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/9/Search/Searching-for-pages-based-on-page-type/ string pageTypeId = _pageTypeRepository.Load<StandardPage>()?.ID.ToString(); if (pageTypeId == null) { return new PageDataCollection(); } PropertyCriteria productPageTypeCriterion = new PropertyCriteria { Name = "PageTypeID", Type = PropertyDataType.PageType, Value = pageTypeId, Condition = CompareCondition.Equal, Required = true }; var criteria = new PropertyCriteriaCollection { productPageTypeCriterion }; PageDataCollection pageDataCollection = _searchPages.FindPagesWithCriteria(pageLink, criteria); return pageDataCollection; }
public NotificationSettings GetNotificationSettings(string language = null) { var contentTypeRepository = ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.IContentTypeRepository>(); var pageCriteriaQueryService = ServiceLocator.Current.GetInstance<IPageCriteriaQueryService>(); var criterias = new PropertyCriteriaCollection(); var criteria = new PropertyCriteria(); criteria.Condition = EPiServer.Filters.CompareCondition.Equal; criteria.Name = "PageTypeID"; criteria.Type = PropertyDataType.PageType; criteria.Value = contentTypeRepository.Load("NotificationSettings").ID.ToString(); criteria.Required = true; criterias.Add(criteria); // TODO: We should not search for settings, point to it from the start page instead. PageData page; if (language == null) { page = pageCriteriaQueryService.FindPagesWithCriteria(ContentReference.StartPage, criterias).FirstOrDefault(); } else { page = pageCriteriaQueryService.FindPagesWithCriteria(ContentReference.StartPage, criterias, language).FirstOrDefault(); } if (page is NotificationSettings) { return (NotificationSettings)page; } return null; }
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); }
internal void AddPropertyCriteria(PropertyCriteria propertyCriteria) { Debug.Assert(propertyCriteria != null); if (!_propertyCriteriaCollectionStack.Any()) { PushNewPropertyCriteriaCollection(); } _propertyCriteriaCollectionStack.Peek().Add(propertyCriteria); }
/// <summary> /// Creates a PropertyCriteria. /// </summary> /// <param name="condition">The condition for the comparison.</param> /// <param name="name">The name of the property.</param> /// <param name="dataType">Type of property data.</param> /// <param name="value">The value to evalute the property against.</param> /// <param name="required">If set to <c>true</c> the criteria is required, which makes it an AND search.</param> /// <returns></returns> public static PropertyCriteria CreateCriteria(CompareCondition condition, string name, PropertyDataType dataType, string value, bool required) { PropertyCriteria criteria = new PropertyCriteria(); criteria.Condition = condition; criteria.Name = name; criteria.Type = dataType; criteria.Value = value; criteria.Required = required; return(criteria); }
public PageDataCollection List(PageReference pageLink) { string key = CachedFindPagesWithCriterion.GetCacheKey(pageLink.ToReferenceWithoutVersion()); var standardPages = _synchronizedObjectInstanceCache.Get(key) as PageDataCollection; if (standardPages == null) { object miniLock = MiniLocks.GetOrAdd(key, k => new object()); lock (miniLock) { standardPages = _synchronizedObjectInstanceCache.Get(key) as PageDataCollection; if (standardPages == null) { string pageTypeId = _pageTypeRepository.Load<StandardPage>()?.ID.ToString(); if (pageTypeId == null) { return new PageDataCollection(); } PropertyCriteria productPageTypeCriterion = new PropertyCriteria { Name = "PageTypeID", Type = PropertyDataType.PageType, Value = pageTypeId, Condition = CompareCondition.Equal, Required = true }; var criteria = new PropertyCriteriaCollection { productPageTypeCriterion }; standardPages = _searchPages.FindPagesWithCriteria(pageLink, criteria); Thread.Sleep(5000); _synchronizedObjectInstanceCache.Insert(key, standardPages, CacheEvictionPolicy.Empty); // Saving some space we will release the lock object temp1; if (MiniLocks.TryGetValue(key, out temp1) && (temp1 == miniLock)) { object temp2; MiniLocks.TryRemove(key, out temp2); } } } } return standardPages; }
public override void ProcessRequest(HttpContext context) { PropertyCriteriaCollection criterias = new PropertyCriteriaCollection(); PropertyCriteria criteria = new PropertyCriteria(); criteria.Condition = CompareCondition.Equal; criteria.Name = "PageTypeID"; criteria.Type = PropertyDataType.PageType; criteria.Value = Locate.ContentTypeRepository().Load("HotelDetailPage").ID.ToString(); criteria.Required = true; criterias.Add(criteria); PageDataCollection _newsPageItems = Locate.PageCriteriaQueryService().FindPagesWithCriteria(PageReference.StartPage, criterias); }
private void RetrieveSiteProductPages() { PropertyCriteriaCollection criteria = new PropertyCriteriaCollection(); PropertyCriteria prodpagecriterion = new PropertyCriteria(); prodpagecriterion.Condition = EPiServer.Filters.CompareCondition.Equal; prodpagecriterion.Name = "PageTypeID"; prodpagecriterion.Type = PropertyDataType.PageType; prodpagecriterion.Value = ServiceLocator.Current.GetInstance <IContentTypeRepository>().Load("ProductPage").ID.ToString(); prodpagecriterion.Required = true; criteria.Add(prodpagecriterion); productPages = ServiceLocator.Current.GetInstance <IPageCriteriaQueryService>().FindPagesWithCriteria(PageReference.StartPage, criteria); }
public static void SetPagesForPageTypeName(ExistingPagesReportViewModel model) { var criterias = new PropertyCriteriaCollection(); var criteria = new PropertyCriteria(); criteria.Condition = CompareCondition.Equal; criteria.Name = "PageTypeID"; criteria.Type = PropertyDataType.PageType; criteria.Value = model.SelectedPageType; criteria.Required = true; criterias.Add(criteria); var pages = DataFactory.Instance.FindPagesWithCriteria(ContentReference.RootPage, criterias); model.Pages = pages; }
public PageDataCollection List(PageReference pageLink) { string cacheKey = CachedFindPagesWithCriterion.GetCacheKey(pageLink.ToReferenceWithoutVersion()); var standardPages = _synchronizedObjectInstanceCache.Get(cacheKey) as PageDataCollection; if (standardPages == null) { lock (Lock) { // Check cache again since standardPages might have been cached while waiting for the lock to open standardPages = _synchronizedObjectInstanceCache.Get(cacheKey) as PageDataCollection; if (standardPages == null) { string pageTypeId = _pageTypeRepository.Load<StandardPage>()?.ID.ToString(); if (pageTypeId == null) { return new PageDataCollection(); } PropertyCriteria productPageTypeCriterion = new PropertyCriteria { Name = "PageTypeID", Type = PropertyDataType.PageType, Value = pageTypeId, Condition = CompareCondition.Equal, Required = true }; var criteria = new PropertyCriteriaCollection { productPageTypeCriterion }; standardPages = _searchPages.FindPagesWithCriteria(pageLink, criteria); Thread.Sleep(5000); _synchronizedObjectInstanceCache.Insert(cacheKey, standardPages, CacheEvictionPolicy.Empty); } } } return standardPages; }
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); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); PropertyCriteriaCollection pcc = new PropertyCriteriaCollection(); PropertyCriteria pc = new PropertyCriteria { Name = "PageChanged", Value = DateTime.Now.Subtract(TimeSpan.FromHours(CorrectHoursPropertyValue())).ToString(), Condition = CompareCondition.GreaterThan, Type = PropertyDataType.Date }; pcc.Add(pc); var pdc = DataFactory.Instance.FindPagesWithCriteria(CurrentPage["RecentContainer"] as PageReference ?? PageReference.StartPage, pcc); pagelist.DataSource = FilterForVisitor.Filter(pdc); pagelist.DataBind(); }
public PageDataCollection GetPagesByPageType(string pageType) { var criterias = new PropertyCriteriaCollection(); var criteria = new PropertyCriteria { Condition = CompareCondition.Equal, Name = "PageTypeID", Type = PropertyDataType.PageType, Value = pageType, Required = true, }; criterias.Add(criteria); var pages = _queryService.FindPagesWithCriteria(ContentReference.RootPage, criterias); return(pages); }
/// <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"; }
private List <PageData> FindPagesContainSearchQuery(string searchQuery) { PropertyCriteriaCollection propertyCriteriaCollection = new PropertyCriteriaCollection(); PropertyCriteria propertyCriteria = new PropertyCriteria() { Name = "PageName", Type = PropertyDataType.String, Condition = Filters.CompareCondition.Contained, Required = true, Value = searchQuery }; propertyCriteriaCollection.Add(propertyCriteria); List <PageData> results = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, propertyCriteriaCollection).ToList <PageData>(); return(results); }
/// <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"); }
protected virtual LocalizationContainer FindLocalizationContainer(ILanguageSelector languageSelector) { var rootPage = ContentReference.RootPage; if (rootPage == null) { // the GetString method is called before EPiServer is fully initialized. // If this is the case we are not able to return any resources since we depend on the epi cms api return(null); } try { var criteria = new PropertyCriteria { Condition = CompareCondition.Equal, Value = typeof(LocalizationContainer).Name, Required = true, Name = "PageTypeName", Type = PropertyDataType.PageType }; var localizationPages = DataFactory.Instance.FindPagesWithCriteria(rootPage, new PropertyCriteriaCollection { criteria }, null, languageSelector); if (localizationPages.Count > 1) { throw new InvalidOperationException("The cms tree contains more then 1 instance of the Localizations container this is not allowed"); } return((LocalizationContainer)localizationPages.FirstOrDefault()); } catch (ContentProviderNotFoundException) { // the GetString method is called before EPiServer is fully initialized. // If this is the case we are not able to return any resources since we depend on the epi cms api return(null); } }
public PageDataCollection List(PageReference pageLink) { string cacheKey = GetCacheKey(pageLink.ToReferenceWithoutVersion()); var standardPages = _synchronizedObjectInstanceCache.Get(cacheKey) as PageDataCollection; if (standardPages == null) { string pageTypeId = _pageTypeRepository.Load<StandardPage>()?.ID.ToString(); if (pageTypeId == null) { return new PageDataCollection(); } PropertyCriteria productPageTypeCriterion = new PropertyCriteria { Name = "PageTypeID", Type = PropertyDataType.PageType, Value = pageTypeId, Condition = CompareCondition.Equal, Required = true }; var criteria = new PropertyCriteriaCollection { productPageTypeCriterion }; standardPages = _searchPages.FindPagesWithCriteria(pageLink, criteria); // Lots of things can happen while fetching the cache Thread.Sleep(1000); // Actually caching the ContentData is not a good practice. Caching the ContentReference is better _synchronizedObjectInstanceCache.Insert(cacheKey, standardPages, CacheEvictionPolicy.Empty); } return standardPages; }
/// <summary> /// Method for retrieving all pages passed by a page type id /// </summary> /// <returns>Returns pages for each page type given by pagetypeid</returns> private static IEnumerable <PageData> GetAllPagesOfPageType(int id) { var pageTypeId = id; var repository = ServiceLocator.Current.GetInstance <IPageCriteriaQueryService>(); var pageTypeCriteria = new PropertyCriteria { Name = "PageTypeID", Type = PropertyDataType.PageType, Value = pageTypeId.ToString(), Condition = CompareCondition.Equal, Required = true }; var criteria = new PropertyCriteriaCollection { pageTypeCriteria }; var currentCulture = ContentLanguage.PreferredCulture; var languageBranch = currentCulture.Name; var pageDataCollection = repository. FindAllPagesWithCriteria(ContentReference.RootPage, criteria, languageBranch, LanguageSelector.AutoDetect(true)); if (pageDataCollection != null) { var sortedPageDataCollection = pageDataCollection.OrderByDescending(c => c.StartPublish); return(sortedPageDataCollection); } return(pageDataCollection); }
protected virtual LocalizationContainer FindLocalizationContainer(ILanguageSelector languageSelector) { var rootPage = ContentReference.RootPage; if (rootPage == null) { // the GetString method is called before EPiServer is fully initialized. // If this is the case we are not able to return any resources since we depend on the epi cms api return null; } try { var criteria = new PropertyCriteria { Condition = CompareCondition.Equal, Value = typeof(LocalizationContainer).Name, Required = true, Name = "PageTypeName", Type = PropertyDataType.PageType }; var localizationPages = DataFactory.Instance.FindPagesWithCriteria(rootPage, new PropertyCriteriaCollection {criteria}, null, languageSelector); if(localizationPages.Count > 1) throw new InvalidOperationException("The cms tree contains more then 1 instance of the Localizations container this is not allowed"); return (LocalizationContainer) localizationPages.FirstOrDefault(); } catch (ContentProviderNotFoundException) { // the GetString method is called before EPiServer is fully initialized. // If this is the case we are not able to return any resources since we depend on the epi cms api return null; } }
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; }
private static PageDataCollection GetPages() { 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); PageDataCollection objCollection = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, criterias); FilterForVisitor.Filter(objCollection); var pageTypeLimitter = new SitemapFilter(NOT_ALLOWED_PAGETYPES); pageTypeLimitter.Filter(objCollection); return objCollection; }
private List<PageData> FindPagesContainSearchQuery(string searchQuery) { PropertyCriteriaCollection propertyCriteriaCollection = new PropertyCriteriaCollection(); PropertyCriteria propertyCriteria = new PropertyCriteria() { Name = "PageName", Type = PropertyDataType.String, Condition = Filters.CompareCondition.Contained, Required = true, Value = searchQuery }; propertyCriteriaCollection.Add(propertyCriteria); List<PageData> results = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, propertyCriteriaCollection).ToList<PageData>(); return results; }
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; }
protected string GetPagesUnfiltered(DateTime since) { PropertyCriteriaCollection col = new PropertyCriteriaCollection(); PageData pageroot; //Restrict Pagetypes var repository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.PageTypeRepository>(); //Start : for News Page page //For Fetching the News Page PropertyCriteria criteria = new PropertyCriteria(); //criteria = new PropertyCriteria(); criteria.Condition = CompareCondition.Equal; criteria.Name = "PageTypeID"; criteria.Type = PropertyDataType.PageType; // set pagetype to be deleted criteria.Value = repository.Load(typeof(PropertiesSeperator)).ID.ToString(); //criteria.Required = true; col.Add(criteria); //Fetching News Page with Date Criteria PropertyCriteria criteria1 = new PropertyCriteria(); //criteria = new PropertyCriteria(); criteria1.Condition = CompareCondition.LessThan; criteria1.Name = "PageCreated"; criteria1.Type = PropertyDataType.Date; criteria1.Value = since.ToString(); criteria.Required = true; col.Add(criteria1); //End : for News page // find key in config file PageDataCollection pageList = DataFactory.Instance.FindPagesWithCriteria(new PageReference(ConfigurationManager.AppSettings["ArchiveStartPage"]), col); // return pageList; //Check if there is any pages that matches the criteria if (pageList.Count >= 1) { //Creating the folder with reference to the start page //PageReference parent = new PageReference(ConfigurationManager.AppSettings["DestinationRootFolder"]); PageReference parent = new PageReference(1); PropertiesSeperator containerPage = DataFactory.Instance.GetDefault<PropertiesSeperator>(parent); //containerPage.PageName = ConfigurationManager.AppSettings["DestinationfolderName"]; containerPage.PageName = ConfigurationManager.AppSettings["DestinationfolderName"]; var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); //var startPage = contentRepository.Get<StartPage>(ContentReference.StartPage); var repository1 = ServiceLocator.Current.GetInstance<IContentRepository>(); PageDataCollection children = DataFactory.Instance.GetChildren(parent); //Check if the Destinationfolder exist var RootFolder = children.Where(p => p.Name == ConfigurationManager.AppSettings["DestinationfolderName"] && p.PageTypeName == typeof(PropertiesSeperator).Name); //If destination folder does not exist than create the folder if (RootFolder.Count() < 1) { var PublishRootFolder = DataFactory.Instance.Save(containerPage, SaveAction.Publish, AccessLevel.NoAccess); pageroot = new PageData(PublishRootFolder); } else { pageroot = RootFolder.FirstOrDefault(); } PageDataCollection children1 = DataFactory.Instance.GetChildren(pageroot.ContentLink as PageReference); //looping through each page which are 6 months older foreach (var page in pageList) { var year = page.Created.Year; var Yearcheck = DataFactory.Instance.GetChildren(pageroot.ContentLink as PageReference); var existyr = Yearcheck.Where(p => p.Name == year.ToString() && p.PageTypeName == typeof(PropertiesSeperator).Name); //if year does not exist than create the year if (existyr.Count() < 1) { PropertiesSeperator containerPage1 = DataFactory.Instance.GetDefault<PropertiesSeperator>(pageroot.ContentLink as PageReference); containerPage1.PageName = year.ToString(); var savedyr = DataFactory.Instance.Save(containerPage1, SaveAction.Publish, AccessLevel.NoAccess); var month = page.Created.Month; int iMonthNo = month; DateTime dtDate = new DateTime(2000, iMonthNo, 1); string sMonthFullName = dtDate.ToString("MMMM"); PropertiesSeperator containerPage2 = DataFactory.Instance.GetDefault<PropertiesSeperator>(savedyr); containerPage2.PageName = sMonthFullName.ToString(); var savedmonth = DataFactory.Instance.Save(containerPage2, SaveAction.Publish, AccessLevel.NoAccess); DataFactory.Instance.Move(page.ContentLink as PageReference, savedmonth); } else { var pagemonth = page.Created.Month; int iMonthNo = pagemonth; DateTime dtDate = new DateTime(2000, iMonthNo, 1); string sMonthFullName = dtDate.ToString("MMMM"); var Monthcheck = DataFactory.Instance.GetChildren(existyr.FirstOrDefault().ContentLink as PageReference); var existMONTH = Monthcheck.Where(p => p.Name == sMonthFullName.ToString() && p.PageTypeName == typeof(PropertiesSeperator).Name); //check if month exist if (existMONTH.Count() < 1) { PropertiesSeperator containerPage3 = DataFactory.Instance.GetDefault<PropertiesSeperator>(existyr.FirstOrDefault().ContentLink as PageReference); containerPage3.PageName = sMonthFullName.ToString(); var curretnsaveddmonth = DataFactory.Instance.Save(containerPage3, SaveAction.Publish, AccessLevel.NoAccess); DataFactory.Instance.Move(page.ContentLink as PageReference, curretnsaveddmonth); } else { DataFactory.Instance.Move(page.ContentLink as PageReference, existMONTH.FirstOrDefault().ContentLink as PageReference); } } } //Delete 15 months older pages //DateTime delete = DateTime.Now.AddMonths(-15); //PropertyCriteriaCollection listpagepropdelete = new PropertyCriteriaCollection(); //PropertyCriteria Listcriteriadelete = new PropertyCriteria(); //Listcriteriadelete.Condition = CompareCondition.LessThan; //Listcriteriadelete.Name = "PageCreated"; //Listcriteriadelete.Type = PropertyDataType.Date; //Listcriteriadelete.Value = delete.ToString(); //Listcriteriadelete.Required = true; //listpagepropdelete.Add(Listcriteriadelete); //PageDataCollection pageListForNewsPageDelete = DataFactory.Instance.FindPagesWithCriteria(pageroot.ContentLink as PageReference, listpagepropdelete); //foreach (var pageDelete in pageListForNewsPageDelete) //{ // DataFactory.Instance.Delete(pageDelete.ContentLink, true); //} return "Job Executed successfully"; } return "There are no pages to move"; }
public PathResolver(PropertyCriteria selector, BasePathSource basePathSource) : this() { Selector = selector; BasePathSource = basePathSource; }