ApplicationEventHandler ContentService.Publishing keeps executing over and over
Hi! I'm making an event that will automatically sort pages of the type "CalendarEventPage". For doing this I get all the pages and sort them on a custom property called "StartDate". Finally, I call the method "ContentService.Sort" that will sort the pages. However, as soon as that line is executed the method starts all over again.
At first I thought it triggered a publish event for the other pages but it is the same page the event is fired for.
Does anyone have any idea why this is happening, am I missing something?
Thanks!
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Publishing += ContentService_Publishing;
}
private void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
var currentPage = e.PublishedEntities.FirstOrDefault();
Debug.WriteLine("CurrentPage: " + currentPage.Name);
if (currentPage != null && currentPage.ContentType.Alias == "CalendarEventPage")
{
var parent = currentPage.Parent();
if (parent.ContentType.Alias == "CalendarEventListingPage")
{
var children = parent.Children();
if (children != null && children.Any())
{
var calendarEvents = children.Where(x => x.ContentType.Alias == "CalendarEventPage");
var sortedCalendarEvents =
calendarEvents.OrderByDescending(x => x.GetValue<DateTime>("StartDate"));
// This line fails!
var results = ApplicationContext.Current.Services.ContentService.Sort(sortedCalendarEvents);
}
}
}
}
ApplicationEventHandler ContentService.Publishing keeps executing over and over
Hi! I'm making an event that will automatically sort pages of the type "CalendarEventPage". For doing this I get all the pages and sort them on a custom property called "StartDate". Finally, I call the method "ContentService.Sort" that will sort the pages. However, as soon as that line is executed the method starts all over again.
At first I thought it triggered a publish event for the other pages but it is the same page the event is fired for.
Does anyone have any idea why this is happening, am I missing something?
Thanks!
Anyone? :)
is working on a reply...