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;
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <summary>
        /// Gets pages by a specific PageTypeId under a certain starting point.
        /// </summary>
        /// <param name="startPageReference">The page reference used as a starting point for the search.</param>
        /// <param name="pageTypeId">The page type id to search for.</param>
        /// <returns>A PageDataCollection containing all pages below the startPageReference of the page type pageTypeId.</returns>
        private static PageDataCollection GetPages(PageReference startPageReference, int pageTypeId)
        {
            PropertyCriteriaCollection pcc = new PropertyCriteriaCollection();

            pcc.Add(BlogUtility.CreateCriteria(CompareCondition.Equal, "PageTypeID", PropertyDataType.PageType, pageTypeId.ToString(CultureInfo.InvariantCulture), true));
            return(DataFactory.Instance.FindPagesWithCriteria(startPageReference, pcc));
        }
Пример #4
0
        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);
        }
Пример #5
0
        private static IEnumerable <PageData> FindPagesByPageTypeRecursively(ContentReference pageLink, int pageTypeId)
        {
            var criteria = new PropertyCriteriaCollection
            {
                new PropertyCriteria
                {
                    Name      = "PageTypeID",
                    Type      = PropertyDataType.PageType,
                    Condition = CompareCondition.Equal,
                    Value     = pageTypeId.ToString(CultureInfo.InvariantCulture)
                }
            };

            if (!ProviderManager.Value.ProviderMap.CustomProvidersExist)
            {
                return(PageCriteriaQueryService.Value.FindPagesWithCriteria(pageLink.ToPageReference(), criteria));
            }

            var contentProvider = ProviderManager.Value.ProviderMap.GetProvider(pageLink);

            if (contentProvider.HasCapability(ContentProviderCapabilities.Search))
            {
                criteria.Add(new PropertyCriteria
                {
                    Name  = "EPI:MultipleSearch",
                    Value = contentProvider.ProviderKey
                });
            }

            return(PageCriteriaQueryService.Value.FindPagesWithCriteria(pageLink.ToPageReference(), criteria));
        }
Пример #6
0
        // Type specified through page type ID
        private IEnumerable <PageData> FindPagesByPageTypeRecursively(PageReference pageLink, int pageTypeId)
        {
            var criteria = new PropertyCriteriaCollection
            {
                new PropertyCriteria
                {
                    Name      = "PageTypeID",
                    Type      = PropertyDataType.PageType,
                    Condition = CompareCondition.Equal,
                    Value     = pageTypeId.ToString(CultureInfo.InvariantCulture)
                }
            };

            // Include content providers serving content beneath the page link specified for the search
            if (_providerManager.ProviderMap.CustomProvidersExist)
            {
                var contentProvider = _providerManager.ProviderMap.GetProvider(pageLink);

                if (contentProvider.HasCapability(ContentProviderCapabilities.Search))
                {
                    criteria.Add(new PropertyCriteria
                    {
                        Name  = "EPI:MultipleSearch",
                        Value = contentProvider.ProviderKey
                    });
                }
            }

            return(_pageCriteriaQueryService.FindPagesWithCriteria(pageLink, criteria));
        }
Пример #7
0
        private void IphoneChecker(object sender, ContentEventArgs e)
        {
            var repo   = ServiceLocator.Current.GetInstance <IContentRepository>();
            var finder = ServiceLocator.Current
                         .GetInstance <IPageCriteriaQueryService>();
            int pageCount = 0;

            var criteria = new PropertyCriteriaCollection();

            criteria.Add(new PropertyCriteria
            {
                Type      = PropertyDataType.LongString,
                Name      = "PageName",
                Condition = EPiServer.Filters.CompareCondition.Contained,
                Value     = "iphone"
            });
            criteria.Add(new PropertyCriteria
            {
                Type      = PropertyDataType.LongString,
                Name      = "MetaTitle",
                Condition = EPiServer.Filters.CompareCondition.Contained,
                Value     = "iphone"
            });
            criteria.Add(new PropertyCriteria
            {
                Type      = PropertyDataType.LongString,
                Name      = "MetaDescription",
                Condition = EPiServer.Filters.CompareCondition.Contained,
                Value     = "iphone"
            });
            PageDataCollection results = finder.FindPagesWithCriteria(
                ContentReference.RootPage as PageReference, criteria);

            foreach (SitePageData page in results)
            {
                var clone = page.CreateWritableClone() as SitePageData;
                clone.Name            = page.Name.Replace("iphone", "[censored]");
                clone.MetaTitle       = page.MetaTitle?.Replace("iphone", "[censored]");
                clone.MetaDescription =
                    page.MetaDescription?.Replace("iphone", "[censored]");
                repo.Save(clone,
                          EPiServer.DataAccess.SaveAction.CheckIn,
                          EPiServer.Security.AccessLevel.NoAccess);
                pageCount++;
            }
        }
