From 7ed652832877c9071b0deb79785f039ff533faad Mon Sep 17 00:00:00 2001 From: gpo Date: Fri, 14 Dec 2018 11:45:04 -0500 Subject: [PATCH] First commit --- src/Sitecore.Support.129513.sln | 22 +++ ...DuringPastOrCurrentInteractionCondition.cs | 108 +++++++++++++ ...DuringPastOrCurrentInteractionCondition.cs | 12 ++ .../Rules/Conditions/TrackerExtensions.cs | 33 ++++ ...DuringPastOrCurrentInteractionCondition.cs | 101 ++++++++++++ ...DuringPastOrCurrentInteractionCondition.cs | 12 ++ ...nnelOfPastOrCurrentInteractionCondition.cs | 96 ++++++++++++ ...DataOfPastOrCurrentInteractionCondition.cs | 12 ++ ...DuringPastOrCurrentInteractionCondition.cs | 144 ++++++++++++++++++ ...DuringPastOrCurrentInteractionCondition.cs | 12 ++ .../Conditions/HasEventOccurredCondition.cs | 106 +++++++++++++ ...DuringPastOrCurrentInteractionCondition.cs | 114 ++++++++++++++ ...DuringPastOrCurrentInteractionCondition.cs | 12 ++ ...enueOfPastOrCurrentInteractionCondition.cs | 99 ++++++++++++ ...DataOfPastOrCurrentInteractionCondition.cs | 12 ++ .../zzz/Sitecore.Support.129513.config | 7 + .../Hooks/UpdateTypeFieldGoalItems.cs | 84 ++++++++++ .../Properties/AssemblyInfo.cs | 6 + .../Rules/Conditions/CondtionsUtility.cs | 118 ++++++++++++++ .../Sitecore.Support.129513.csproj | 122 +++++++++++++++ src/Sitecore.Support.129513/packages.config | 8 + src/Sitecore.Support.129513/web.config | 4 + 22 files changed, 1244 insertions(+) create mode 100644 src/Sitecore.Support.129513.sln create mode 100644 src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWithCustomDataWasRegisteredDuringPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/TrackerExtensions.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWasTriggeredDuringPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelOfPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelWithCustomDataOfPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWasTriggeredDuringPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/HasEventOccurredCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWasTriggeredDuringPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/VenueOfPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/Analytics/Rules/Conditions/VenueWithCustomDataOfPastOrCurrentInteractionCondition.cs create mode 100644 src/Sitecore.Support.129513/App_Config/Include/zzz/Sitecore.Support.129513.config create mode 100644 src/Sitecore.Support.129513/Hooks/UpdateTypeFieldGoalItems.cs create mode 100644 src/Sitecore.Support.129513/Properties/AssemblyInfo.cs create mode 100644 src/Sitecore.Support.129513/Rules/Conditions/CondtionsUtility.cs create mode 100644 src/Sitecore.Support.129513/Sitecore.Support.129513.csproj create mode 100644 src/Sitecore.Support.129513/packages.config create mode 100644 src/Sitecore.Support.129513/web.config diff --git a/src/Sitecore.Support.129513.sln b/src/Sitecore.Support.129513.sln new file mode 100644 index 0000000..0bfce9b --- /dev/null +++ b/src/Sitecore.Support.129513.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{4B5CC991-628B-4559-A040-804E517E5C15}") = "Sitecore.Support.129513", "Sitecore.Support.129513\Sitecore.Support.129513.csproj", "{82E3C87F-7DA4-4F8F-B779-A8F0EB751547}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {82E3C87F-7DA4-4F8F-B779-A8F0EB751547}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82E3C87F-7DA4-4F8F-B779-A8F0EB751547}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82E3C87F-7DA4-4F8F-B779-A8F0EB751547}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82E3C87F-7DA4-4F8F-B779-A8F0EB751547}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..39a79a3 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition.cs @@ -0,0 +1,108 @@ +using Sitecore.Analytics; +using Sitecore.Analytics.Outcome.Model; +using Sitecore.Analytics.Tracking; +using Sitecore.Data; +using Sitecore.Diagnostics; +using Sitecore.Rules; +using Sitecore.Support.Analytics.Rules.Conditions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Sitecore.Support.Analytics.Outcome.Rules.Conditions +{ + public class OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition : HasEventOccurredCondition where T : RuleContext + { + private Guid? outcomeGuid; + + private bool outcomeGuidInitialized; + + public string OutcomeId { get; set; } + + private Guid? OutcomeGuid + { + get + { + if (this.outcomeGuidInitialized) + { + return this.outcomeGuid; + } + + try + { + this.outcomeGuid = new Guid(this.OutcomeId); + } + catch + { + Log.Warn(string.Format("Could not convert value to guid: {0}", this.OutcomeId), (object)base.GetType()); + } + + this.outcomeGuidInitialized = true; + return this.outcomeGuid; + } + } + + public OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition() + : base(false) + { + } + + protected OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition(bool filterByCustomData) + : base(filterByCustomData) + { + } + + protected override bool Execute(T ruleContext) + { + 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.OutcomeGuid.HasValue) + { + return false; + } + + if (this.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); + + return Enumerable.Any(this.FilterKeyBehaviorCacheEntries(keyBehaviorCache), (Func)delegate (KeyBehaviorCacheEntry entry) + { + + Guid id = entry.Id; + Guid? b = this.OutcomeGuid; + return (Guid?)id == b; + }); + } + + protected override IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) + { + Assert.ArgumentNotNull((object)keyBehaviorCache, "keyBehaviorCache"); + return keyBehaviorCache.Outcomes; + } + + protected override bool HasEventOccurredInInteraction(IInteractionData interaction) + { + Assert.ArgumentNotNull((object)interaction, "interaction"); + Assert.IsNotNull((object)Tracker.Current, "Tracker.Current is not initialized"); + Assert.IsNotNull((object)Tracker.Current.Contact, "Tracker.Current.Contact is not initialized"); + + return Enumerable.Any(Enumerable.Select, IOutcome>((IEnumerable>)TrackerExtensions.GetContactOutcomes(Tracker.Current.Session), (Func, IOutcome>)((KeyValuePair keyValuePair) => keyValuePair.Value)), (Func)delegate (IOutcome outcome) + { + if (!outcome.InteractionId.IsNull && outcome.InteractionId.Guid == interaction.InteractionId) + { + Guid guid = outcome.DefinitionId.Guid; + Guid? b = this.OutcomeGuid; + return (Guid?)guid == b; + } + + return false; + }); + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWithCustomDataWasRegisteredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWithCustomDataWasRegisteredDuringPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..258a739 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/OutcomeWithCustomDataWasRegisteredDuringPastOrCurrentInteractionCondition.cs @@ -0,0 +1,12 @@ +using Sitecore.Rules; + +namespace Sitecore.Support.Analytics.Outcome.Rules.Conditions +{ + public class OutcomeWithCustomDataWasRegisteredDuringPastOrCurrentInteractionCondition : OutcomeWasRegisteredDuringPastOrCurrentInteractionCondition where T : RuleContext + { + public OutcomeWithCustomDataWasRegisteredDuringPastOrCurrentInteractionCondition() + : base(true) + { + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/TrackerExtensions.cs b/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/TrackerExtensions.cs new file mode 100644 index 0000000..33b59ee --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Outcome/Rules/Conditions/TrackerExtensions.cs @@ -0,0 +1,33 @@ +using Sitecore.Analytics.Outcome.Model; +using Sitecore.Analytics.Tracking; +using Sitecore.Common; +using Sitecore.Data; +using Sitecore.Diagnostics; +using System.Collections.Generic; + +namespace Sitecore.Support.Analytics.Outcome.Rules.Conditions +{ + public static class TrackerExtensions + { + internal static Dictionary GetContactOutcomes(Session session) + { + Dictionary dictionary; + if (session.CustomData.ContainsKey("Sitecore.Analytics.Outcome#Outcomes")) + { + dictionary = (session.CustomData["Sitecore.Analytics.Outcome#Outcomes"] as Dictionary); + string text = string.Format("Outcome data in session for the contact {0} contained the key {1}, but the type of the object was not Dictionary as expected.", session.Contact.ContactId, "Sitecore.Analytics.Outcome#Outcomes"); + Assert.IsNotNull((object)dictionary, text); + foreach (IOutcome value in dictionary.Values) + { + value.EntityId=(TypeExtensions.ToID(session.Contact.ContactId)); + } + + return dictionary; + } + + dictionary = new Dictionary(); + session.CustomData["Sitecore.Analytics.Outcome#Outcomes"] = dictionary; + return dictionary; + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWasTriggeredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWasTriggeredDuringPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..8df7bae --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -0,0 +1,101 @@ +using Sitecore.Analytics; +using Sitecore.Analytics.Tracking; +using Sitecore.Diagnostics; +using Sitecore.Rules; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class CampaignWasTriggeredDuringPastOrCurrentInteractionCondition : HasEventOccurredCondition where T : RuleContext + { + private Guid? campaignGuid; + + private bool campaignGuidInitialized; + + private bool filterByCustomData; + + public string CampaignId { get; set; } + + private Guid? CampaignGuid + { + get + { + if (this.campaignGuidInitialized) + { + return this.campaignGuid; + } + + try + { + this.campaignGuid = new Guid(this.CampaignId); + } + catch + { + Log.Warn(string.Format("Could not convert value to guid: {0}", this.CampaignId), (object)base.GetType()); + } + + this.campaignGuidInitialized = true; + return this.campaignGuid; + } + } + + public CampaignWasTriggeredDuringPastOrCurrentInteractionCondition() + : base(false) + { + } + + protected CampaignWasTriggeredDuringPastOrCurrentInteractionCondition(bool filterByCustomData) + : base(filterByCustomData) + { + this.filterByCustomData = filterByCustomData; + } + + protected override bool Execute(T ruleContext) + { + 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.CampaignGuid.HasValue) + { + return false; + } + + if (this.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); + + return Enumerable.Any(this.FilterKeyBehaviorCacheEntries(keyBehaviorCache), (Func)delegate (KeyBehaviorCacheEntry entry) + { + Guid id = entry.Id; + Guid? b = this.CampaignGuid; + return (Guid?)id == b; + }); + } + + protected override IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) + { + Assert.ArgumentNotNull((object)keyBehaviorCache, "keyBehaviorCache"); + return keyBehaviorCache.Campaigns; + } + + protected override bool HasEventOccurredInInteraction(IInteractionData interaction) + { + Assert.ArgumentNotNull((object)interaction, "interaction"); + if (interaction.CampaignId.HasValue) + { + Guid value = interaction.CampaignId.Value; + Guid? b = this.CampaignGuid; + return (Guid?)value == b; + } + + return false; + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..2a27927 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/CampaignWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -0,0 +1,12 @@ +using Sitecore.Rules; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class CampaignWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition : CampaignWasTriggeredDuringPastOrCurrentInteractionCondition where T : RuleContext + { + public CampaignWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition() + : base(true) + { + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelOfPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelOfPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..a366083 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelOfPastOrCurrentInteractionCondition.cs @@ -0,0 +1,96 @@ +using Sitecore.Analytics; +using Sitecore.Analytics.Tracking; +using Sitecore.Diagnostics; +using Sitecore.Rules; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class ChannelOfPastOrCurrentInteractionCondition : HasEventOccurredCondition where T : RuleContext + { + private Guid? channelGuid; + + private bool channelGuidInitialized; + + private bool filterByCustomData; + + public string ChannelId { get; set; } + + private Guid? ChannelGuid + { + get + { + if (this.channelGuidInitialized) + { + return this.channelGuid; + } + + try + { + this.channelGuid = new Guid(this.ChannelId); + } + catch + { + Log.Warn(string.Format("Could not convert value to guid: {0}", this.ChannelId), (object)base.GetType()); + } + + this.channelGuidInitialized = true; + return this.channelGuid; + } + } + + public ChannelOfPastOrCurrentInteractionCondition() + : base(false) + { + } + + protected ChannelOfPastOrCurrentInteractionCondition(bool filterByCustomData) + : base(filterByCustomData) + { + this.filterByCustomData = filterByCustomData; + } + + protected override bool Execute(T ruleContext) + { + 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.ChannelGuid.HasValue) + { + return false; + } + + if (!this.HasEventOccurredInInteraction(Tracker.Current.Session.Interaction)) + { + 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) + { + Guid id = entry.Id; + Guid? b = this.ChannelGuid; + return (Guid?)id == b; + }); + } + + protected override IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) + { + Assert.ArgumentNotNull((object)keyBehaviorCache, "keyBehaviorCache"); + return keyBehaviorCache.Channels; + } + + protected override bool HasEventOccurredInInteraction(IInteractionData interaction) + { + Assert.ArgumentNotNull((object)interaction, "interaction"); + Guid channelId = interaction.ChannelId; + Guid? b = this.ChannelGuid; + return (Guid?)channelId == b; + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelWithCustomDataOfPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelWithCustomDataOfPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..c4a2a88 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/ChannelWithCustomDataOfPastOrCurrentInteractionCondition.cs @@ -0,0 +1,12 @@ +using Sitecore.Rules; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class ChannelWithCustomDataOfPastOrCurrentInteractionCondition : ChannelOfPastOrCurrentInteractionCondition where T : RuleContext + { + public ChannelWithCustomDataOfPastOrCurrentInteractionCondition() + : base(true) + { + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWasTriggeredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWasTriggeredDuringPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..900c4cd --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -0,0 +1,144 @@ +using Sitecore.Analytics; +using Sitecore.Analytics.Core; +using Sitecore.Analytics.Model; +using Sitecore.Analytics.Tracking; +using Sitecore.Diagnostics; +using Sitecore.Rules; +using Sitecore.Support.Rules.Conditions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class GoalWasTriggeredDuringPastOrCurrentInteractionCondition : HasEventOccurredCondition where T : RuleContext + { + private Guid? _goalGuid; + + private bool _goalGuidInitialized; + + private bool filterByCustomData; + + public GoalWasTriggeredDuringPastOrCurrentInteractionCondition() + : base(false) + { + } + + protected GoalWasTriggeredDuringPastOrCurrentInteractionCondition(bool filterByCustomData) + : base(filterByCustomData) + { + this.filterByCustomData = filterByCustomData; + } + + [NotNull] + public string GoalId { get; set; } + + private Guid? GoalGuid + { + get + { + if (_goalGuidInitialized) + { + return _goalGuid; + } + + try + { + _goalGuid = new Guid(GoalId); + } + catch + { + Log.Warn($"Could not convert value to guid: {GoalId}", GetType()); + } + + _goalGuidInitialized = true; + + return _goalGuid; + } + } + + protected override bool Execute([NotNull] T ruleContext) + { + 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 (HasEventOccurredInInteraction(Tracker.Current.Session.Interaction)) + { + return true; + } + + 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) + { + Guid id = entry.Id; + Guid? b = this.GoalGuid; + return (Guid?)id == b; + }); + } + + protected override IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) + { + Assert.ArgumentNotNull(keyBehaviorCache, "keyBehaviorCache"); + + return keyBehaviorCache.Goals; + } + + protected override bool HasEventOccurredInInteraction(IInteractionData interaction) + { + 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; + }); + } + + return interaction.Pages + .SelectMany(page => page.PageEvents) + .Any(pageEvent => pageEvent.IsGoal && pageEvent.PageEventDefinitionId == GoalGuid); + } + } +} + diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..bcded6b --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/GoalWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -0,0 +1,12 @@ +using Sitecore.Rules; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class GoalWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition : GoalWasTriggeredDuringPastOrCurrentInteractionCondition where T : RuleContext + { + public GoalWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition() + : base(true) + { + } + } +} \ 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 new file mode 100644 index 0000000..6873e97 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/HasEventOccurredCondition.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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 +{ + public abstract class HasEventOccurredCondition : WhenCondition where T : RuleContext + { + private readonly bool filterByCustomData; + + protected HasEventOccurredCondition(bool filterByCustomData) + { + this.filterByCustomData = filterByCustomData; + } + + public string CustomData { get; set; } + + public string CustomDataOperatorId { get; set; } + + public int NumberOfElapsedDays { get; set; } + + public string NumberOfElapsedDaysOperatorId { get; set; } + + public int NumberOfPastInteractions { get; set; } + + public string NumberOfPastInteractionsOperatorId { get; set; } + + protected virtual IEnumerable FilterKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) + { + 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) + { + Log.Warn("CustomData can not be null", GetType()); + return Enumerable.Empty(); + } + + 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) + { + Assert.ArgumentNotNull(keyBehaviorCacheEntries, "keyBehaviorCacheEntries"); + if (ConditionsUtility.GetInt32Comparer(NumberOfElapsedDaysOperatorId) == null) + { + return Enumerable.Empty(); + } + + var numberOfPastInteractionsComparer = ConditionsUtility.GetInt32Comparer(NumberOfPastInteractionsOperatorId); + var numberOfElapsedDaysOperatorsComparer = ConditionsUtility.GetInt32Comparer(NumberOfElapsedDaysOperatorId); + if (numberOfPastInteractionsComparer == null) + { + return Enumerable.Empty(); + } + + var selectedEntries = keyBehaviorCacheEntries + .GroupBy(entry => new + { + entry.InteractionId, + entry.InteractionStartDateTime + }) + .OrderByDescending(entries => entries.Key.InteractionStartDateTime) + .Where((entries, i) => + { + if (numberOfElapsedDaysOperatorsComparer((DateTime.UtcNow - entries.Key.InteractionStartDateTime).Days, NumberOfElapsedDays)) + { + return numberOfPastInteractionsComparer(i + 2, ((HasEventOccurredCondition)this).NumberOfPastInteractions); + } + + return false; + }) + .SelectMany(entries => (IEnumerable)entries); + + return Assert.ResultNotNull(selectedEntries); + } + + 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 new file mode 100644 index 0000000..b4a51c6 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -0,0 +1,114 @@ +using Sitecore.Analytics; +using Sitecore.Analytics.Tracking; +using Sitecore.Diagnostics; +using Sitecore.Rules; +using Sitecore.Support.Rules.Conditions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class PageEventWasTriggeredDuringPastOrCurrentInteractionCondition : HasEventOccurredCondition where T : RuleContext + { + private Guid? pageEventGuid; + + private bool pageEventGuidInitialized; + + private bool filterByCustomData; + + public string PageEventId { get; set; } + + private Guid? PageEventGuid + { + get + { + if (this.pageEventGuidInitialized) + { + return this.pageEventGuid; + } + + try + { + this.pageEventGuid = new Guid(this.PageEventId); + } + catch + { + Log.Warn(string.Format("Could not convert value to guid: {0}", this.PageEventId), (object)base.GetType()); + } + + this.pageEventGuidInitialized = true; + return this.pageEventGuid; + } + } + + public PageEventWasTriggeredDuringPastOrCurrentInteractionCondition() + : base(false) + { + } + + protected PageEventWasTriggeredDuringPastOrCurrentInteractionCondition(bool filterByCustomData) + : base(filterByCustomData) + { + this.filterByCustomData = filterByCustomData; + } + + protected override bool Execute(T ruleContext) + { + 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.PageEventGuid.HasValue) + { + return false; + } + + if (this.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); + + return FilterKeyBehaviorCacheEntries(keyBehaviorCache).Any(entry => (Guid?)entry.Id == this.pageEventGuid); + } + + protected override IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) + { + Assert.ArgumentNotNull((object)keyBehaviorCache, "keyBehaviorCache"); + return keyBehaviorCache.PageEvents; + } + + protected override bool HasEventOccurredInInteraction(IInteractionData interaction) + { + Assert.ArgumentNotNull((object)interaction, "interaction"); + Assert.IsNotNull((object)interaction.Pages, "interaction.Pages is not initialized."); + + var pageEvents = interaction.Pages + .SelectMany(page => page.PageEvents) + .Where(pageEvent => !pageEvent.IsGoal ? (Guid?)pageEvent.PageEventDefinitionId == this.PageEventGuid : false); + + if (this.filterByCustomData) + { + if (this.CustomData == null) + { + Log.Warn("CustomData can not be null", (object)base.GetType()); + return false; + } + + var source2 = pageEvents.Where(entry => entry.Data != null && ConditionsUtility.CompareStrings(entry.Data, this.CustomData, this.CustomDataOperatorId)); + + return source2.Any(entry => + { + Guid pageEventDefinitionId2 = entry.PageEventDefinitionId; + Guid? b2 = this.PageEventGuid; + return (Guid?)pageEventDefinitionId2 == b2; + }); + } + + return pageEvents.Any(); + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..16658d0 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/PageEventWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition.cs @@ -0,0 +1,12 @@ +using Sitecore.Rules; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class PageEventWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition : PageEventWasTriggeredDuringPastOrCurrentInteractionCondition where T : RuleContext + { + public PageEventWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition() + : base(true) + { + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/VenueOfPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/VenueOfPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..5567d31 --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/VenueOfPastOrCurrentInteractionCondition.cs @@ -0,0 +1,99 @@ +using Sitecore.Analytics; +using Sitecore.Analytics.Tracking; +using Sitecore.Diagnostics; +using Sitecore.Rules; +using Sitecore.Support.Analytics.Rules.Conditions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class VenueOfPastOrCurrentInteractionCondition : HasEventOccurredCondition where T : RuleContext + { + private Guid? venueGuid; + + private bool venueGuidInitialized; + + public string VenueId { get; set; } + + private Guid? VenueGuid + { + get + { + if (this.venueGuidInitialized) + { + return this.venueGuid; + } + + try + { + this.venueGuid = new Guid(this.VenueId); + } + catch + { + Log.Warn(string.Format("Could not convert value to guid: {0}", this.VenueId), (object)base.GetType()); + } + + this.venueGuidInitialized = true; + return this.venueGuid; + } + } + + public VenueOfPastOrCurrentInteractionCondition() + : base(false) + { + } + + protected VenueOfPastOrCurrentInteractionCondition(bool filterByCustomData) + : base(filterByCustomData) + { + } + + protected override bool Execute(T ruleContext) + { + 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.VenueGuid.HasValue) + { + return false; + } + + if (this.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); + + return Enumerable.Any(this.FilterKeyBehaviorCacheEntries(keyBehaviorCache), (Func)delegate (KeyBehaviorCacheEntry entry) + { + Guid id = entry.Id; + Guid? b = this.VenueGuid; + return (Guid?)id == b; + }); + } + + protected override IEnumerable GetKeyBehaviorCacheEntries(KeyBehaviorCache keyBehaviorCache) + { + Assert.ArgumentNotNull((object)keyBehaviorCache, "keyBehaviorCache"); + return keyBehaviorCache.Venues; + } + + protected override bool HasEventOccurredInInteraction(IInteractionData interaction) + { + Assert.ArgumentNotNull((object)interaction, "interaction"); + if (interaction.VenueId.HasValue) + { + Guid value = interaction.VenueId.Value; + Guid? b = this.VenueGuid; + return (Guid?)value == b; + } + + return false; + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Analytics/Rules/Conditions/VenueWithCustomDataOfPastOrCurrentInteractionCondition.cs b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/VenueWithCustomDataOfPastOrCurrentInteractionCondition.cs new file mode 100644 index 0000000..9788ecf --- /dev/null +++ b/src/Sitecore.Support.129513/Analytics/Rules/Conditions/VenueWithCustomDataOfPastOrCurrentInteractionCondition.cs @@ -0,0 +1,12 @@ +using Sitecore.Rules; + +namespace Sitecore.Support.Analytics.Rules.Conditions +{ + public class VenueWithCustomDataOfPastOrCurrentInteractionCondition : VenueOfPastOrCurrentInteractionCondition where T : RuleContext + { + public VenueWithCustomDataOfPastOrCurrentInteractionCondition() + : base(true) + { + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/App_Config/Include/zzz/Sitecore.Support.129513.config b/src/Sitecore.Support.129513/App_Config/Include/zzz/Sitecore.Support.129513.config new file mode 100644 index 0000000..2a460b0 --- /dev/null +++ b/src/Sitecore.Support.129513/App_Config/Include/zzz/Sitecore.Support.129513.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Hooks/UpdateTypeFieldGoalItems.cs b/src/Sitecore.Support.129513/Hooks/UpdateTypeFieldGoalItems.cs new file mode 100644 index 0000000..3a22830 --- /dev/null +++ b/src/Sitecore.Support.129513/Hooks/UpdateTypeFieldGoalItems.cs @@ -0,0 +1,84 @@ +using Sitecore.Configuration; +using Sitecore.Data.Items; +using Sitecore.Diagnostics; +using Sitecore.Events.Hooks; +using Sitecore.SecurityModel; +using System; + +namespace Sitecore.Support.Hooks +{ + public class UpdateTypeFieldGoalItems : IHook + { + public void Initialize() + { + using (new SecurityDisabler()) + { + var databaseName = "master"; + var fieldName = "Type"; + var database = Factory.GetDatabase(databaseName, false); + if (database == null) + { + return; + } + + string[] itemPaths = new string[] + { + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Goal was triggered during a past or current interaction", + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Goal with custom data was triggered during a past or current interaction", + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Campaign was triggered during a past or current interaction", + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Campaign with custom data was triggered during a past or current interaction", + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Channel of a past or current interaction", + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Page event was triggered during a past or current interaction", + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Page event with custom data was triggered during a past or current interaction", + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Venue of a past or current interaction", + "/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Venue with custom data of a past or current interaction" + }; + + Type[] types = new Type[] + { + typeof(Analytics.Rules.Conditions.GoalWasTriggeredDuringPastOrCurrentInteractionCondition<>), + typeof(Analytics.Rules.Conditions.GoalWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition<>), + typeof(Analytics.Rules.Conditions.CampaignWasTriggeredDuringPastOrCurrentInteractionCondition<>), + typeof(Analytics.Rules.Conditions.CampaignWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition<>), + typeof(Analytics.Rules.Conditions.ChannelOfPastOrCurrentInteractionCondition<>), + typeof(Analytics.Rules.Conditions.PageEventWasTriggeredDuringPastOrCurrentInteractionCondition<>), + typeof(Analytics.Rules.Conditions.PageEventWithCustomDataWasTriggeredDuringPastOrCurrentInteractionCondition<>), + typeof(Analytics.Rules.Conditions.VenueOfPastOrCurrentInteractionCondition<>), + typeof(Analytics.Rules.Conditions.VenueWithCustomDataOfPastOrCurrentInteractionCondition<>), + }; + + string typeName = null; + string assemblyName = null; + string fieldValue = null; + Item item = null; + bool isAssemblyInstalled = false; + + for (int i = 0; i < itemPaths.Length; i++) + { + // removing '1 in the end of the generic type name + typeName = types[i].FullName.Remove(types[i].FullName.IndexOf('`')); + assemblyName = types[i].Assembly.GetName().Name; + fieldValue = $"{typeName}, {assemblyName}"; + item = database.GetItem(itemPaths[i]); + if (item != null) + { + if (string.Equals(item[fieldName], fieldValue, StringComparison.Ordinal)) + { + isAssemblyInstalled = true; + continue; + } + + item.Editing.BeginEdit(); + item[fieldName] = fieldValue; + item.Editing.EndEdit(); + } + } + + if (!isAssemblyInstalled) + { + Log.Info($"Installing {assemblyName}", this); + } + } + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Properties/AssemblyInfo.cs b/src/Sitecore.Support.129513/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cf0251a --- /dev/null +++ b/src/Sitecore.Support.129513/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Sitecore.Support.129513")] +[assembly: AssemblyProduct("Sitecore.Support.129513")] +[assembly: ComVisible(false)] diff --git a/src/Sitecore.Support.129513/Rules/Conditions/CondtionsUtility.cs b/src/Sitecore.Support.129513/Rules/Conditions/CondtionsUtility.cs new file mode 100644 index 0000000..5aa376a --- /dev/null +++ b/src/Sitecore.Support.129513/Rules/Conditions/CondtionsUtility.cs @@ -0,0 +1,118 @@ +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; + } + + switch (conditionOperatorId) + { + case "{066602E2-ED1D-44C2-A698-7ED27FD3A2CC}": + return ConditionOperator.Equal; + case "{814EF7D0-1639-44FD-AEEF-735B5AC14425}": + return ConditionOperator.GreaterThanOrEqual; + case "{B88CD556-082E-4385-BB76-E4D1B565F290}": + return ConditionOperator.GreaterThan; + case "{2E1FC840-5919-4C66-8182-A33A1039EDBF}": + return ConditionOperator.LessThanOrEqual; + case "{E362A3A4-E230-4A40-A7C4-FC42767E908F}": + return ConditionOperator.LessThan; + } + + return conditionOperatorId == "{3627ED99-F454-4B83-841A-A0194F0FB8B4}" + ? ConditionOperator.NotEqual + : ConditionOperator.Unknown; + } + + internal static Func GetInt32Comparer(string conditionOperatorId) + { + return GetInt32Comparer(GetConditionOperatorById(conditionOperatorId)); + } + + internal static Func GetInt32Comparer(ConditionOperator conditionOperator) + { + switch (conditionOperator) + { + case ConditionOperator.Equal: + return (first, second) => first == second; + case ConditionOperator.GreaterThanOrEqual: + return (first, second) => first >= second; + case ConditionOperator.GreaterThan: + return (first, second) => first > second; + case ConditionOperator.LessThanOrEqual: + return (first, second) => first <= second; + case ConditionOperator.LessThan: + return (first, second) => first < second; + case ConditionOperator.NotEqual: + return (first, second) => first != second; + default: + return null; + } + } + + public static StringConditionOperator GetStringConditionOperatorById(string conditionOperatorId) + { + 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(first, "first"); + Assert.ArgumentNotNull(second, "second"); + + switch (GetStringConditionOperatorById(conditionOperatorId)) + { + case StringConditionOperator.Equals: + return first == second; + case StringConditionOperator.CaseInsensitivelyEquals: + return string.Compare(first, second, StringComparison.CurrentCultureIgnoreCase) == 0; + case StringConditionOperator.NotEqual: + return first != second; + case StringConditionOperator.NotCaseInsensitivelyEquals: + return (uint)string.Compare(first, second, StringComparison.CurrentCultureIgnoreCase) > 0U; + case StringConditionOperator.Contains: + return first.IndexOf(second, StringComparison.CurrentCultureIgnoreCase) >= 0; + case StringConditionOperator.MatchesRegularExpression: + return Regex.IsMatch(first, second); + case StringConditionOperator.StartsWith: + return first.StartsWith(second, StringComparison.CurrentCultureIgnoreCase); + case StringConditionOperator.EndsWith: + return first.EndsWith(second, StringComparison.CurrentCultureIgnoreCase); + default: + return false; + } + } + } +} \ No newline at end of file diff --git a/src/Sitecore.Support.129513/Sitecore.Support.129513.csproj b/src/Sitecore.Support.129513/Sitecore.Support.129513.csproj new file mode 100644 index 0000000..26fcc4e --- /dev/null +++ b/src/Sitecore.Support.129513/Sitecore.Support.129513.csproj @@ -0,0 +1,122 @@ + + + + + Debug + AnyCPU + + + 2.0 + {82E3C87F-7DA4-4F8F-B779-A8F0EB751547} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Sitecore.Support + Sitecore.Support.129513 + v4.5 + true + + + + + + + 6 + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + none + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\SC.Sitecore.Analytics.8.1.2\lib\Sitecore.Analytics.dll + False + + + ..\packages\SC.Sitecore.Analytics.Core.8.1.2\lib\Sitecore.Analytics.Core.dll + False + + + ..\packages\SC.Sitecore.Analytics.Model.8.1.2\lib\Sitecore.Analytics.Model.dll + False + + + ..\packages\SC.Sitecore.Analytics.Outcome.8.1.2\lib\Sitecore.Analytics.Outcome.dll + False + + + ..\packages\SC.Sitecore.Kernel.8.1.2\lib\Sitecore.Kernel.dll + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 0 + / + http://localhost:49293/ + False + False + + + False + + + + + \ No newline at end of file diff --git a/src/Sitecore.Support.129513/packages.config b/src/Sitecore.Support.129513/packages.config new file mode 100644 index 0000000..9ee5daf --- /dev/null +++ b/src/Sitecore.Support.129513/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Sitecore.Support.129513/web.config b/src/Sitecore.Support.129513/web.config new file mode 100644 index 0000000..7e1d425 --- /dev/null +++ b/src/Sitecore.Support.129513/web.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file