コード例 #1
0
        internal static bool MatchGroups(IList <IPublishedContent> pickedGroups)
        {
            // Package is disabled, return default
            if (PersonalisationGroupsConfig.Value.DisablePackage)
            {
                return(true);
            }

            // Check each personalisation group assigned for a match with the current site visitor
            foreach (var group in pickedGroups)
            {
                var definition = group.GetPropertyValue <PersonalisationGroupDefinition>(AppConstants.PersonalisationGroupDefinitionPropertyAlias);
                if (GroupMatchingHelper.IsStickyMatch(definition, group.Id))
                {
                    return(true);
                }

                var matchCount = PersonalisationGroupMatcher.CountMatchingDefinitionDetails(definition);

                // If matching any and matched at least one, or matching all and matched all - we've matched one of the definitions
                // associated with a selected personalisation group
                if ((definition.Match == PersonalisationGroupDefinitionMatch.Any && matchCount > 0) ||
                    (definition.Match == PersonalisationGroupDefinitionMatch.All && matchCount == definition.Details.Count()))
                {
                    GroupMatchingHelper.MakeStickyMatch(definition, group.Id);
                    return(true);
                }
            }

            // If we've got here, we haven't found a match
            return(false);
        }
        private static object CreatePersonalisationGroupsHashForVisitor(IPublishedContent personalisationGroupsRootNode)
        {
            var groups = personalisationGroupsRootNode.Descendants(AppConstants.DocumentTypeAliases.PersonalisationGroup);
            var sb     = new StringBuilder();

            foreach (var group in groups)
            {
                var definition = group.GetPropertyValue <PersonalisationGroupDefinition>(AppConstants.PersonalisationGroupDefinitionPropertyAlias);
                GroupMatchingHelper.AppendMatchedGroupDetailToVisitorHashString(sb, definition, group.CreatorName);
            }

            return(sb.ToString().GetHashCode().ToString());
        }