diff --git a/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition.cs index 5ef5cac..5e59976 100644 --- a/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition.cs +++ b/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition.cs @@ -73,7 +73,7 @@ protected override bool Execute(T ruleContext) KeyBehaviorCache keyBehaviorCache = ContactKeyBehaviorCacheExtension.GetKeyBehaviorCache(Tracker.Current.Contact); return Enumerable.Any(this.FilterKeyBehaviorCacheEntries(keyBehaviorCache), (Func)delegate (KeyBehaviorCacheEntry entry) { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) + Guid id = entry.Id; Guid? b = this.OutcomeGuid; return (Guid?)id == b; diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWasTriggeredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWasTriggeredDuringPastOrCurrentInteractionCondition.cs index e1184d7..3974990 100644 --- a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWasTriggeredDuringPastOrCurrentInteractionCondition.cs +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -15,6 +15,7 @@ public class CampaignWasTriggeredDuringPastOrCurrentInteractionCondition : Ha private bool campaignGuidInitialized; + private bool filterByCustomData; public string CampaignId { get; @@ -50,6 +51,7 @@ public CampaignWasTriggeredDuringPastOrCurrentInteractionCondition() protected CampaignWasTriggeredDuringPastOrCurrentInteractionCondition(bool filterByCustomData) : base(filterByCustomData) { + this.filterByCustomData = filterByCustomData; } protected override bool Execute(T ruleContext) @@ -64,7 +66,7 @@ protected override bool Execute(T ruleContext) } if (this.HasEventOccurredInInteraction(Tracker.Current.Session.Interaction)) { - return true; + return true; } Assert.IsNotNull((object)Tracker.Current.Contact, "Tracker.Current.Contact is not initialized"); KeyBehaviorCache keyBehaviorCache = ContactKeyBehaviorCacheExtension.GetKeyBehaviorCache(Tracker.Current.Contact); diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelOfPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelOfPastOrCurrentInteractionCondition.cs index 8afa251..d004fd8 100644 --- a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelOfPastOrCurrentInteractionCondition.cs +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelOfPastOrCurrentInteractionCondition.cs @@ -23,6 +23,8 @@ public class ChannelOfPastOrCurrentInteractionCondition : HasEventOccurredCon private bool channelGuidInitialized; + private bool filterByCustomData; + public string ChannelId { get; @@ -58,30 +60,12 @@ public ChannelOfPastOrCurrentInteractionCondition() protected ChannelOfPastOrCurrentInteractionCondition(bool filterByCustomData) : base(filterByCustomData) { + this.filterByCustomData = filterByCustomData; } protected override bool Execute(T ruleContext) { - //IL_0010: Unknown result type (might be due to invalid IL or missing references) - //IL_001a: Expected O, but got Unknown - //IL_001f: Unknown result type (might be due to invalid IL or missing references) - //IL_0024: Unknown result type (might be due to invalid IL or missing references) - //IL_002e: Expected O, but got Unknown - //IL_0033: Unknown result type (might be due to invalid IL or missing references) - //IL_0038: Unknown result type (might be due to invalid IL or missing references) - //IL_003d: Unknown result type (might be due to invalid IL or missing references) - //IL_0047: Expected O, but got Unknown - //IL_005f: Unknown result type (might be due to invalid IL or missing references) - //IL_0064: Unknown result type (might be due to invalid IL or missing references) - //IL_0069: Unknown result type (might be due to invalid IL or missing references) - //IL_0077: Unknown result type (might be due to invalid IL or missing references) - //IL_007c: Unknown result type (might be due to invalid IL or missing references) - //IL_0086: Expected O, but got Unknown - //IL_008b: Unknown result type (might be due to invalid IL or missing references) - //IL_0090: Unknown result type (might be due to invalid IL or missing references) - //IL_0095: Unknown result type (might be due to invalid IL or missing references) - //IL_009a: Unknown result type (might be due to invalid IL or missing references) - //IL_009c: Unknown result type (might be due to invalid IL or missing references) + Assert.ArgumentNotNull((object)ruleContext, "ruleContext"); Assert.IsNotNull((object)Tracker.Current, "Tracker.Current is not initialized"); Assert.IsNotNull((object)Tracker.Current.Session, "Tracker.Current.Session is not initialized"); @@ -90,15 +74,14 @@ protected override bool Execute(T ruleContext) { return false; } - if (this.HasEventOccurredInInteraction(Tracker.Current.Session.Interaction)) + if (!this.HasEventOccurredInInteraction(Tracker.Current.Session.Interaction)) { - return true; + return false; } Assert.IsNotNull((object)Tracker.Current.Contact, "Tracker.Current.Contact is not initialized"); KeyBehaviorCache keyBehaviorCache = ContactKeyBehaviorCacheExtension.GetKeyBehaviorCache(Tracker.Current.Contact); return Enumerable.Any(this.FilterKeyBehaviorCacheEntries(keyBehaviorCache), (Func)delegate (KeyBehaviorCacheEntry entry) { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) Guid id = entry.Id; Guid? b = this.ChannelGuid; return (Guid?)id == b; @@ -107,18 +90,12 @@ protected override bool Execute(T ruleContext) protected override IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) - //IL_0006: Expected O, but got Unknown - //IL_000b: Unknown result type (might be due to invalid IL or missing references) Assert.ArgumentNotNull((object)keyBehaviorCache, "keyBehaviorCache"); return keyBehaviorCache.Channels; } protected override bool HasEventOccurredInInteraction(IInteractionData interaction) { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) - //IL_0006: Expected O, but got Unknown - //IL_000b: Unknown result type (might be due to invalid IL or missing references) Assert.ArgumentNotNull((object)interaction, "interaction"); Guid channelId = interaction.ChannelId; Guid? b = this.ChannelGuid; diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWasTriggeredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWasTriggeredDuringPastOrCurrentInteractionCondition.cs index 07b5082..b0a4bf2 100644 --- a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWasTriggeredDuringPastOrCurrentInteractionCondition.cs +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -8,129 +8,189 @@ using System; using System.Collections.Generic; using System.Linq; +using Sitecore.Support.Rules.Conditions; namespace Sitecore.Support.Analytics.Rules.Conditions { - public class GoalWasTriggeredDuringPastOrCurrentInteractionCondition : HasEventOccurredCondition where T : RuleContext + public class GoalWasTriggeredDuringPastOrCurrentInteractionCondition : Sitecore.Support.Analytics.Rules.Conditions.HasEventOccurredCondition + where T : RuleContext { - private Guid? goalGuid; + /// + /// The goal GUID. + /// + private Guid? _goalGuid; - private bool goalGuidInitialized; + /// + /// The is goal GUID initialized. + /// + private bool _goalGuidInitialized; - public string GoalId + private bool filterByCustomData; + + /// + /// Initializes a new instance of the class. + /// + public GoalWasTriggeredDuringPastOrCurrentInteractionCondition() + : base(false) { - get; - set; } + /// + /// Initializes a new instance of the class. + /// + /// + /// If set to true, the key behavior cache entries will be filtered by custom data. + /// + protected GoalWasTriggeredDuringPastOrCurrentInteractionCondition(bool filterByCustomData) + : base(filterByCustomData) + { + this.filterByCustomData = filterByCustomData; + } + + /// + /// Gets or sets the identifier of the goal. + /// + /// + /// A representing the ID of the goal. + /// + [NotNull] + public string GoalId { get; set; } + + /// + /// Gets the goal GUID. + /// + /// + /// The goal GUID. + /// private Guid? GoalGuid { get { - if (this.goalGuidInitialized) + if (_goalGuidInitialized) { - return this.goalGuid; + return _goalGuid; } + try { - this.goalGuid = new Guid(this.GoalId); + _goalGuid = new Guid(GoalId); } catch { - Log.Warn(string.Format("Could not convert value to guid: {0}", this.GoalId), (object)base.GetType()); + Log.Warn($"Could not convert value to guid: {GoalId}", GetType()); } - this.goalGuidInitialized = true; - return this.goalGuid; - } - } - public GoalWasTriggeredDuringPastOrCurrentInteractionCondition() - : base(false) - { - } + _goalGuidInitialized = true; - protected GoalWasTriggeredDuringPastOrCurrentInteractionCondition(bool filterByCustomData) - : base(filterByCustomData) - { + return _goalGuid; + } } - protected override bool Execute(T ruleContext) + /// + /// Executes the specified rule context. + /// + /// + /// The rule context. + /// + /// + /// True, if the condition succeeds, otherwise false. + /// + protected override bool Execute([NotNull] T ruleContext) { - //IL_0010: Unknown result type (might be due to invalid IL or missing references) - //IL_001a: Expected O, but got Unknown - //IL_001f: Unknown result type (might be due to invalid IL or missing references) - //IL_0024: Unknown result type (might be due to invalid IL or missing references) - //IL_002e: Expected O, but got Unknown - //IL_0033: Unknown result type (might be due to invalid IL or missing references) - //IL_0038: Unknown result type (might be due to invalid IL or missing references) - //IL_003d: Unknown result type (might be due to invalid IL or missing references) - //IL_0047: Expected O, but got Unknown - //IL_005f: Unknown result type (might be due to invalid IL or missing references) - //IL_0064: Unknown result type (might be due to invalid IL or missing references) - //IL_0069: Unknown result type (might be due to invalid IL or missing references) - //IL_0077: Unknown result type (might be due to invalid IL or missing references) - //IL_007c: Unknown result type (might be due to invalid IL or missing references) - //IL_0086: Expected O, but got Unknown - //IL_008b: Unknown result type (might be due to invalid IL or missing references) - //IL_0090: Unknown result type (might be due to invalid IL or missing references) - //IL_0095: Unknown result type (might be due to invalid IL or missing references) - //IL_009a: Unknown result type (might be due to invalid IL or missing references) - //IL_009c: Unknown result type (might be due to invalid IL or missing references) - Assert.ArgumentNotNull((object)ruleContext, "ruleContext"); - Assert.IsNotNull((object)Tracker.Current, "Tracker.Current is not initialized"); - Assert.IsNotNull((object)Tracker.Current.Session, "Tracker.Current.Session is not initialized"); - Assert.IsNotNull((object)Tracker.Current.Session.Interaction, "Tracker.Current.Session.Interaction is not initialized"); - if (!this.GoalGuid.HasValue) + Assert.ArgumentNotNull(ruleContext, "ruleContext"); + Assert.IsNotNull(Tracker.Current, "Tracker.Current is not initialized"); + Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session is not initialized"); + Assert.IsNotNull(Tracker.Current.Session.Interaction, "Tracker.Current.Session.Interaction is not initialized"); + + if (GoalGuid == null) { return false; } - if (this.HasEventOccurredInInteraction(Tracker.Current.Session.Interaction)) + + if (HasEventOccurredInInteraction(Tracker.Current.Session.Interaction)) { return true; } - Assert.IsNotNull((object)Tracker.Current.Contact, "Tracker.Current.Contact is not initialized"); - KeyBehaviorCache keyBehaviorCache = ContactKeyBehaviorCacheExtension.GetKeyBehaviorCache(Tracker.Current.Contact); + + Assert.IsNotNull(Tracker.Current.Contact, "Tracker.Current.Contact is not initialized"); + + KeyBehaviorCache keyBehaviorCache = Tracker.Current.Contact.GetKeyBehaviorCache(); + return Enumerable.Any(this.FilterKeyBehaviorCacheEntries(keyBehaviorCache), (Func)delegate (KeyBehaviorCacheEntry entry) - { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) - Guid id = entry.Id; - Guid? b = this.GoalGuid; - return (Guid?)id == b; - }); + { + Guid id = entry.Id; + Guid? b = this.GoalGuid; + return (Guid?)id == b; + }); } + /// + /// Gets key behavior cache entries. + /// + /// + /// The key behavior cache. + /// + /// + /// The . + /// protected override IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) - //IL_0006: Expected O, but got Unknown - //IL_000b: Unknown result type (might be due to invalid IL or missing references) - Assert.ArgumentNotNull((object)keyBehaviorCache, "keyBehaviorCache"); + Assert.ArgumentNotNull(keyBehaviorCache, "keyBehaviorCache"); + return keyBehaviorCache.Goals; } + /// + /// Checks whether event occurred in interaction. + /// + /// + /// The interaction. + /// + /// + /// The + /// true if the event occurred in the interaction; otherwise, false. + /// protected override bool HasEventOccurredInInteraction(IInteractionData interaction) { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) - //IL_0006: Expected O, but got Unknown - //IL_000b: Unknown result type (might be due to invalid IL or missing references) - //IL_001b: Unknown result type (might be due to invalid IL or missing references) - Assert.ArgumentNotNull((object)interaction, "interaction"); - Assert.IsNotNull((object)interaction.Pages, "interaction.Pages is not initialized."); - return Enumerable.Any(Enumerable.SelectMany((IEnumerable)interaction.Pages, (Func>)((Page page) => page.PageEvents)), (Func)delegate (PageEventData pageEvent) - { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) - //IL_0008: Unknown result type (might be due to invalid IL or missing references) - if (pageEvent.IsGoal) - { - Guid pageEventDefinitionId = pageEvent.PageEventDefinitionId; - Guid? b = this.GoalGuid; - return (Guid?)pageEventDefinitionId == b; - } - return false; - }); + Assert.ArgumentNotNull(interaction, "interaction"); + Assert.IsNotNull(interaction.Pages, "interaction.Pages is not initialized."); + if (this.filterByCustomData) + { + IEnumerable source = Enumerable.Where(Enumerable.SelectMany((IEnumerable)interaction.Pages, (Func>)((Page page) => page.PageEvents)), (Func)delegate (PageEventData pageEvent) + { + if (!pageEvent.IsGoal) + { + Guid pageEventDefinitionId3 = pageEvent.PageEventDefinitionId; + Guid? b3 = this.GoalGuid; + return (Guid?)pageEventDefinitionId3 == b3; + } + return false; + }); + if (this.CustomData == null) + { + Log.Warn("CustomData can not be null", (object)base.GetType()); + return false; + } + IEnumerable source2 = Enumerable.Where(source, (Func)delegate (PageEventData entry) + { + if (entry.Data != null) + { + return ConditionsUtility.CompareStrings(entry.Data, this.CustomData, this.CustomDataOperatorId); + } + return false; + }); + return Enumerable.Any(source2, (Func)delegate (PageEventData entry) + { + Guid pageEventDefinitionId2 = entry.PageEventDefinitionId; + Guid? b2 = this.GoalGuid; + return (Guid?)pageEventDefinitionId2 == b2; + }); + } + var result = interaction.Pages.SelectMany(page => page.PageEvents).Any(pageEvent => pageEvent.IsGoal && pageEvent.PageEventDefinitionId == GoalGuid); + return result; } } +} -} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/HasEventOccurredCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/HasEventOccurredCondition.cs index f09b4be..1aa4314 100644 --- a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/HasEventOccurredCondition.cs +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/HasEventOccurredCondition.cs @@ -1,123 +1,89 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web; +using Sitecore.Analytics.Tracking; +using Sitecore.Diagnostics; +using Sitecore.Rules; +using Sitecore.Rules.Conditions; +using ConditionsUtility = Sitecore.Support.Rules.Conditions.ConditionsUtility; namespace Sitecore.Support.Analytics.Rules.Conditions { - - - // Sitecore.Support.Analytics.Rules.Conditions.HasEventOccurredCondition - using Sitecore.Analytics.Tracking; - using Sitecore.Diagnostics; - using Sitecore.Rules; - using Sitecore.Rules.Conditions; - using System; - using System.Collections.Generic; - using System.Linq; - - public abstract class HasEventOccurredCondition:WhenCondition where T : RuleContext + public abstract class HasEventOccurredCondition : WhenCondition where T : RuleContext { private readonly bool filterByCustomData; - public string CustomData + protected HasEventOccurredCondition(bool filterByCustomData) { - get; - set; + this.filterByCustomData = filterByCustomData; } - public string CustomDataOperatorId - { - get; - set; - } + public string CustomData { get; set; } - public int NumberOfElapsedDays - { - get; - set; - } + public string CustomDataOperatorId { get; set; } - public string NumberOfElapsedDaysOperatorId - { - get; - set; - } + public int NumberOfElapsedDays { get; set; } - public int NumberOfPastInteractions - { - get; - set; - } + public string NumberOfElapsedDaysOperatorId { get; set; } - public string NumberOfPastInteractionsOperatorId - { - get; - set; - } + public int NumberOfPastInteractions { get; set; } - protected HasEventOccurredCondition(bool filterByCustomData) - : base() - { - this.filterByCustomData = filterByCustomData; - } + public string NumberOfPastInteractionsOperatorId { get; set; } protected virtual IEnumerable FilterKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) { - Assert.ArgumentNotNull((object)keyBehaviorCache, "keyBehaviorCache"); - IEnumerable keyBehaviorCacheEntries = Enumerable.Concat(Enumerable.Concat(Enumerable.Concat(Enumerable.Concat(Enumerable.Concat(Enumerable.Concat((IEnumerable)keyBehaviorCache.Campaigns, (IEnumerable)keyBehaviorCache.Channels), (IEnumerable)keyBehaviorCache.CustomValues), (IEnumerable)keyBehaviorCache.Goals), (IEnumerable)keyBehaviorCache.Outcomes), (IEnumerable)keyBehaviorCache.PageEvents), (IEnumerable)keyBehaviorCache.Venues); - IEnumerable enumerable = this.FilterKeyBehaviorCacheEntriesByInteractionConditions(keyBehaviorCacheEntries); - if (this.filterByCustomData) + Assert.ArgumentNotNull(keyBehaviorCache, "keyBehaviorCache"); + var behaviorCacheEntries = + FilterKeyBehaviorCacheEntriesByInteractionConditions( + keyBehaviorCache.Campaigns.Concat(keyBehaviorCache.Channels) + .Concat(keyBehaviorCache.CustomValues) + .Concat(keyBehaviorCache.Goals) + .Concat(keyBehaviorCache.Outcomes) + .Concat(keyBehaviorCache.PageEvents) + .Concat(keyBehaviorCache.Venues)); + if (!filterByCustomData) + return + Assert.ResultNotNull(GetKeyBehaviorCacheEntries(keyBehaviorCache) + .Intersect(behaviorCacheEntries, new KeyBehaviorCacheEntry.KeyBehaviorCacheEntryEqualityComparer())); + if (CustomData == null) { - if (this.CustomData == null) - { - Log.Warn("CustomData can not be null", (object)base.GetType()); - return Enumerable.Empty(); - } - enumerable = Enumerable.Where(enumerable, (Func)delegate (KeyBehaviorCacheEntry entry) - { - //IL_0000: Unknown result type (might be due to invalid IL or missing references) - //IL_0008: Unknown result type (might be due to invalid IL or missing references) - if (entry.Data != null) - { - return ConditionsUtility.CompareStrings(entry.Data, this.CustomData, this.CustomDataOperatorId); - } - return false; - }); + Log.Warn("CustomData can not be null", GetType()); + return Enumerable.Empty(); } - return Assert.ResultNotNull>(Enumerable.Intersect(this.GetKeyBehaviorCacheEntries(keyBehaviorCache), enumerable, (IEqualityComparer)new Sitecore.Analytics.Model.Entities.KeyBehaviorCacheEntryEqualityComparer())); + behaviorCacheEntries = behaviorCacheEntries.Where(entry => + { + return entry.Data != null && ConditionsUtility.CompareStrings(entry.Data, CustomData, CustomDataOperatorId); + }); + return + Assert.ResultNotNull(GetKeyBehaviorCacheEntries(keyBehaviorCache) + .Intersect(behaviorCacheEntries, new KeyBehaviorCacheEntry.KeyBehaviorCacheEntryEqualityComparer())); } - protected virtual IEnumerable FilterKeyBehaviorCacheEntriesByInteractionConditions(IEnumerable keyBehaviorCacheEntries) + protected virtual IEnumerable FilterKeyBehaviorCacheEntriesByInteractionConditions( + IEnumerable keyBehaviorCacheEntries) { - Assert.ArgumentNotNull((object)keyBehaviorCacheEntries, "keyBehaviorCacheEntries"); - if (ConditionsUtility.GetInt32Comparer(this.NumberOfElapsedDaysOperatorId) == null) - { + Assert.ArgumentNotNull(keyBehaviorCacheEntries, "keyBehaviorCacheEntries"); + if (ConditionsUtility.GetInt32Comparer(NumberOfElapsedDaysOperatorId) == null) return Enumerable.Empty(); - } - Func numberOfPastInteractionsComparer = ConditionsUtility.GetInt32Comparer(this.NumberOfPastInteractionsOperatorId); - Func numberOfElapsedDaysOperatorsComparer = ConditionsUtility.GetInt32Comparer(this.NumberOfElapsedDaysOperatorId); + var numberOfPastInteractionsComparer = ConditionsUtility.GetInt32Comparer(NumberOfPastInteractionsOperatorId); + var numberOfElapsedDaysOperatorsComparer = ConditionsUtility.GetInt32Comparer(NumberOfElapsedDaysOperatorId); if (numberOfPastInteractionsComparer == null) - { return Enumerable.Empty(); - } - return Assert.ResultNotNull>(Enumerable.SelectMany(Enumerable.Where(Enumerable.OrderByDescending(Enumerable.GroupBy(keyBehaviorCacheEntries, (KeyBehaviorCacheEntry entry) => new + return Assert.ResultNotNull(keyBehaviorCacheEntries.GroupBy(entry => new { - InteractionId = entry.InteractionId, - InteractionStartDateTime = entry.InteractionStartDateTime - }), entries => entries.Key.InteractionStartDateTime), (entries, i) => + entry.InteractionId, + entry.InteractionStartDateTime + }).OrderByDescending(entries => entries.Key.InteractionStartDateTime).Where((entries, i) => { - if (numberOfElapsedDaysOperatorsComparer((DateTime.UtcNow - entries.Key.InteractionStartDateTime).Days, this.NumberOfElapsedDays)) - { - return numberOfPastInteractionsComparer(i + 2, this.NumberOfPastInteractions); - } + if (numberOfElapsedDaysOperatorsComparer((DateTime.UtcNow - entries.Key.InteractionStartDateTime).Days, + NumberOfElapsedDays)) + return numberOfPastInteractionsComparer(i + 2, ((HasEventOccurredCondition)this).NumberOfPastInteractions); return false; - }), entries => (IEnumerable)entries)); + }).SelectMany(entries => (IEnumerable)entries)); } protected abstract IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache); protected abstract bool HasEventOccurredInInteraction(IInteractionData interaction); } - } \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWasTriggeredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWasTriggeredDuringPastOrCurrentInteractionCondition.cs index db53c2f..faf705f 100644 --- a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWasTriggeredDuringPastOrCurrentInteractionCondition.cs +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -1,4 +1,6 @@ -namespace Sitecore.Support.Analytics.Rules.Conditions +using Sitecore.Support.Rules.Conditions; + +namespace Sitecore.Support.Analytics.Rules.Conditions { using Sitecore.Analytics; using Sitecore.Analytics.Core; @@ -16,7 +18,7 @@ public class PageEventWasTriggeredDuringPastOrCurrentInteractionCondition : H private Guid? pageEventGuid; private bool pageEventGuidInitialized; - + private bool filterByCustomData; public string PageEventId { get; @@ -52,6 +54,7 @@ public PageEventWasTriggeredDuringPastOrCurrentInteractionCondition() protected PageEventWasTriggeredDuringPastOrCurrentInteractionCondition(bool filterByCustomData) : base(filterByCustomData) { + this.filterByCustomData = filterByCustomData; } protected override bool Execute(T ruleContext) @@ -88,6 +91,40 @@ protected override bool HasEventOccurredInInteraction(IInteractionData interacti { Assert.ArgumentNotNull((object)interaction, "interaction"); Assert.IsNotNull((object)interaction.Pages, "interaction.Pages is not initialized."); + if (this.filterByCustomData) + { + IEnumerable source = Enumerable.Where(Enumerable.SelectMany((IEnumerable)interaction.Pages, (Func>)((Page page) => page.PageEvents)), (Func)delegate (PageEventData pageEvent) + { + + if (!pageEvent.IsGoal) + { + Guid pageEventDefinitionId3 = pageEvent.PageEventDefinitionId; + Guid? b3 = this.PageEventGuid; + return (Guid?)pageEventDefinitionId3 == b3; + } + return false; + }); + if (this.CustomData == null) + { + Log.Warn("CustomData can not be null", (object)base.GetType()); + return false; + } + IEnumerable source2 = Enumerable.Where(source, (Func)delegate (PageEventData entry) + { + + if (entry.Data != null) + { + return ConditionsUtility.CompareStrings(entry.Data, this.CustomData, this.CustomDataOperatorId); + } + return false; + }); + return Enumerable.Any(source2, (Func)delegate (PageEventData entry) + { + Guid pageEventDefinitionId2 = entry.PageEventDefinitionId; + Guid? b2 = this.PageEventGuid; + return (Guid?)pageEventDefinitionId2 == b2; + }); + } return Enumerable.Any(Enumerable.SelectMany((IEnumerable)interaction.Pages, (Func>)((Page page) => page.PageEvents)), (Func)delegate (PageEventData pageEvent) { if (!pageEvent.IsGoal) diff --git a/src/Sitecore.Support.129513/Rules/Conditions/CondtionsUtility.cs b/src/Sitecore.Support.129513/Rules/Conditions/CondtionsUtility.cs index 8aea0f8..c80f58f 100644 --- a/src/Sitecore.Support.129513/Rules/Conditions/CondtionsUtility.cs +++ b/src/Sitecore.Support.129513/Rules/Conditions/CondtionsUtility.cs @@ -1,109 +1,101 @@ -namespace Sitecore.Support.Rules.Conditions -{ - using Sitecore.Diagnostics; - using Sitecore.Rules.Conditions; - using System; - using System.Text.RegularExpressions; +using System; +using System.Text.RegularExpressions; +using Sitecore.Diagnostics; +using Sitecore.Rules.Conditions; +namespace Sitecore.Support.Rules.Conditions +{ internal static class ConditionsUtility { internal static ConditionOperator GetConditionOperatorById(string conditionOperatorId) { if (string.IsNullOrEmpty(conditionOperatorId)) - { return ConditionOperator.Unknown; - } - if (conditionOperatorId != null) + switch (conditionOperatorId) { - if (conditionOperatorId == "{066602E2-ED1D-44C2-A698-7ED27FD3A2CC}") - { + case "{066602E2-ED1D-44C2-A698-7ED27FD3A2CC}": return ConditionOperator.Equal; - } - if (conditionOperatorId == "{814EF7D0-1639-44FD-AEEF-735B5AC14425}") - { + case "{814EF7D0-1639-44FD-AEEF-735B5AC14425}": return ConditionOperator.GreaterThanOrEqual; - } - if (conditionOperatorId == "{B88CD556-082E-4385-BB76-E4D1B565F290}") - { + case "{B88CD556-082E-4385-BB76-E4D1B565F290}": return ConditionOperator.GreaterThan; - } - if (conditionOperatorId == "{2E1FC840-5919-4C66-8182-A33A1039EDBF}") - { + case "{2E1FC840-5919-4C66-8182-A33A1039EDBF}": return ConditionOperator.LessThanOrEqual; - } - if (conditionOperatorId == "{E362A3A4-E230-4A40-A7C4-FC42767E908F}") - { + case "{E362A3A4-E230-4A40-A7C4-FC42767E908F}": return ConditionOperator.LessThan; - } - if (conditionOperatorId == "{3627ED99-F454-4B83-841A-A0194F0FB8B4}") - { - return ConditionOperator.NotEqual; - } } - return 0; + return conditionOperatorId == "{3627ED99-F454-4B83-841A-A0194F0FB8B4}" + ? ConditionOperator.NotEqual + : ConditionOperator.Unknown; } internal static Func GetInt32Comparer(string conditionOperatorId) { - return ConditionsUtility.GetInt32Comparer(ConditionsUtility.GetConditionOperatorById(conditionOperatorId)); + return GetInt32Comparer(GetConditionOperatorById(conditionOperatorId)); } internal static Func GetInt32Comparer(ConditionOperator conditionOperator) { - switch (conditionOperator - 1) + switch (conditionOperator) { case ConditionOperator.Equal: - return (int first, int second) => first == second; + return (first, second) => first == second; case ConditionOperator.GreaterThanOrEqual: - return (int first, int second) => first >= second; + return (first, second) => first >= second; case ConditionOperator.GreaterThan: - return (int first, int second) => first > second; + return (first, second) => first > second; case ConditionOperator.LessThanOrEqual: - return (int first, int second) => first <= second; + return + (first, second) => + first <= second; case ConditionOperator.LessThan: - return (int first, int second) => first < second; + return (first, second) => + first < second; case ConditionOperator.NotEqual: - return (int first, int second) => first != second; + return (first, second) => first != second; default: return null; } } - internal static StringConditionOperator GetStringConditionOperatorById(string conditionOperatorId) + public static StringConditionOperator GetStringConditionOperatorById(string conditionOperatorId) { - if (string.IsNullOrEmpty(conditionOperatorId)) - { - return 0; - } - switch (conditionOperatorId) - { - case "{10537C58-1684-4CAB-B4C0-40C10907CE31}": - return StringConditionOperator.Equals; - case "{537244C2-3A3F-4B81-A6ED-02AF494C0563}": - return StringConditionOperator.CaseInsensitivelyEquals; - case "{2E67477C-440C-4BCA-A358-3D29AED89F47}": - return StringConditionOperator.Contains; - case "{F8641C26-EE27-483C-9FEA-35529ECC8541}": - return StringConditionOperator.MatchesRegularExpression; - case "{A6AC5A6B-F409-48B0-ACE7-C3E8C5EC6406}": - return StringConditionOperator.NotEqual; - case "{6A7294DF-ECAE-4D5F-A8D2-C69CB1161C09}": - return StringConditionOperator.NotCaseInsensitivelyEquals; - case "{22E1F05F-A17A-4D0C-B376-6F7661500F03}": - return StringConditionOperator.EndsWith; - case "{FDD7C6B1-622A-4362-9CFF-DDE9866C68EA}": - return StringConditionOperator.StartsWith; - default: - return StringConditionOperator.Unknown; - } + if (!string.IsNullOrEmpty(conditionOperatorId)) + switch (conditionOperatorId) + { + case "{10537C58-1684-4CAB-B4C0-40C10907CE31}": + return StringConditionOperator.Equals; + + case "{537244C2-3A3F-4B81-A6ED-02AF494C0563}": + return StringConditionOperator.CaseInsensitivelyEquals; + + case "{2E67477C-440C-4BCA-A358-3D29AED89F47}": + return StringConditionOperator.Contains; + + case "{F8641C26-EE27-483C-9FEA-35529ECC8541}": + return StringConditionOperator.MatchesRegularExpression; + + case "{A6AC5A6B-F409-48B0-ACE7-C3E8C5EC6406}": + return StringConditionOperator.NotEqual; + + case "{6A7294DF-ECAE-4D5F-A8D2-C69CB1161C09}": + return StringConditionOperator.NotCaseInsensitivelyEquals; + + case "{22E1F05F-A17A-4D0C-B376-6F7661500F03}": + return StringConditionOperator.EndsWith; + + case "{FDD7C6B1-622A-4362-9CFF-DDE9866C68EA}": + return StringConditionOperator.StartsWith; + } + return StringConditionOperator.Unknown; } + internal static bool CompareStrings(string first, string second, string conditionOperatorId) { - Assert.ArgumentNotNull((object)first, "first"); - Assert.ArgumentNotNull((object)second, "second"); - StringConditionOperator stringConditionOperatorById = ConditionsUtility.GetStringConditionOperatorById(conditionOperatorId); - switch (stringConditionOperatorById - 1) + Assert.ArgumentNotNull(first, "first"); + Assert.ArgumentNotNull(second, "second"); + switch (GetStringConditionOperatorById(conditionOperatorId)) { case StringConditionOperator.Equals: return first == second; @@ -112,7 +104,7 @@ internal static bool CompareStrings(string first, string second, string conditio case StringConditionOperator.NotEqual: return first != second; case StringConditionOperator.NotCaseInsensitivelyEquals: - return string.Compare(first, second, StringComparison.CurrentCultureIgnoreCase) != 0; + return (uint)string.Compare(first, second, StringComparison.CurrentCultureIgnoreCase) > 0U; case StringConditionOperator.Contains: return first.IndexOf(second, StringComparison.CurrentCultureIgnoreCase) >= 0; case StringConditionOperator.MatchesRegularExpression: @@ -126,5 +118,4 @@ internal static bool CompareStrings(string first, string second, string conditio } } } - } \ No newline at end of file