Esempio n. 1
0
        /// <summary> Gets item renderings </summary>
        /// <param name="item">item to proceed</param>
        /// <returns>list of item renderings</returns>
        protected List <RenderingReference> GetRenderings(Item item)
        {
            RuleList <ConditionalRenderingsRuleContext> globalRules = this.GetGlobalRules(item);
            List <RenderingReference> resultCollection = new List <RenderingReference>(item.Visualization.GetRenderings(Sitecore.Context.Device, true));

            foreach (RenderingReference reference in new List <RenderingReference>(resultCollection))
            {
                string conditions = reference.Settings.Conditions;
                if (!string.IsNullOrEmpty(conditions))
                {
                    List <Item> conditionItems = this.GetConditionItems(item.Database, conditions);
                    if (conditionItems.Count > 0)
                    {
                        RuleList <ConditionalRenderingsRuleContext> rules       = RuleFactory.GetRules <ConditionalRenderingsRuleContext>(conditionItems, "Rule");
                        ConditionalRenderingsRuleContext            ruleContext = new ConditionalRenderingsRuleContext(resultCollection, reference)
                        {
                            Item = item
                        };
                        rules.Run(ruleContext);
                    }
                }

                if (globalRules != null)
                {
                    ConditionalRenderingsRuleContext globalRuleContext = new ConditionalRenderingsRuleContext(resultCollection, reference)
                    {
                        Item = item
                    };
                    globalRules.Run(globalRuleContext);
                }
            }

            return(resultCollection);
        }
        protected virtual void Evaluate(CustomizeRenderingArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item item = args.PageContext.Item;

            if (item != null)
            {
                RenderingReference    renderingReference    = GetRenderingReference(args.Rendering, args.Rendering.Item.Language, args.Rendering.Item.Database);
                GetRenderingRulesArgs getRenderingRulesArgs = new GetRenderingRulesArgs(item, renderingReference);
                GetRenderingRulesPipeline.Run(getRenderingRulesArgs);
                RuleList <ConditionalRenderingsRuleContext> ruleList = getRenderingRulesArgs.RuleList;
                if (ruleList != null && ruleList.Count != 0)
                {
                    List <RenderingReference> references = new List <RenderingReference>
                    {
                        renderingReference
                    };
                    ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(references, renderingReference)
                    {
                        Item = item
                    };
                    conditionalRenderingsRuleContext.Parameters["mvc.rendering"] = args.Rendering;
                    var matchingRule = GetMatchingRule(ruleList, conditionalRenderingsRuleContext);
                    ApplyActions(args, conditionalRenderingsRuleContext, matchingRule);
                }
            }
        }