Пример #8
0
        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);
        }
Пример #9
0
        public static IEnumerable <PageData> FindPages(string pageTypeId)
        {
            var criteria = new PropertyCriteriaCollection();

            if (FilterStrategy.ShouldFilterOnPageType(pageTypeId))
            {
                criteria.Add(PropertyCriteriaGenerator.ForPageType(pageTypeId));
            }

            return(DataFactory.Instance.FindPagesWithCriteria(PageReference.RootPage, criteria));
        }
Пример #10
0
        public static IEnumerable<PageData> FindPages(string pageTypeId)
        {
            var criteria = new PropertyCriteriaCollection();

            if (FilterStrategy.ShouldFilterOnPageType(pageTypeId))
            {
                criteria.Add(PropertyCriteriaGenerator.ForPageType(pageTypeId));
            }

            return DataFactory.Instance.FindPagesWithCriteria(PageReference.RootPage, criteria);
        }
Пример #11
0
        /// <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()
        {
            OnStatusChanged(string.Format("Starting execution of {0}", this.GetType()));

            var repo = ServiceLocator.Current.GetInstance <IContentRepository>();

            var finder = ServiceLocator.Current.GetInstance <IPageCriteriaQueryService>();

            var criteria = new PropertyCriteriaCollection();

            criteria.Add(new PropertyCriteria
            {
                Type      = PropertyDataType.LongString,
                Name      = "MetaDescription",
                Condition = EPiServer.Filters.CompareCondition.Contained,
                Value     = "iWatch"
            });

            criteria.Add(new PropertyCriteria
            {
                Type      = PropertyDataType.LongString,
                Name      = "MainIntro",
                Condition = EPiServer.Filters.CompareCondition.Contained,
                Value     = "iWatch"
            });

            PageDataCollection results =
                finder.FindPagesWithCriteria(ContentReference.RootPage as PageReference, criteria);

            foreach (PageData page in results)
            {
                //For long running jobs periodically check if stop is signaled and if so stop execution
                if (_stopSignaled)
                {
                    return("Stop of job was called");
                }
            }

            return("All content containing iWatch has been changed to Apple Watch.");
        }
Пример #12
0
        /// <summary>
        /// Sets the search criterias to find the blog items used for the listing.
        /// Uses the properties IsTagListing, IsDateListing and IsTeamLevel to determine what criterias to set up.
        /// </summary>
        private void SetSearchCriterias()
        {
            if (CurrentPage[BlogUtility.IsTagListingPropertyName] != null)
            {
                _criterias.Add(BlogUtility.CreateCriteria(CompareCondition.Equal, "PageTypeName", PropertyDataType.PageType, BlogUtility.ItemPageTypeName, true));
                _criterias.Add(BlogUtility.CreateCriteria(CompareCondition.Equal, "PageCategory", PropertyDataType.Category, CurrentPage.PageName, true));

                _searchStart = (PageReference)CurrentPage[BlogUtility.StartPropertyName];
            }
            else if (CurrentPage[BlogUtility.IsDateListingPropertyName] != null && CurrentPage[BlogUtility.IsTeamLevelPropertyName] == null)
            {
                _criterias.Add(BlogUtility.CreateCriteria(CompareCondition.Equal, "PageTypeName", PropertyDataType.PageType, BlogUtility.ItemPageTypeName, true));

                _searchStart = CurrentPageLink;
            }
            else if (CurrentPage[BlogUtility.IsDateListingPropertyName] != null && CurrentPage[BlogUtility.IsTeamLevelPropertyName] != null)
            {
                _criterias.Add(BlogUtility.CreateCriteria(CompareCondition.Equal, "PageTypeName", PropertyDataType.PageType, BlogUtility.ItemPageTypeName, true));
                _criterias.Add(BlogUtility.CreateCriteria(CompareCondition.GreaterThan, "PageStartPublish", PropertyDataType.Date, CurrentPage.StartPublish.ToString(), true));
                _criterias.Add(BlogUtility.CreateCriteria(CompareCondition.LessThan, "PageStartPublish", PropertyDataType.Date, CurrentPage.StartPublish.Add(SearchInterval).ToString(), true));

                _searchStart = (PageReference)CurrentPage[BlogUtility.StartPropertyName];
            }
            else
            {
                throw new EPiServerException(Translate("/blog/listpage/errormessage"));
            }
        }
