Sap 为什么集成总线在CreateObject事件上执行3次,为什么在Kentico中传出同步期间sitename为null?
我已经安装了新版本的Kentico v12,并且使用了基本的goat模板 我希望能够使用SAP webservice在前端应用程序中同步创建用户和更新这些用户的个人信息 我在用户对象“SAPID”中添加了一个新的自定义字段,并创建了一个连接器来管理与sapwebservices的同步 这是我的poc代码:Sap 为什么集成总线在CreateObject事件上执行3次,为什么在Kentico中传出同步期间sitename为null?,sap,kentico,Sap,Kentico,我已经安装了新版本的Kentico v12,并且使用了基本的goat模板 我希望能够使用SAP webservice在前端应用程序中同步创建用户和更新这些用户的个人信息 我在用户对象“SAPID”中添加了一个新的自定义字段,并创建了一个连接器来管理与sapwebservices的同步 这是我的poc代码: public class CMSIntegrationConnector : BaseIntegrationConnector { /// <summary> //
public class CMSIntegrationConnector : BaseIntegrationConnector
{
/// <summary>
/// Initializes the connector name.
/// </summary>
public override void Init()
{
// Initializes the connector name (must match the code name of the connector object in the system)
// GetType().Name uses the name of the class as the ConnectorName
ConnectorName = GetType().Name;
SubscribeToObjects(TaskProcessTypeEnum.AsyncSimple, PredefinedObjectType.USER);
}
public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
{
try
{
if (siteName == "DancingGoat")
{
if (infoObj.TypeInfo.ObjectType == PredefinedObjectType.USER.ToString())
{
if (taskType == TaskTypeEnum.CreateObject)
{
EventLogProvider.LogInformation("Connector", "CreateUser", "User created on SAP !!!!!");
UserInfo user = infoObj.MainObject as UserInfo;
// Call SAP webservice
user.SetValue("SAPID", Guid.NewGuid());
UserInfoProvider.SetUserInfo(user);
}
else if (taskType == TaskTypeEnum.UpdateObject)
{
EventLogProvider.LogInformation("Connector", "CreateUser", "User updated on SAP !!!!!");
// Call SAP webservice
}
}
}
}
catch (Exception ex)
{
EventLogProvider.LogException("Connector", "CreateUser", ex);
errorMessage = ex.Message;
return IntegrationProcessResultEnum.Error;
}
errorMessage = null;
return IntegrationProcessResultEnum.OK;
}
}
公共类CMSIntegrationConnector:BaseIntegrationConnector
{
///
///初始化连接器名称。
///
公共重写void Init()
{
//初始化连接器名称(必须与系统中连接器对象的代码名匹配)
//GetType().Name使用类的名称作为ConnectorName
ConnectorName=GetType().Name;
SubscribeToObjects(TaskProcessTypeEnum.AsyncSimple,预定义的ObjectType.USER);
}
公共覆盖集成ProcessResultenum ProcessInternalTaskAsync(GeneralizedInfo infoObj、TranslationHelper translations、TaskTypeEnum taskType、TaskDataTypeEnum dataType、string siteName、out string errorMessage)
{
尝试
{
如果(siteName==“DancingGoat”)
{
if(infoObj.TypeInfo.ObjectType==预定义的ObjectType.USER.ToString())
{
if(taskType==TaskTypeEnum.CreateObject)
{
登录信息(“连接器”、“创建用户”、“在SAP上创建的用户”!!!!!”;
UserInfo user=infoObj.MainObject作为UserInfo;
//调用SAP Web服务
user.SetValue(“SAPID”,Guid.NewGuid());
UserInfoProvider.SetUserInfo(用户);
}
else if(taskType==TaskTypeEnum.UpdateObject)
{
登录信息(“连接器”、“CreateUser”、“SAP上更新的用户”!!!!!”;
//调用SAP Web服务
}
}
}
}
捕获(例外情况除外)
{
LogException(“连接器”,“创建用户”,ex);
errorMessage=ex.Message;
返回IntegrationProcessResultEnum.Error;
}
errorMessage=null;
返回IntegrationProcessResultEnum.OK;
}
}
以下是调试createobject事件时获得的参数值的转储:
我有两个问题
- 为什么参数sitename为null
- 为什么在每个CreateObject事件上连续执行3次
提前谢谢你 通过Enn的评论,我了解到我的问题来自此说明“UserInfoProvider.SetUserInfo(user);” 我订阅了在任何新的用户对象上应用一个逻辑,并在逻辑中再次更新它,这就是为什么我多次执行它的原因 为了解决这个问题,我应用了迈克尔的命题
using (CMSActionContext context = new CMSActionContext())
{
context.LogWebFarmTasks = false;
context.LogEvents = false;
context.LogExport = false;
context.LogIntegration = false;
context.LogSynchronization = false;
UserInfo user = infoObj.MainObject as UserInfo;
user.SetValue("SAPID", Guid.NewGuid());
UserInfoProvider.SetUserInfo(user);
}
谢谢大家! 通过Enn的评论,我了解到我的问题来自此说明“UserInfoProvider.SetUserInfo(user);” 我订阅了在任何新的用户对象上应用一个逻辑,并在逻辑中再次更新它,这就是为什么我多次执行它的原因 为了解决这个问题,我应用了迈克尔的命题
using (CMSActionContext context = new CMSActionContext())
{
context.LogWebFarmTasks = false;
context.LogEvents = false;
context.LogExport = false;
context.LogIntegration = false;
context.LogSynchronization = false;
UserInfo user = infoObj.MainObject as UserInfo;
user.SetValue("SAPID", Guid.NewGuid());
UserInfoProvider.SetUserInfo(user);
}
谢谢大家! 我认为sitename不可用,因为它的“异步”同步,因此站点的上下文丢失。如果您尝试使用“同步”,您应该会看到sitename以及其他上下文属性。你说它执行了3次,但是你检查过它是什么类型的对象了吗?是同一个物体吗?可能是相关对象与主对象一起创建。感谢您的快速回答!我想我找到了原因,它来自于说明“UserInfoProvider.SetUserInfo(user);”。。。。您知道有没有一种方法可以明确地说“不要为下一条指令发出事件”?当一个新客户创建一个帐户时,我想用它的SAP标识符更新用户信息:xIs it you,谁直接使用此API,还是来自KenticoAPI的调用?无论哪种方式,CMSActionContext类都可以用作包装器,您可以使用它并将LogTasks属性(或类似名称)设置为false,以抑制任务创建。对于Kentico API,这可以通过自定义提供程序进行调整,但我仍有兴趣查看调用来自何处。我使用的是IntegrationBus,Kentico在“cms.user”对象上的每个事件上执行我的连接器,感谢您提供关于“CMSActionContext”的线索,我将对此进行调查!我认为sitename不可用,因为它的“异步”同步,因此站点的上下文丢失。如果您尝试使用“同步”,您应该会看到sitename以及其他上下文属性。你说它执行了3次,但是你检查过它是什么类型的对象了吗?是同一个物体吗?可能是相关对象与主对象一起创建。感谢您的快速回答!我想我找到了原因,它来自于说明“UserInfoProvider.SetUserInfo(user);”。。。。您知道有没有一种方法可以明确地说“不要为下一条指令发出事件”?当一个新客户创建一个帐户时,我想用它的SAP标识符更新用户信息:xIs it you,谁直接使用此API,还是来自KenticoAPI的调用?无论哪种方式,CMSActionContext类都可以用作包装器,您可以使用它并将LogTasks属性(或类似名称)设置为false,以抑制任务创建。对于Kentico API,这可以通过自定义的提供程序进行调整,但我仍然有兴趣查看调用来自何处。我使用的是IntegrationBus,我的连接器由Kentico在“c”上的每个事件上执行