Esempio n. 3
0
        public string GeneratePersonlisationKey()
        {
            string cacheKey = string.Empty;

            try
            {
                var allReferences       = GetRenderingsForControl().ToList();
                var renderingUniqueId   = ID.Parse(RenderingContext.Current.Rendering.UniqueId);
                var renderingReferrence = allReferences.FirstOrDefault(i => ID.Parse(i.UniqueId).Equals(renderingUniqueId));
                if (renderingReferrence?.Settings?.Rules != null)
                {
                    var ruleContext = new ConditionalRenderingsRuleContext(allReferences, renderingReferrence);
                    if (ruleContext != null)
                    {
                        renderingReferrence.Settings.Rules.RunFirstMatching(ruleContext);
                        string personalizedDatasource = ruleContext.Reference.Settings.DataSource;
                        if (!string.IsNullOrWhiteSpace(personalizedDatasource))
                        {
                            cacheKey += String.Concat("pd:", new ID(new Guid(personalizedDatasource)).ToShortID().ToString());
                            string profileMatch = GetPatterName(ruleContext, personalizedDatasource);
                            if (!string.IsNullOrWhiteSpace(profileMatch))
                            {
                                cacheKey += String.Concat(":pn:", profileMatch);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Debug("Sitecore.React could not identify a personalisation for the current rendering", ex);
            }

            return(cacheKey);
        }
        public static string GenerateMetaTags()
        {
            StringBuilder sb         = new StringBuilder();
            RuleStack     stack      = new RuleStack();
            var           references = Sitecore.Context.Item.Visualization.GetRenderings(Sitecore.Context.Device, false);

            try
            {
                foreach (RenderingReference reference in references)
                {
                    ConditionalRenderingsRuleContext context = new ConditionalRenderingsRuleContext(references.ToList(), reference);
                    foreach (Rule <ConditionalRenderingsRuleContext> rule in reference.Settings.Rules.Rules)
                    {
                        rule.Condition.Evaluate(context, stack);
                        if ((stack.Count != 0) && (bool)stack.Pop() && rule.UniqueId != ID.Null)
                        {
                            sb.Append(",").Append(rule.Name);
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Warn("Problem aggregating rules for personalization context, metatag may be incorrect", e, e);
            }
            return(sb.Length > 0 ? $@"<meta name=""sitecorePersonalization"" content=""{sb.ToString(1, sb.Length - 1)}"">" : "");
        }
Esempio n. 5
0
 /// <summary>
 /// If the rendering has rules attached lookup profile card associated with the Rule run.
 /// Return empty if it can't be found.
 /// </summary>
 /// <param name="ruleContext"></param>
 /// <param name="personalizedDatasource"></param>
 /// <returns></returns>
 public string GetPatterName(ConditionalRenderingsRuleContext ruleContext, string personalizedDatasource)
 {
     try
     {
         foreach (var rule in ruleContext.Reference.Settings.Rules.Rules)
         {
             foreach (var action in rule.Actions)
             {
                 var setDataSourceAction = action as SetDataSourceAction <ConditionalRenderingsRuleContext>;
                 if (setDataSourceAction != null && setDataSourceAction.DataSource == personalizedDatasource)
                 {
                     var conditionMatch = rule.Condition as Sitecore.Analytics.Rules.Conditions.HasPatternCondition <ConditionalRenderingsRuleContext>;
                     if (conditionMatch != null)
                     {
                         return(conditionMatch.PatternName.ToLower().GetHashString());
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Sitecore.Diagnostics.Log.Error("Could not locate profile card match for rendering", ex);
     }
     return(string.Empty);
 }
        /// <summary>
        /// Adds the renderings.
        /// </summary>
        /// <returns>List of renderings, with personalization processed</returns>
        private static IEnumerable<RenderingReference> AddRenderings()
        {
            Item item = Context.Item;
            if (item == null)
            {
                return new RenderingReference[0];
            }

            DeviceItem device = Context.Device;
            if (device == null)
            {
                return new RenderingReference[0];
            }

            RuleList<ConditionalRenderingsRuleContext> globalRules = GetGlobalRules(item);
            List<RenderingReference> collection = new List<RenderingReference>(item.Visualization.GetRenderings(device, true));
            List<RenderingReference> list3 = new List<RenderingReference>(collection);
            foreach (RenderingReference reference in list3)
            {
                string conditions = reference.Settings.Conditions;
                if (!string.IsNullOrEmpty(conditions))
                {
                    List<Item> conditionItems = new ListString(conditions).Select(item.Database.GetItem).Where(x => x != null).ToList();
                    if (conditionItems.Count > 0)
                    {
                        var rules = RuleFactory.GetRules<ConditionalRenderingsRuleContext>(conditionItems, "Rule");
                        var ruleContext = new ConditionalRenderingsRuleContext(collection, reference) { Item = item };

                        if (!PersonaHelper.DisableOtherRules)
                        {
                            rules.Run(ruleContext);
                        }

                        foreach (var conditionItem in conditionItems)
                        {
                            if (!PersonaHelper.RuleIsActive(conditionItem))
                            {
                                continue;
                            }

                            var conditionRules = RuleFactory.GetRules<ConditionalRenderingsRuleContext>(new[] {conditionItem}, "Rule");
                            foreach (var action in conditionRules.Rules.SelectMany(rule => rule.Actions))
                            {
                                action.Apply(ruleContext);
                            }
                        }
                    }
                }

                if (globalRules != null)
                {
                    ConditionalRenderingsRuleContext context4 = new ConditionalRenderingsRuleContext(collection, reference);
                    context4.Item = item;
                    ConditionalRenderingsRuleContext context3 = context4;
                    globalRules.Run(context3);
                }
            }

            return collection.ToArray();
        }
        protected override void Evaluate(Sitecore.Pipelines.InsertRenderings.InsertRenderingsArgs args, Sitecore.Data.Items.Item item)
        {
            RuleList<ConditionalRenderingsRuleContext> globalRules = this.GetGlobalRules(item);
            foreach (RenderingReference reference in new List<RenderingReference>((IEnumerable<RenderingReference>)args.Renderings))
            {
                string conditions = reference.Settings.Conditions;
                if (!string.IsNullOrEmpty(conditions))
                {
                    List<Item> conditionItems = this.GetConditionItems(item.Database, conditions);
                    if (conditionItems.Count > 0)
                    {
                        RuleList<ConditionalRenderingsRuleContext> rules = RuleFactory.GetRules<ConditionalRenderingsRuleContext>((IEnumerable<Item>)conditionItems, "Rule");
                        ConditionalRenderingsRuleContext renderingsRuleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
                        renderingsRuleContext.Item = item;
                        ConditionalRenderingsRuleContext ruleContext = renderingsRuleContext;
                        rules.Run(ruleContext);
                    }
                }
                if (globalRules != null)
                {
                    ConditionalRenderingsRuleContext renderingsRuleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
                    renderingsRuleContext.Item = item;
                    ConditionalRenderingsRuleContext ruleContext = renderingsRuleContext;
                    globalRules.Run(ruleContext);
                }

                GetCustomRules(args, item, reference);
            }
        }
        /// <summary> Gets item renderings </summary>
        /// <param name="item">item to proceed</param>
        /// <returns>list of item renderings</returns>
        protected List<RenderingReference> GetRenderings(Item item)
        {
            RuleList<ConditionalRenderingsRuleContext> globalRules = this.GetGlobalRules(item);
              List<RenderingReference> resultCollection = new List<RenderingReference>(item.Visualization.GetRenderings(Sitecore.Context.Device, true));
              foreach (RenderingReference reference in new List<RenderingReference>(resultCollection))
              {
            string conditions = reference.Settings.Conditions;
            if (!string.IsNullOrEmpty(conditions))
            {
              List<Item> conditionItems = this.GetConditionItems(item.Database, conditions);
              if (conditionItems.Count > 0)
              {
            RuleList<ConditionalRenderingsRuleContext> rules = RuleFactory.GetRules<ConditionalRenderingsRuleContext>(conditionItems, "Rule");
            ConditionalRenderingsRuleContext ruleContext = new ConditionalRenderingsRuleContext(resultCollection, reference) { Item = item };
            rules.Run(ruleContext);
              }
            }

            if (globalRules != null)
            {
              ConditionalRenderingsRuleContext globalRuleContext = new ConditionalRenderingsRuleContext(resultCollection, reference) { Item = item };
              globalRules.Run(globalRuleContext);
            }
              }

              return resultCollection;
        }
        protected override void Evaluate(CustomizeRenderingArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item item = args.PageContext.Item;

            if (item != null)
            {
                RenderingReference    renderingReference    = CustomizeRenderingProcessor.GetRenderingReference(args.Rendering, Context.Language, args.PageContext.Database);
                GetRenderingRulesArgs getRenderingRulesArgs = new GetRenderingRulesArgs(item, renderingReference);
                GetRenderingRulesPipeline.Run(getRenderingRulesArgs);
                RuleList <ConditionalRenderingsRuleContext> ruleList = getRenderingRulesArgs.RuleList;
                if (ruleList != null && ruleList.Count != 0)
                {
                    List <RenderingReference> references = new List <RenderingReference>
                    {
                        renderingReference
                    };
                    ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(references, renderingReference)
                    {
                        Item = item
                    };
                    conditionalRenderingsRuleContext.Parameters["mvc.rendering"] = args.Rendering;
                    RunRules(ruleList, conditionalRenderingsRuleContext);
                    ApplyActions(args, conditionalRenderingsRuleContext);
                    args.IsCustomized = true;
                }
            }
        }
Esempio n. 10
0
        protected override void Evaluate(Sitecore.Pipelines.InsertRenderings.InsertRenderingsArgs args, Sitecore.Data.Items.Item item)
        {
            RuleList <ConditionalRenderingsRuleContext> globalRules = this.GetGlobalRules(item);

            foreach (RenderingReference reference in new List <RenderingReference>((IEnumerable <RenderingReference>)args.Renderings))
            {
                string conditions = reference.Settings.Conditions;
                if (!string.IsNullOrEmpty(conditions))
                {
                    List <Item> conditionItems = this.GetConditionItems(item.Database, conditions);
                    if (conditionItems.Count > 0)
                    {
                        RuleList <ConditionalRenderingsRuleContext> rules = RuleFactory.GetRules <ConditionalRenderingsRuleContext>((IEnumerable <Item>)conditionItems, "Rule");
                        ConditionalRenderingsRuleContext            renderingsRuleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
                        renderingsRuleContext.Item = item;
                        ConditionalRenderingsRuleContext ruleContext = renderingsRuleContext;
                        rules.Run(ruleContext);
                    }
                }
                if (globalRules != null)
                {
                    ConditionalRenderingsRuleContext renderingsRuleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
                    renderingsRuleContext.Item = item;
                    ConditionalRenderingsRuleContext ruleContext = renderingsRuleContext;
                    globalRules.Run(ruleContext);
                }

                GetCustomRules(args, item, reference);
            }
        }
Esempio n. 11
0
        protected override void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context)
        {
            base.ApplyActions(args, context);
            RenderingReference renderingReference = context.References.Find((RenderingReference r) => r.UniqueId == context.Reference.UniqueId);

            if (renderingReference != null)
            {
                ExtensionMethods.TransferRenderingParameters(args.Rendering, renderingReference);
            }
        }
Esempio n. 12
0
 private static void RunPromoRule(Sitecore.Pipelines.InsertRenderings.InsertRenderingsArgs args, Sitecore.Data.Items.Item item, RenderingReference reference, Item promo, string fieldName)
 {
     if (promo != null && !string.IsNullOrEmpty(fieldName))
     {
         RuleList <ConditionalRenderingsRuleContext> rules = RuleFactory.GetRules <ConditionalRenderingsRuleContext>(promo.Fields[fieldName]);
         var ruleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
         ruleContext.Item = item;
         rules.Run(ruleContext);
     }
 }
Esempio n. 13
0
        protected override void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(context, "context");
            RenderingReference renderingReference = context.References.Find((RenderingReference r) => r.UniqueId == context.Reference.UniqueId);

            if (renderingReference == null)
            {
                args.Renderer = new EmptyRenderer();
                return;
            }
            this.ApplyChanges(args.Rendering, renderingReference);
        }
Esempio n. 14
0
        protected override RenderingReference DoActivateCondition(RenderingDefinition rendering, ID conditionID, Language lang, Database database, Item item, SiteContext site)
        {
            // Copied from Sitecore
            Assert.ArgumentNotNull(rendering, "rendering");
            Assert.ArgumentNotNull(conditionID, "conditionID");
            Assert.ArgumentNotNull(lang, "lang");
            Assert.ArgumentNotNull(database, "database");
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(site, "site");
            RenderingReference renderingReference             = new RenderingReference(rendering, lang, database);
            RuleList <ConditionalRenderingsRuleContext> rules = renderingReference.Settings.Rules;
            Rule <ConditionalRenderingsRuleContext>     rule  = rules.Rules.FirstOrDefault <Rule <ConditionalRenderingsRuleContext> >((Rule <ConditionalRenderingsRuleContext> r) => r.UniqueId == conditionID);

            if (rule == null)
            {
                return(renderingReference);
            }
            List <RenderingReference> renderingReferences = new List <RenderingReference>()
            {
                renderingReference
            };
            ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(renderingReferences, renderingReference)
            {
                Item = item
            };

            rule.SetCondition(new TrueCondition <ConditionalRenderingsRuleContext>());
            rules = new RuleList <ConditionalRenderingsRuleContext>(rule);
            using (SiteContextSwitcher siteContextSwitcher = new SiteContextSwitcher(site))
            {
                using (DatabaseSwitcher databaseSwitcher = new DatabaseSwitcher(item.Database))
                {
                    rules.Run(conditionalRenderingsRuleContext);
                }
            }
            Assert.IsTrue(conditionalRenderingsRuleContext.References.Count == 1, "The references count should equal 1");
            RenderingReference renderingReference1 = conditionalRenderingsRuleContext.References[0];

            Assert.IsNotNull(renderingReference1, "result");
            rendering.Datasource = renderingReference1.Settings.DataSource;
            if (renderingReference1.RenderingItem != null)
            {
                rendering.ItemID = renderingReference1.RenderingItem.ID.ToString();
            }
            // End copied from Sitecore

            // Apply Parameters Too
            rendering.Parameters = renderingReference1.Settings.Parameters;

            return(renderingReference1);
        }
Esempio n. 15
0
        protected override void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context)
        {
            // Begin copied from sitecore
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(context, "context");
            RenderingReference renderingReference = context.References.Find((RenderingReference r) => r.UniqueId == context.Reference.UniqueId);

            if (renderingReference == null)
            {
                args.Renderer = new EmptyRenderer();
                return;
            }
            this.ApplyChanges(args.Rendering, renderingReference);
            // End copied from sitecore

            // Apply Parameters Too
            TransferRenderingParameters(args.Rendering, renderingReference);
        }
Esempio n. 16
0
        protected override void Evaluate(CustomizeRenderingArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item item = args.PageContext.Item;

            if (item == null)
            {
                return;
            }
            RenderingReference    renderingReference = CustomizeRenderingProcessor.GetRenderingReference(args.Rendering, Context.Language, args.PageContext.Database);
            GetRenderingRulesArgs expr_3E            = new GetRenderingRulesArgs(item, renderingReference);

            GetRenderingRulesPipeline.Run(expr_3E);
            RuleList <ConditionalRenderingsRuleContext> ruleList = expr_3E.RuleList;

            if (ruleList == null || ruleList.Count == 0)
            {
                return;
            }

            // after the ruleList has been retrieved AND ruleList > 0, instantiate a new personalization rulelist which has a fix to continue evaluation of conditions
            // even when some exceptions occur.
            PersonalizationRuleList <ConditionalRenderingsRuleContext> personalizationRuleList = new PersonalizationRuleList <ConditionalRenderingsRuleContext>();

            foreach (var r in ruleList.Rules)
            {
                personalizationRuleList.Add(r);
            }

            ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(new List <RenderingReference>
            {
                renderingReference
            }, renderingReference)
            {
                Item = item
            };

            conditionalRenderingsRuleContext.Parameters["mvc.rendering"] = args.Rendering;

            // runRules for the personalizationRuleList
            this.RunRules(personalizationRuleList, conditionalRenderingsRuleContext);
            this.ApplyActions(args, conditionalRenderingsRuleContext);
            args.IsCustomized = true;
        }
        /// <summary>
        /// Executes all the action against matched Rule.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="context"></param>
        /// <param name="matchingRule"></param>
        protected virtual void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context, Rule <ConditionalRenderingsRuleContext> matchingRule)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(matchingRule, "matchingRule");
            if (matchingRule?.Actions?.Count <= 0)
            {
                return;
            }

            matchingRule.Actions?.Where(a => a.GetType().Name.StartsWith("SetRenderingVariantAction"))?.Each(a => a.Apply(context));

            var parameters = WebUtil.ParseQueryString(context.Reference.Settings.Parameters, true);

            if (!string.IsNullOrWhiteSpace(parameters["FieldNames"]))
            {
                args.Rendering.Parameters["FieldNames"] = parameters["FieldNames"];
            }
        }
        public override void Process(RenderRenderingArgs args)
        {
            if (args.Rendered)
            {
                return;
            }

            if (HttpContext.Current == null || !args.Cacheable ||
                args.Rendering.RenderingItem?.InnerItem == null)
            {
                return;
            }

            var renderingItem = args.Rendering.RenderingItem.InnerItem;

            if (renderingItem?["VaryByPersonalizedData"] != "1")
            {
                return;
            }

            var allReferences       = GetRenderingsForControl(Sitecore.Context.Item, Sitecore.Context.Device).ToList();
            var renderingUniqueId   = ID.Parse(args.Rendering.UniqueId);
            var renderingReferrence = allReferences.Where(i => ID.Parse(i.UniqueId).Equals(renderingUniqueId)).FirstOrDefault();

            if (renderingReferrence != null)
            {
                var ruleContext = new ConditionalRenderingsRuleContext(allReferences, renderingReferrence);
                renderingReferrence.Settings.Rules.RunFirstMatching(ruleContext);
                if (!ruleContext.Reference.Settings.Rules.Rules.Any())
                {
                    return;
                }

                string personalizedDatasource = ruleContext.Reference.Settings.DataSource;

                args.CacheKey += String.Concat("_#personlizedData:", personalizedDatasource);
            }
        }
Esempio n. 19
0
        public string GeneratePagePersonlisationKey()
        {
            //IL_0042: Unknown result type (might be due to invalid IL or missing references)
            //IL_0049: Expected O, but got Unknown
            //IL_007b: Unknown result type (might be due to invalid IL or missing references)
            string text = string.Empty;

            try
            {
                List <RenderingReference> list = GetRenderingsForControl().ToList();
                if (list.Any())
                {
                    foreach (RenderingReference item in list)
                    {
                        if (!string.IsNullOrWhiteSpace(item.RenderingItem.Conditions))
                        {
                            ConditionalRenderingsRuleContext val = new ConditionalRenderingsRuleContext(list, item);
                            item.Settings.Rules.RunFirstMatching(val);
                            string dataSource = val.Reference.Settings.DataSource;
                            text = text + "pd:" + ((object)new ID(new Guid(dataSource)).ToShortID()).ToString();
                            string profileMatch = GetPatterName(val, dataSource);
                            if (!string.IsNullOrWhiteSpace(profileMatch))
                            {
                                text = text + "pn:" + ((object)new ID(new Guid(dataSource)).ToShortID()).ToString();
                            }
                        }
                    }
                    return(text);
                }
                return(text);
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Sitecore.React could not identify a combined personalization key", (object)ex);
                return(text);
            }
        }
 private void RulesAppliedHandler(RuleList <ConditionalRenderingsRuleContext> ruleList, ConditionalRenderingsRuleContext ruleContext, RuleAction <ConditionalRenderingsRuleContext> action)
 {
     if (action.GetType().Name.StartsWith("SetRenderingVariantAction"))
     {
         _VariantId = (action as SetRenderingVariantAction <ConditionalRenderingsRuleContext>).VariantID;
     }
 }
 protected override void RunRules(RuleList <ConditionalRenderingsRuleContext> rules, ConditionalRenderingsRuleContext context)
 {
     Assert.ArgumentNotNull(rules, "rules");
     Assert.ArgumentNotNull(context, "context");
     if (!RenderingRuleEvaluatedPipeline.IsEmpty())
     {
         rules.Evaluated += RulesEvaluatedHandler;
         rules.Applied   += RulesAppliedHandler;
     }
     rules.RunFirstMatching(context);
 }
Esempio n. 22
0
        /// <summary>
        /// accept personalizationRuleList, evaluate conditions,
        /// </summary>
        /// <param name="rules"></param>
        /// <param name="context"></param>
        protected virtual void RunRules(PersonalizationRuleList <ConditionalRenderingsRuleContext> rules, ConditionalRenderingsRuleContext context)
        {
            Assert.ArgumentNotNull(rules, "rules");
            Assert.ArgumentNotNull(context, "context");
            if (!RenderingRuleEvaluatedPipeline.IsEmpty())
            {
                rules.Evaluated += new RuleConditionEventHandler <ConditionalRenderingsRuleContext>(this.RulesEvaluatedHandler);
            }

            rules.RunFirstMatchingIgnoringTrackingExceptions(context);
        }
        private void RulesEvaluatedHandler(RuleList <ConditionalRenderingsRuleContext> ruleList, ConditionalRenderingsRuleContext ruleContext, Rule <ConditionalRenderingsRuleContext> rule)
        {
            RenderingRuleEvaluatedArgs args = new RenderingRuleEvaluatedArgs(ruleList, ruleContext, rule);

            RenderingRuleEvaluatedPipeline.Run(args);
        }
 private static void RunPromoRule(Sitecore.Pipelines.InsertRenderings.InsertRenderingsArgs args, Sitecore.Data.Items.Item item, RenderingReference reference, Item promo, string fieldName)
 {
     if (promo != null && !string.IsNullOrEmpty(fieldName))
     {
         RuleList<ConditionalRenderingsRuleContext> rules = RuleFactory.GetRules<ConditionalRenderingsRuleContext>(promo.Fields[fieldName]);
         var ruleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
         ruleContext.Item = item;
         rules.Run(ruleContext);
     }
 }
        /// <summary>
        /// Evaluates if rule is active.
        /// </summary>
        /// <param name="ruleItem">The rule item.</param>
        /// <param name="contextItem">The context item.</param>
        /// <returns></returns>
        private static bool RuleIsActive(Item ruleItem, Item contextItem)
        {
            var personaHelper = PersonaHelper.GetHelper();
            personaHelper.SetAnalyticsContext();

            foreach (Rule<ConditionalRenderingsRuleContext> rule in RuleFactory.GetRules<ConditionalRenderingsRuleContext>(new[] { ruleItem }, "Rule").Rules)
            {
                if (rule.Condition != null)
                {
                    var ruleContext = new ConditionalRenderingsRuleContext(new List<RenderingReference>(), new RenderingReference(new Control())) { Item = contextItem };
                    var stack = new RuleStack();
                    rule.Condition.Evaluate(ruleContext, stack);
                    if (ruleContext.IsAborted)
                    {
                        return false;
                    }

                    bool ruleOutcome = false;
                    if ((stack.Count != 0) && ((bool)stack.Pop()))
                    {
                        ruleOutcome = true;
                    }
                    if (rule.Condition.GetType() == typeof(VisitorIdentificationCondition<ConditionalRenderingsRuleContext>))
                    {
                        ruleOutcome = !ruleOutcome;
                    }
                    return ruleOutcome;
                }
            }
            return false;
        }
        /// <summary>
        /// Gets the matching rule from the rulelist
        /// </summary>
        /// <param name="rules"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        protected virtual Rule <ConditionalRenderingsRuleContext> GetMatchingRule(RuleList <ConditionalRenderingsRuleContext> rules, ConditionalRenderingsRuleContext context)
        {
            Assert.ArgumentNotNull(rules, "rules");
            Assert.ArgumentNotNull(context, "context");

            var matchingRule = rules.Rules.FirstOrDefault(r => r.Evaluate(context)) ?? rules.Rules.FirstOrDefault(r => r.UniqueId == ID.Null);

            return(matchingRule);
        }