private static ObjectEnterspeedProperty ConvertToEnterspeedProperty(JToken item)
        {
            if (item == null)
            {
                return(null);
            }

            var properties = new Dictionary <string, IEnterspeedProperty>();

            var caption    = item.Value <string>("caption");
            var title      = item.Value <string>("title");
            var newWindow  = item.Value <bool>("newWindow");
            var isInternal = item.Value <bool>("isInternal");

            string url;

            if (isInternal)
            {
                var nodeId = item.Value <int>("internal");
                url = UmbracoContextHelper.GetUmbracoHelper().UrlAbsolute(nodeId);
            }
            else
            {
                url = item.Value <string>("link");
            }

            properties.Add("caption", new StringEnterspeedProperty(caption));
            properties.Add("title", new StringEnterspeedProperty(title));
            properties.Add("newWindow", new BooleanEnterspeedProperty(newWindow));
            properties.Add("url", new StringEnterspeedProperty(url));

            return(new ObjectEnterspeedProperty(properties));
        }
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var nodeIds    = property.GetValue <string>()?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var arrayItems = new List <IEnterspeedProperty>();

            if (nodeIds != null)
            {
                var umbracoHelper = UmbracoContextHelper.GetUmbracoHelper();
                foreach (var nodeId in nodeIds)
                {
                    var node = umbracoHelper.TypedContent(nodeId);

                    if (node == null)
                    {
                        node = umbracoHelper.TypedMember(nodeId);
                    }

                    if (node == null)
                    {
                        node = umbracoHelper.TypedMedia(nodeId);
                    }

                    var convertedNode = ConvertToEnterspeedProperty(node);
                    if (convertedNode != null)
                    {
                        arrayItems.Add(convertedNode);
                    }
                }
            }

            return(new ArrayEnterspeedProperty(property.PropertyTypeAlias, arrayItems.ToArray()));
        }
        private static void CacheRefresherBaseOnCacheUpdated(PageCacheRefresher sender, CacheRefresherEventArgs cacheRefresherEventArgs)
        {
            // Do not configure if Enterspeed is not configured in Umbraco
            if (EnterspeedContext.Current?.Configuration == null ||
                !EnterspeedContext.Current.Configuration.IsConfigured)
            {
                return;
            }

            var umbracoHelper = UmbracoContextHelper.GetUmbracoHelper();
            var jobs          = new List <EnterspeedJob>();

            switch (cacheRefresherEventArgs.MessageType)
            {
            case MessageType.RefreshById:
                var refreshContent =
                    umbracoHelper.TypedContent((int)cacheRefresherEventArgs.MessageObject);
                if (refreshContent != null)
                {
                    var culture = refreshContent.GetCulture()?.IetfLanguageTag?.ToLowerInvariant();
                    var now     = DateTime.UtcNow;
                    jobs.Add(new EnterspeedJob
                    {
                        ContentId = refreshContent.Id,
                        Culture   = culture,
                        JobType   = EnterspeedJobType.Publish,
                        State     = EnterspeedJobState.Pending,
                        CreatedAt = now,
                        UpdatedAt = now,
                    });
                }

                break;

            case MessageType.RefreshByInstance:
                var node = umbracoHelper.TypedContent(((IContent)cacheRefresherEventArgs.MessageObject).Id);
                if (node != null)
                {
                    var culture = node.GetCulture()?.IetfLanguageTag?.ToLowerInvariant();
                    var now     = DateTime.UtcNow;
                    jobs.Add(new EnterspeedJob
                    {
                        ContentId = node.Id,
                        Culture   = culture,
                        JobType   = EnterspeedJobType.Publish,
                        State     = EnterspeedJobState.Pending,
                        CreatedAt = now,
                        UpdatedAt = now,
                    });
                }

                break;
            }

            EnqueueJobs(jobs);
        }