Пример #13
0
    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);
    }
Пример #14
0
        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);
        }
Пример #15
0
        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;
        }
Пример #16
0
        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);
        }
Пример #17
0
        /// <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();
        }
Пример #18
0
        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);
        }
Пример #19
0
        /// <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";
        }
Пример #20
0
        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");
        }
        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;
        }
Пример #23
0
        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";
        }
Пример #24
0
        /// <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()
        {
            OnStatusChanged(string.Format("Starting execution of {0}", this.GetType()));

            var repo = ServiceLocator.Current.GetInstance <IContentRepository>();

            var finder = ServiceLocator.Current.GetInstance <IPageCriteriaQueryService>();

            int pageCount = 0;

            foreach (string word in badWords)
            {
                var criteria = new PropertyCriteriaCollection();

                criteria.Add(new PropertyCriteria
                {
                    Type      = PropertyDataType.LongString,
                    Name      = "PageName",
                    Condition = EPiServer.Filters.CompareCondition.Contained,
                    Value     = word
                });

                criteria.Add(new PropertyCriteria
                {
                    Type      = PropertyDataType.LongString,
                    Name      = "MetaTitle",
                    Condition = EPiServer.Filters.CompareCondition.Contained,
                    Value     = word
                });

                criteria.Add(new PropertyCriteria
                {
                    Type      = PropertyDataType.LongString,
                    Name      = "MetaDescription",
                    Condition = EPiServer.Filters.CompareCondition.Contained,
                    Value     = word
                });

                PageDataCollection results = finder.FindPagesWithCriteria(
                    ContentReference.RootPage as PageReference, criteria);

                foreach (SitePageData page in results)
                {
                    var clone = page.CreateWritableClone() as SitePageData;

                    clone.Name            = page.Name.Replace(word, "[censored]");
                    clone.MetaTitle       = page.MetaTitle.Replace(word, "[censored]");
                    clone.MetaDescription = page.MetaDescription.Replace(word, "[censored]");

                    repo.Save(clone,
                              EPiServer.DataAccess.SaveAction.CheckIn,
                              EPiServer.Security.AccessLevel.NoAccess);

                    pageCount++;
                }

                //For long running jobs periodically check if stop is signaled and if so stop execution
                if (_stopSignaled)
                {
                    return("Stop of job was called");
                }
            }

            return($"{pageCount} pages containing one of the following bad words: '{string.Join("' or '", badWords)}' have been censored.");
        }
        public override string Execute()
        {
            OnStatusChanged($"Starting execution of {jobName} job...");

            var finder = ServiceLocator.Current.GetInstance <IPageCriteriaQueryService>();

            var criteria = new PropertyCriteriaCollection();

            criteria.Add(new PropertyCriteria
            {
                Type      = PropertyDataType.LongString,
                Name      = "PageName", // you cannot use Name
                Condition = CompareCondition.Contained,
                Value     = "iWatch"
            });
            criteria.Add(new PropertyCriteria
            {
                Type      = PropertyDataType.LongString,
                Name      = "MetaTitle",
                Condition = CompareCondition.Contained,
                Value     = "iWatch"
            });
            criteria.Add(new PropertyCriteria
            {
                Type      = PropertyDataType.LongString,
                Name      = "MetaDescription",
                Condition = CompareCondition.Contained,
                Value     = "iWatch"
            });

            PageDataCollection matches = finder.FindPagesWithCriteria(
                ContentReference.RootPage, criteria);

            int total = matches.Count;
            int count = 0;

            var repo = ServiceLocator.Current.GetInstance <IContentRepository>();

            foreach (PageData page in matches)
            {
                if (_stopSignaled)
                {
                    return($"{jobName} job was stopped. {count} of {total} pieces of content were corrected.");
                }

                SitePageData sitepage = page.CreateWritableClone() as SitePageData;
                if (sitepage != null)
                {
                    sitepage.Name            = sitepage.Name.Replace("iWatch", "Apple Watch");
                    sitepage.MetaDescription = sitepage.MetaDescription.Replace("iWatch", "Apple Watch");
                    sitepage.MetaTitle       = sitepage.MetaTitle.Replace("iWatch", "Apple Watch");

                    repo.Save(content: sitepage,
                              action: EPiServer.DataAccess.SaveAction.Publish,
                              access: EPiServer.Security.AccessLevel.NoAccess);

                    count++;
                }

                OnStatusChanged($"{jobName} is {count/(double)total*100:0.0}% complete. Please wait...");

                // pause for five seconds to simulate work, and
                // to allow us to test the Stop functionality ;)
                System.Threading.Thread.Sleep(5000);
            }

            return($"{jobName} job completed successfully. {count} of {total} pieces of content were corrected.");
        }
        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;

        }
