umbraco / Umbraco.Headless.Client.Net

.NET Client Library and Samples for the Umbraco headless cms Cloud Service called Umbraco Heartcore
https://umbraco.com/products/umbraco-heartcore/
13 stars 14 forks source link

Umbraco Heartcore Pulling information #26

Closed loriRyanp closed 4 years ago

loriRyanp commented 4 years ago

I would like to pull content from Umbraco Heartcore into a self-hosted umbraco project.

I have the below:

However the code sometimes just hangs with no errors thrown, just waiting not getting a response. However, if I reset iis the content is actually there and displays. I would like to check for new notifications every 15-30 minutes.

public async Task<PagedContent> GetNotificationsAsync()
    {
        var projectAlias = "xxxxxxxx";
        Guid notifications = new Guid("xxxxxxxxxxxxx");
        var contentDeliveryService = new ContentDeliveryService(projectAlias, "xxxxxxxxxxxxxxxxxxxxx");
        var response = await contentDeliveryService.Content.GetChildren(notifications, "en-GB", page: 1, pageSize: 25);
        return (response);
    }

public List<notificationItem> GetNotificationsV2()
    {

            List<notificationItem> notificationsComplete = new List<notificationItem>();

            Task<PagedContent> response = null;
            var tNotifications = Task.Factory.StartNew(() =>
            {
                try
                {
                    response = GetNotificationsAsync();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }

            });
            tNotifications.Wait();

            var countItems = response.Result.TotalItems;
            if (countItems > 0)
            {
                foreach (var item in response.Result.Content.Items)
                {
                    var myProperties = item.Properties;
                    var pNotificationDetail = myProperties["notificationDetail"].ToString();
                    var pNotificationFor = myProperties["notificationFor"].ToString();                 
                        notificationsComplete.Add(new notificationItem()
                        {
                            Name = item.Name,
                            notificationDetail = pNotificationDetail,
                            notificationFor = pNotificationFor
                        });

                }
            }
        return notificationsComplete;
    }
sitereactor commented 4 years ago

Hi @loriRyanp could you use webhooks to achieve the same? And have the content pushed to a URL instead of fetching it / polling every 15 minutes?

In terms of the issue you experience, could you reach out to the Support team through the Umbraco Cloud Portal and reference this issue? We'd need to know the alias of the project in order to investigate what is happening. It doesn't sound like a code/library issue, but maybe more of a platform or caching issue.

loriRyanp commented 4 years ago

Hey I was already on, there was an issue with my instance of Umbraco heartcore which was resolved but unfortunately, the hanging is still happening. I get back on and let you know when I hear back. Thanks for coming back to me, I give the webhooks root a try :-)

nul800sebastiaan commented 4 years ago

Hi there @loriRyanp, it's been a few weeks. I hope your issue got fixed by now. I'll close this for now but let us know if there's still a problem.