Exemplo n.º 1
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);
        }