Пример #27
0
        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 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;
        }
        public override string Execute()
        {
            OnStatusChanged(string.Format(
                                "Starting execution of {0}", this.GetType()));

            var finder = ServiceLocator.Current
                         .GetInstance <IPageCriteriaQueryService>();

            var language = Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2);

            var criteria = new PropertyCriteriaCollection();

            if (language == "en")
            {
                criteria.Add(new PropertyCriteria
                {
                    Type      = PropertyDataType.LongString,
                    Name      = "PageName",
                    Condition = EPiServer.Filters.CompareCondition.Equal,
                    Value     = "Services"
                });
            }
            else if (language == "sv")
            {
                criteria.Add(new PropertyCriteria
                {
                    Type      = PropertyDataType.LongString,
                    Name      = "PageName",
                    Condition = EPiServer.Filters.CompareCondition.Equal,
                    Value     = "Tjänster"
                });
            }
            else
            {
                throw new InvalidOperationException($"No suppor for language branch: {language}");
            }

            var servicesPage = finder.FindPagesWithCriteria(
                ContentReference.RootPage as PageReference, criteria, language)[0] as ServicesPage;

            var loader = ServiceLocator.Current.GetInstance <IContentLoader>();

            if (servicesPage != null && servicesPage.MainContentArea != null && servicesPage.MainContentArea.Items.Any())
            {
                int count = 0;
                FormContainerBlock formContainerBlock = null;

                foreach (var item in servicesPage.MainContentArea.Items)
                {
                    try
                    {
                        formContainerBlock = loader.Get <FormContainerBlock>(item.ContentLink);
                    }
                    catch (TypeMismatchException)
                    {
                        if (count >= servicesPage.MainContentArea.Items.Count)
                        {
                            throw;
                        }
                    }
                    if (_stopSignaled)
                    {
                        return("Stop of job was called");
                    }
                    count++;
                }

                if (formContainerBlock != null)
                {
                    var formDataRepository = ServiceLocator.Current.GetInstance <IFormDataRepository>();

                    List <Submission> submittedData = formDataRepository.GetSubmissionData(
                        new FormIdentity(formContainerBlock.Form.FormGuid, servicesPage.Language.Name),
                        DateTime.Now.AddDays(-100), DateTime.Now)
                                                      .ToList();

                    if (submittedData.Count > 0)
                    {
                        var repo       = ServiceLocator.Current.GetInstance <IContentRepository>();
                        var clone      = servicesPage.CreateWritableClone() as ServicesPage;
                        var editString = servicesPage.MainBody.ToHtmlString();
                        int length     = editString.IndexOf("<div id=\"newsletter-receivers\">");

                        editString  = editString.Substring(0, length == -1 ? editString.Length : length);
                        editString += "<div id=\"newsletter-receivers\"><ul style='color:black;'>";
                        count       = 0;

                        foreach (var submission in submittedData)
                        {
                            string email;
                            if (language == "en")
                            {
                                email = submission.Data["__field_40"] as string;
                            }
                            else
                            {
                                email = submission.Data["__field_36"] as string;
                            }

                            editString += $"<li>{email}</li>";
                            if (_stopSignaled)
                            {
                                return("Stop of job was called");
                            }
                            count++;
                        }
                        editString    += "</ul></div>";
                        clone.MainBody = new XhtmlString(editString);
                        repo.Save(clone, EPiServer.DataAccess.SaveAction.CheckIn,
                                  EPiServer.Security.AccessLevel.NoAccess);

                        return($"The newsletter receivers list on the services-page has been updated and now contains {count} customer(s) in total.");
                    }
                    return("No submitted data was found");
                }
                return("No form container block was found");
            }
            return("No services page with the page name: 'Services' was found or services page was found but MainContentArea was empty.");
        }