Brian McKeiver's Blog

My Kentico EMS API Deep Dive Presentation


Introduction

A few people asked me to provide my presentation from the Kentico User Group webinar that I presented at this past week. I have attached the presentation to this blog post.  I think it went really well considering the amount of people that attended and the feedback that I received from it.

Remember there is a great tip in there for how to use the new Kentico 8.2 MacroRuleInstanceTranslator class to optimize your contact group rebuild time and lead scoring calculation time for when you have a large volume of contacts in your Kentico instance.

The deck is embedded and can be downloaded from this post after the jump. 

 

 

Kentico 8.2 EMS API Deep Dive 

Kentico 8 EMS API Deep Dive from Mcbeev

 

MacroRuleInstanceTranslator Source Code

 

using System;
using CMS.DataEngine;
using CMS.Membership;
using CMS.OnlineMarketing;

internal class ContactIsDetroitLionsFanInstanceTranslator : IMacroRuleInstanceTranslator
{
    /// 
/// Translates ContactIsDetroitsLionFanMacro rule. ///

 

public ObjectQuery Translate(MacroRuleInstance macroRuleInstance) { if (macroRuleInstance == null) { throw new ArgumentNullException("macroRuleInstance"); } if (macroRuleInstance.MacroRuleName != "ContactIsDetroitLionsFan") { throw new ArgumentException("[ContactIsDetroitLionsFanTranslator.Translate]: Only macro rule instances of type ContactIsDetroitLionsFan can be translated"); } var ruleParameters = macroRuleInstance.Parameters; // ruleParameters contains the data user enters in macro fields string paramIs = ruleParameters["_is"].Value; QueryOperator queryOperator = paramIs == "!" ? QueryOperator.NotEquals : QueryOperator.Equals; return ContactInfoProvider.GetContacts().Where("ContactIsDetroitLionsFan", queryOperator, true); } }

 

 

 

 

 

MacroRuleMetadataLoader Source Code

 

 

 

 

 

 

 

using System;
using System.Collections.Generic;
using CMS.Base;
using CMS.DocumentEngine;
using CMS.OnlineMarketing;

[CustomMacroRuleMetadataLoader]
public partial class CMSModuleLoader
{
    /// 

 

/// Attribute class that ensures the loading of custom macro rule translator. ///

 

private class CustomMacroRuleMetadataLoaderAttribute : CMSLoaderAttribute { ///

 

/// The system executes the Init method of the CMSModuleLoader attributes when the application starts. ///

 

public override void Init() { MacroRuleMetadata metadata = new MacroRuleMetadata( "ContactIsDetroitLionsFan", new ContactIsDetroitLionsFanInstanceTranslator(), affectingActivities: new List(0), affectingAttributes: new List { // Recalculate when specific attributes change "contactisdetroitlionsfan", "contactisgreenbaypackersfan" }); MacroRuleMetadataContainer.RegisterMetadata(metadata); } } }