API Questions on Kentico API.
Version 6.x > API > DataChanged with Exclude Columns Not Working within Integration Bus View modes: 
User avatar
Member
Member
JA - 8/12/2013 6:39:58 PM
   
DataChanged with Exclude Columns Not Working within Integration Bus
I've got the below connector subscribing to user object changes. I want to capture events like when the user changes their profile details (ie Name, Email, Address details which are custom user settings fields etc) but want to be able to ignore when a user logs in. I've tried to do this by using the DataChanged method on the user object the connector receives. I pass in the columns I want exclude from the check but it still comes back true when the user logs in and hasn't changed any of their details.

Any ideas on if this is possible or even another way of detecting only a login has occurred?
using CMS.EventLog;
using CMS.SettingsProvider;
using CMS.SiteProvider;
using CMS.Synchronization;
using CMS.SynchronizationEngine;
using System;


namespace Test.Services
{

/// <summary>
/// Responsible for pushing User/Contact changes made in Kentico out to the Global Contacts Web API.
///
/// Ensure Integration Bus is enabled Kentico wide, load Site Manager for site > Settings Tab > Integration in Tree Menu > Integration Bus in Tree Menu, tick "Enable system integration bus"
///
/// This class then needs registered in Kentico (for Kentico 6), load Site Manager for site > Administration Tab > Integration Bus in Tree Menu > Connectors Tab.
/// Display Name: Pioneers Global Contacts Connector
/// Code Name: GCOutboundConnector
/// Assembly Name: Test
/// Class Name: Test.Services.GCOutboundConnector
/// Enabled: Ticked
/// </summary>
public class GCOutboundConnector : BaseIntegrationConnector
{
public override void Init()
{
ConnectorName = GetType().Name;

SubscribeToObjects(TaskProcessTypeEnum.AsyncSnapshot, PredefinedObjectType.USER, TaskTypeEnum.CreateObject);
SubscribeToObjects(TaskProcessTypeEnum.AsyncSnapshot, PredefinedObjectType.USER, TaskTypeEnum.UpdateObject);
}


/// <summary>
/// Processes given User Creates and Updates (as defined in Init).
/// Update Global Contacts with the changes.
/// Unfortunately this is going to trigger for a lot of stuff that's irrelevant (ie last login/activity date updated)
/// but not sure how to prevent that at this stage.
/// </summary>
/// <param name="infoObj">Info object to process</param>
/// <param name="translations">Translation helper object containing translations for given object</param>
/// <param name="taskType">Type of task</param>
/// <param name="dataType">Type of data</param>
/// <param name="siteName">Name of site</param>
/// <param name="errorMessage">Possible error message</param>
/// <returns>Result of processing</returns>
public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
{
try
{
// If object is of 'user' type
// You can also use following condition: (((BaseInfo)infoObj) is CMS.SiteProvider.UserInfo)
if (infoObj.ObjectType == PredefinedObjectType.USER
&& (taskType == TaskTypeEnum.CreateObject || taskType == TaskTypeEnum.UpdateObject))
{
var user = ((BaseInfo)infoObj) as CMS.SiteProvider.UserInfo;
bool changed = user.DataChanged("LastLogin;UserLastModified;UserPassword;UserLastLogonInfo;");
//Get user settings from the database to ensure latest details
var userSettings = UserSettingsInfoProvider.GetUserSettingsInfoByUser(user.UserID);

EventLogProvider eventLog = new EventLogProvider();
eventLog.LogEvent("I", DateTime.Now, ConnectorName, taskType.ToString(), "",
"Global Contacts Connector Triggered for UserID: " + user.UserID + " Changed: " + changed);

}
errorMessage = null;
return IntegrationProcessResultEnum.OK;
}
catch (Exception ex)
{
errorMessage = ex.Message;
EventLogProvider eventLog = new EventLogProvider();
eventLog.LogEvent(EventLogProvider.EVENT_TYPE_ERROR, DateTime.Now, ConnectorName, taskType.ToString(), 0, null, 0, null, null, errorMessage, 0, null);
return IntegrationProcessResultEnum.Error;
}
finally
{
// Clear translations cached during TranslateColumnsToExternal which internally calls GetExternalObjectID, GetExternalDocumentID
// This call is optional but recommended in the case where eg. collision of code names can occur
ClearInternalTranslations();
}
}


}
}

User avatar
Member
Member
JA - 8/12/2013 7:29:04 PM
   
RE:DataChanged with Exclude Columns Not Working within Integration Bus
I did notice I had LastLogin as one of the excluded columns which wasn't correct but that doesn't seem to make a difference. Changed to LastLogon and the boolean flag is still true within the connector when all the user has done is logged in. Corrected code below:

 bool changed = user.DataChanged("LastLogon;UserLastModified;UserPassword;UserLastLogonInfo;");

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 9/1/2013 1:35:02 PM
   
RE:DataChanged with Exclude Columns Not Working within Integration Bus
Hi,

Which exact version are you using (incl. hotfix/build number)?
Have you had a chance to test this also in some 7.0 website instance?

Thank you in advance for information.

Regards,
Zdenek