为什么集成总线在 CreateObject 事件上执行 3 次,为什么在 Kentico 的传出同步期间站点名称为空?
Why integration bus executes 3 times on CreateObject event and why sitename is null during outgoing synchronisation in Kentico?
我已经安装了全新版本的 Kentico v12,我正在使用基本的山羊模板。
我希望能够使用 SAP 网络服务在前端应用程序中同步创建用户和更新这些用户的个人信息。
我在用户对象中添加了一个新的自定义字段 "SAPID" 并创建了一个连接器来管理与 SAP 网络服务的同步。
这是我的 POC 代码:
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;
}
}
这是我在调试 createobject 事件时获得的参数值的转储:
我有 2 个问题。
- 为什么参数sitename为空?
- 为什么在每个 CreateObject 事件上连续执行 3 次?
我检查过这个post:
在站点的域别名中添加 "localhost" 无效。
提前致谢!
通过 Enn 的评论,我了解到我的问题来自于这条指令 "UserInfoProvider.SetUserInfo(user);"
我订阅了对任何新用户对象应用逻辑并在逻辑中再次更新它,这就是我多次执行它的原因。
为了解决这个问题,我应用了 Michal 的命题
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);
}
谢谢!
我已经安装了全新版本的 Kentico v12,我正在使用基本的山羊模板。
我希望能够使用 SAP 网络服务在前端应用程序中同步创建用户和更新这些用户的个人信息。
我在用户对象中添加了一个新的自定义字段 "SAPID" 并创建了一个连接器来管理与 SAP 网络服务的同步。
这是我的 POC 代码:
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;
}
}
这是我在调试 createobject 事件时获得的参数值的转储:
我有 2 个问题。
- 为什么参数sitename为空?
- 为什么在每个 CreateObject 事件上连续执行 3 次?
我检查过这个post:
在站点的域别名中添加 "localhost" 无效。
提前致谢!
通过 Enn 的评论,我了解到我的问题来自于这条指令 "UserInfoProvider.SetUserInfo(user);" 我订阅了对任何新用户对象应用逻辑并在逻辑中再次更新它,这就是我多次执行它的原因。
为了解决这个问题,我应用了 Michal 的命题
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);
}
谢谢!