Esempio n. 1
0
        /// <summary>
        /// Adds an extension method to UmbracoHelper to calculate a hash for the current visitor for all visitor groups
        /// </summary>
        /// <param name="helper">Instance of UmbracoHelper</param>
        /// <param name="personalisationGroupsRootNodeId">Id of root node for the personalisation groups</param>
        /// <param name="cacheUserIdentifier">Identifier for the user to use in the cache key (likely the session Id)</param>
        /// <param name="cacheForSeconds">Length of time in seconds to cache the generated personalisation group hash for the visitor</param>
        /// <returns>Has for the visitor for all groups</returns>
        public static string GetPersonalisationGroupsHashForVisitor(this UmbracoHelper helper, Guid personalisationGroupsRootNodeId,
                                                                    string cacheUserIdentifier, int cacheForSeconds)
        {
            var personalisationGroupsRootNode = helper.Content(personalisationGroupsRootNodeId);

            if (!personalisationGroupsRootNode.IsDocumentType(AppConstants.DocumentTypeAliases.PersonalisationGroupsFolder))
            {
                throw new InvalidOperationException(
                          $"The personalisation groups hash for a visitor can only be calculated for a root node of type {AppConstants.DocumentTypeAliases.PersonalisationGroupsFolder}");
            }

            return(GetPersonalisationGroupsHashForVisitor(helper, personalisationGroupsRootNode, cacheUserIdentifier, cacheForSeconds));
        }
Esempio n. 2
0
        /// <summary>
        /// Adds an extension method to UmbracoHelper to score the content item for the current site
        /// visitor, based on the personalisation groups associated with the Ids passed into the method
        /// </summary>
        /// <param name="umbraco">Instance of UmbracoHelper</param>
        /// <param name="groupIds">List of group Ids</param>
        /// <returns>True if content should be shown to visitor</returns>
        public static int ScoreForVisitor(this UmbracoHelper umbraco, IEnumerable <int> groupIds)
        {
            var groups = umbraco.Content(groupIds).ToList();

            return(ScoreForVisitor(groups));
        }
Esempio n. 3
0
        /// <summary>
        /// Adds an extension method to UmbracoHelper to determine if the content item should be shown to the current site
        /// visitor, based on the personalisation groups associated with the Ids passed into the method
        /// </summary>
        /// <param name="umbraco">Instance of UmbracoHelper</param>
        /// <param name="groupIds">List of group Ids</param>
        /// <param name="showIfNoGroupsDefined">Indicates the response to return if groups cannot be found on the content</param>
        /// <returns>True if content should be shown to visitor</returns>
        public static bool ShowToVisitor(this UmbracoHelper umbraco, IEnumerable <int> groupIds, bool showIfNoGroupsDefined = true)
        {
            var groups = umbraco.Content(groupIds).ToList();

            return(ShowToVisitor(groups, showIfNoGroupsDefined));
        }
Esempio n. 4
0
        public void Load()
        {
            var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
            BlogRoot = Content.Parent;
            EntryDate = (Content.HasValue("entryDate")) ? DateTime.Parse(Content.GetPropertyValue<string>("entryDate")) : Content.CreateDate;
            BlogContent = Content.GetPropertyValue<HtmlString>("content");
            Categories = (Content.HasValue("categories")) ? umbracoHelper.Content(Content.GetPropertyValue<string>("categories").Split(',')) : new List<IPublishedContent>().AsEnumerable();
            Tags = (Content.HasValue("tags")) ? Content.GetPropertyValue<string>("tags").Split(',') : new string[0];
            MainImage = (Content.HasValue("mainImage")) ? JsonConvert.DeserializeObject<ImageCropDataSet>(Content.GetPropertyValue <string>("mainImage") ): null;

            Blurb = (Content.HasValue("blurb")) ? Content.GetPropertyValue<HtmlString>("blurb") : (HtmlString)umbracoHelper.Truncate(BlogContent, 800);
            Title = Content.Name;
            CommentsEnabled = (Content.HasValue("commentsEnabled", true)) ? Content.GetPropertyValue<bool>("commentsEnabled", true) : false;
            DisqusShortname = (Content.HasValue("disqusShortname", true)) ? Content.GetPropertyValue<string>("disqusShortname", true) : null;
            TwitterUsername = Content.GetPropertyValue<string>("twitterUsername", true);
            ShareDescription = Content.GetPropertyValue<string>("shareDescription", true);
            FullUrl = Content.UrlWithDomain();
            var authorId = Content.GetProperty("author");
            Author = (authorId != null && authorId.HasValue) ? new BlogAuthor(
                Convert.ToInt32( authorId.Value)
                ) : null;
            EnableShareIcons = (Content.HasValue("enableShareIcons", true)) ? Content.GetPropertyValue<bool>("enableShareIcons", true) : false;
        }
Esempio n. 5
0
 public IPublishedContent Content(string id)
 {
     return(_umbracoHelper.Content(id));
 }
Esempio n. 6
0
 public UmbracoHelperAdapter(Umbraco.Web.UmbracoHelper umbracoHelper)
 {
     _umbracoHelper = umbracoHelper;
     umbracoHelper.Content(2).AncestorsOrSelf();
 }