Ejemplo n.º 4
0
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var value = property.GetValue <string>();

            ObjectEnterspeedProperty mediaValue = null;

            if (!string.IsNullOrWhiteSpace(value) && int.TryParse(value, out var mediaId))
            {
                var media = UmbracoContextHelper.GetUmbracoHelper().TypedMedia(mediaId);
                mediaValue = ConvertToEnterspeedProperty(media);
            }

            return(new ObjectEnterspeedProperty(property.PropertyTypeAlias, mediaValue?.Properties));
        }
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var value = property.GetValue <string>();

            if (!string.IsNullOrWhiteSpace(value) && int.TryParse(value, out var prevalueId))
            {
                value = UmbracoContextHelper.GetUmbracoHelper().GetPreValueAsString(prevalueId);
            }
            else
            {
                value = null;
            }

            return(new StringEnterspeedProperty(property.PropertyTypeAlias, value));
        }
        private ObjectEnterspeedProperty ConvertToEnterspeedProperty(IPublishedContent node)
        {
            if (node == null)
            {
                return(null);
            }

            Dictionary <string, IEnterspeedProperty> properties;

            if (node.ItemType == PublishedItemType.Member)
            {
                properties = new Dictionary <string, IEnterspeedProperty>
                {
                    { "id", new NumberEnterspeedProperty(node.Id) },
                    { "name", new StringEnterspeedProperty(node.Name) },
                    { "memberType", new StringEnterspeedProperty(node.ContentType.Alias) }
                };
            }
            else
            {
                var url = node.Url;
                var id  = node.Id.ToString();
                if (node.ItemType == PublishedItemType.Content)
                {
                    id  = _entityIdentityService.GetId(node);
                    url = UmbracoContextHelper.GetUmbracoHelper().UrlAbsolute(node.Id);
                }
                else if (node.ItemType == PublishedItemType.Media)
                {
                    url = _mediaUrlProvider.GetUrl(node);
                }

                properties = new Dictionary <string, IEnterspeedProperty>
                {
                    { "id", new StringEnterspeedProperty(id) },
                    { "name", new StringEnterspeedProperty(node.Name) },
                    { "url", new StringEnterspeedProperty(url) }
                };
            }

            return(new ObjectEnterspeedProperty(properties));
        }
Ejemplo n.º 7
0
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var mediaIds   = property.GetValue <string>()?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            var arrayItems = new List <IEnterspeedProperty>();

            if (mediaIds != null)
            {
                var umbracoHelper = UmbracoContextHelper.GetUmbracoHelper();
                foreach (var mediaId in mediaIds)
                {
                    var media          = umbracoHelper.TypedMedia(mediaId);
                    var convertedMedia = ConvertToEnterspeedProperty(media);
                    if (convertedMedia != null)
                    {
                        arrayItems.Add(convertedMedia);
                    }
                }
            }

            return(new ArrayEnterspeedProperty(property.PropertyTypeAlias, arrayItems.ToArray()));
        }
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var values     = property.GetValue <string>()?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            var arrayItems = new List <IEnterspeedProperty>();

            if (values != null)
            {
                foreach (var value in values)
                {
                    if (int.TryParse(value, out var prevalueId))
                    {
                        var prevalue = UmbracoContextHelper.GetUmbracoHelper().GetPreValueAsString(prevalueId);
                        if (!string.IsNullOrWhiteSpace(prevalue))
                        {
                            arrayItems.Add(new StringEnterspeedProperty(value));
                        }
                    }
                }
            }

            return(new ArrayEnterspeedProperty(property.PropertyTypeAlias, arrayItems.ToArray()));
        }
Ejemplo n.º 9
0
        public SeedResponse Seed()
        {
            var umbracoHelper = UmbracoContextHelper.GetUmbracoHelper();

            var allContent = umbracoHelper.TypedContentAtRoot()?.SelectMany(x => x.DescendantsOrSelf()).ToList();

            if (allContent == null || !allContent.Any())
            {
                return(new SeedResponse
                {
                    JobsAdded = 0,
                    Nodes = 0,
                });
            }

            var jobs = new List <EnterspeedJob>();

            foreach (var content in allContent)
            {
                var contentJob = GetJobForContent(content);
                if (contentJob == null)
                {
                    continue;
                }

                jobs.Add(contentJob);
            }

            _enterspeedJobRepository.Save(jobs);

            return(new SeedResponse
            {
                Nodes = allContent.Count,
                JobsAdded = jobs.Count
            });
        }