Пример #1
0
 /// <summary>
 /// proces to execute
 /// </summary>
 /// <param name="args">actionContext</param>
 public override void Process(DetermineChannelProcessorArgs args)
 {
     if (this.IsRobbieTraffic())
     {
         args.ChannelId = new ID(this.channelId);
     }
 }
Пример #2
0
        /// <summary>
        /// Executes the process event.
        /// </summary>
        /// <param name="args">The arguments.</param>
        protected void DoProcess(DetermineChannelProcessorArgs args)
        {
            try
            {
                if (args.Interaction != null && !string.IsNullOrEmpty(args.Interaction.Referrer))
                {
                    InteractionChannelMappingsConfiguration interactionChannelMappingsConfiguration = _configurationFactory.Get <InteractionChannelMappingsConfiguration>();

                    if (interactionChannelMappingsConfiguration.IsEmpty)
                    {
                        _log.Warn("No InteractionChannelMappingsConfiguration found. Interaction-socialchannel-mapping only works properly if there is a <interactionChannelMappings> node present in the configuration.", this);
                    }

                    Uri             interactionUrlReferrer = new Uri(args.Interaction.Referrer);
                    ChannelSettings channelSettings2       = (from channelSettings in interactionChannelMappingsConfiguration.Channels
                                                              where !string.IsNullOrEmpty(channelSettings.ChannelId)
                                                              select channelSettings).FirstOrDefault((ChannelSettings channelSettings) => channelSettings.ChannelMappings.Any((ChannelMappingSettings channelMappingSettings) => string.Compare(channelMappingSettings.UrlReferrerHost, interactionUrlReferrer.Host, StringComparison.InvariantCultureIgnoreCase) == 0));
                    if (channelSettings2 != null)
                    {
                        args.ChannelId = ID.Parse(channelSettings2.ChannelId);
                        _log.Debug($"Interaction has been mapped to channel '{args.ChannelId}' for referrer '{args.Interaction.Referrer}'");
                    }
                }
            }
            catch (Exception exception)
            {
                _log.Error("Couldn't determine the social channels for the interaction.", exception, this);
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes the Channelizer settings.
        /// </summary>
        /// <returns></returns>
        private bool Initialize(DetermineChannelProcessorArgs args)
        {
            Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Initializing module", this);

            var rootItem = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.RootPath);

            if (String.IsNullOrEmpty(rootItem[Templates.HasChannelizer.Fields.Channelizer]))
            {
                Sitecore.Diagnostics.Log.Warn($"Channelizer configuration item not selected.", this);
                return(false);
            }
            this.channelizerSettingsItem = new Sitecore.Data.Fields.ReferenceField(rootItem.Fields[Templates.HasChannelizer.Fields.Channelizer]).TargetItem;
            if (channelizerSettingsItem == null)
            {
                return(false);
            }
            if (!channelizerSettingsItem.DescendsFrom(Templates.ChannelizerSettings.TemplateId))
            {
                Sitecore.Diagnostics.Log.Warn($"The selected item ({channelizerSettingsItem.Paths.FullPath}) is not deriving Channelizer settings template.", this);
                return(false);
            }
            String channelsSelectedToSkipProcessing = channelizerSettingsItem[Templates.ChannelizerSettings.Fields.DoNotProcessIfChannelsAlreadyAssigned];

            if (!String.IsNullOrEmpty(channelsSelectedToSkipProcessing) && channelsSelectedToSkipProcessing.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Contains(args.ChannelId.ToString()))
            {
                Sitecore.Diagnostics.Log.Warn($"The assinged channel ({args.ChannelId}) from previous processor(s) is setup to terminate the process.", this);
                return(false);
            }
            if (!Sitecore.MainUtil.GetBool(channelizerSettingsItem[Templates.ChannelizerSettings.Fields.Active], false))
            {
                Sitecore.Diagnostics.Log.Warn($"Channelizer is diabled. ({this.channelizerSettingsItem.Paths.FullPath})", this);
                return(false);
            }
            if (!this.channelizerSettingsItem.Children.Any(c => c.DescendsFrom(Templates.ChannelizerSettingItem.TemplateId)))
            {
                Sitecore.Diagnostics.Log.Warn($"Channelizer child setting items not found. ({this.channelizerSettingsItem.Paths.FullPath})", this);
                return(false);
            }
            return(true);
        }
        public override void Process(DetermineChannelProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            // Define context

            var ruleContext = new ChannelRulesContext()
            {
                ChannelId = null,
                Item = Sitecore.Context.Item
            };

            Item ChannelRulesRoot;

            // Set root
            using (new SecurityDisabler())
            {
                var db = Sitecore.Context.ContentDatabase??Sitecore.Context.Database;

                ChannelRulesRoot = db?.GetItem(RootId);

                if (ChannelRulesRoot == null)
                    return; // no root, exit
            }

            RuleList<ChannelRulesContext> rules = RuleFactory.GetRules<ChannelRulesContext>(ChannelRulesRoot, "Rule");//"Rule" is the field name

            if (rules != null)
            { // Run rules
                rules.Run(ruleContext);
            }

            if (ruleContext.ChannelId != (ID)null)
            {
                args.ChannelId = ruleContext.ChannelId;

                args.AbortPipeline();
              }
        }
Пример #5
0
        public override void Process(DetermineChannelProcessorArgs args)
        {
            if (!Initialize(args))
            {
                return;
            }

            bool channelSet = false;

            /**
             * Process all settings item for diffenet domain and query parameters.
             * If the match found and the channel id has been set, then exit and stop processing other items
             */
            foreach (var settingItem in this.channelizerSettingsItem.Children.Where(c => c.DescendsFrom(Templates.ChannelizerSettingItem.TemplateId)))
            {
                if (String.IsNullOrEmpty(settingItem[Templates.ChannelizerSettingItem.Fields.Channel]))
                {
                    Sitecore.Diagnostics.Log.Warn($"Channel item is not selected. ({settingItem.Paths.FullPath})", this);
                    continue;
                }
                var priority = settingItem[Templates.ChannelizerSettingItem.Fields.Priority];
                if (String.IsNullOrEmpty(priority))
                {
                    Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Priority not selected, setting 'both' as the priority.", this);
                    priority = "both";
                }
                priority = priority.ToLowerInvariant();
                var referringDomain = settingItem[Templates.ChannelizerSettingItem.Fields.Domains];
                var channelItem     = new Sitecore.Data.Fields.ReferenceField(settingItem.Fields[Templates.ChannelizerSettingItem.Fields.Channel]).TargetItem;
                var queryParameters = settingItem[Templates.ChannelizerSettingItem.Fields.QueryParameters];
                var onlyCheckQueryParametersPresence    = Sitecore.MainUtil.GetBool(settingItem[Templates.ChannelizerSettingItem.Fields.OnlyCheckQueryParametersPresence], false);
                NameValueCollection queryParametersList = new NameValueCollection();
                if (!String.IsNullOrEmpty(queryParameters))
                {
                    queryParametersList = Sitecore.Web.WebUtil.ParseUrlParameters(queryParameters.ToLowerInvariant());
                }
                if (priority.Equals(Constants.CHANNELIZER_PRIORITY_BOTH))
                {
                    Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - priority - both", this);
                    if (MatchesReferrerDomain(referringDomain.ToLowerInvariant()) && MatchesQueryParameters(queryParametersList, onlyCheckQueryParametersPresence))
                    {
                        args.ChannelId = channelItem.ID;
                        Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Assigned channel - {channelItem.Name}({channelItem.ID})", this);
                        channelSet = true;
                        break;
                    }
                }
                else if (priority.Equals(Constants.CHANNELIZER_PRIORITY_DOMAIN) && !String.IsNullOrEmpty(referringDomain))
                {
                    Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - priority - referring domain", this);
                    if (MatchesReferrerDomain(referringDomain.ToLowerInvariant()))
                    {
                        args.ChannelId = channelItem.ID;
                        Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Assigned channel - {channelItem.Name}({channelItem.ID})", this);
                        channelSet = true;
                        break;
                    }
                }
                else if (priority.Equals(Constants.CHANNELIZER_PRIORITY_QUERYSTRING))
                {
                    Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - priority - query parameters", this);
                    if (MatchesQueryParameters(queryParametersList, onlyCheckQueryParametersPresence))
                    {
                        args.ChannelId = channelItem.ID;
                        Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - Assigned channel - {channelItem.Name}({channelItem.ID})", this);
                        channelSet = true;
                        break;
                    }
                }
            }

            if (!channelSet && HttpContext.Current.Request.UrlReferrer != null)
            {
                Sitecore.Diagnostics.Log.Debug($"{typeof(SetChannel).FullName} - channel not set by custom rules, and request has url referrer so setting the common referral channel from settings.", this);
                //Set the other referrals channel
                string channelId = this.channelizerSettingsItem[Templates.ChannelizerSettings.Fields.OtherReferralsChannel];
                if (!String.IsNullOrEmpty(channelId))
                {
                    var channleItem = Sitecore.Context.Database.GetItem(channelId);
                    if (channleItem != null && channleItem.DescendsFrom(Templates.ChannelTemplateId))
                    {
                        args.ChannelId = channleItem.ID;
                    }
                }
            }
        }
Пример #6
0
 /// <summary>
 /// Runs the processor.
 /// </summary>
 /// <param name="args">The arguments.</param>
 public override void Process(DetermineChannelProcessorArgs args)
 {
     DoProcess(args);
 }