Hello all, I'm trying to use a ContentService.Published hook to trigger some events.
Which sends a request to DependencyResolver.Current.GetService<IRequestHandler>()
.SendRequest(new Uri("Umbraco/Api/Agenda/UpdateBirthdays", UriKind.Relative));
This works for my other webrequest which does not change/save or publish any content.
But when i Use this class to handle what i want to do on the call:
public static void UpdateBirthdays()
{
DeleteBirthdays();
CreateBirthdays();
}
public static void ArchiveAgendaItems()
{
// Implement automatic archiving here.
}
private static void CreateBirthdays()
{
var helper = new UmbracoHelper(UmbracoContext.Current);
var content = helper.TypedContentAtRoot().ToList();
var employees = content.DescendantsOrSelf("employee").Where("Visible").ToList();
var createdBirthdays = new List<IContent>();
var agendaId = helper.TypedContentSingleAtXPath("//home/trending/agenda").Id;
foreach (var employee in employees)
{
var birthday = employee.GetPropertyValueExists<DateTime>("EmployeeBirthdate");
var firstName = employee.GetPropertyValueExists<string>("EmployeeFirstName");
var lastName = employee.GetPropertyValueExists<string>("EmployeeLastName");
var title = $"Verjaardag van {firstName} {lastName}";
var birthdayItemDate = birthday.Month < DateTime.Now.Month && birthday.Day < DateTime.Now.Day ? new DateTime(DateTime.Now.Year + 1, birthday.Month, birthday.Day) : new DateTime(DateTime.Now.Year, birthday.Month, birthday.Day);
var birthdayItem = ContentService.CreateContentWithIdentity(title, agendaId, "birthdayItem");
birthdayItem.SetValue("itemTitle", title);
birthdayItem.SetValue("itemDate", birthdayItemDate);
birthdayItem.SetValue("itemDescription", title);
ContentService.Save(birthdayItem);
createdBirthdays.Add(birthdayItem);
}
foreach (var createdBirthday in createdBirthdays)
{
ContentService.PublishWithStatus(createdBirthday);
}
}
private static void DeleteBirthdays()
{
var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
var birthdayContentType = contentTypeService.GetContentType("birthdayItem");
var itemsToDelete = ContentService.GetContentOfContentType(birthdayContentType.Id).ToList();
foreach (var item in itemsToDelete)
{
ContentService.Delete(item);
}
}
}
It works on some occasions but it tends to timeout on the On all the
ContentService calls.
I already tried calling this directly in the code as a temporary check.
My class seems to work just fine, but not when it calls contentservice in the request.
Something seems to prevent the contentservice from doing its work.
Eventhandler webapi request
Hello all, I'm trying to use a ContentService.Published hook to trigger some events. Which sends a request to
DependencyResolver.Current.GetService<IRequestHandler>() .SendRequest(new Uri("Umbraco/Api/Agenda/UpdateBirthdays", UriKind.Relative));
This works for my other webrequest which does not change/save or publish any content.
But when i Use this class to handle what i want to do on the call:
It works on some occasions but it tends to timeout on the On all the ContentService calls.
Any Help?
I already tried calling this directly in the code as a temporary check. My class seems to work just fine, but not when it calls contentservice in the request.
Something seems to prevent the contentservice from doing its work.
look this:
https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/blob/master/Umbraco.Extensions/Utilities/WebApiHandler.cs
Thank you for your response, I don't exactly understand how i can solve my problem with this though. Do you mean make everything async?
is working on a reply...