为什么未触发集成总线连接器?
Why integration bus connector is not fired?
我正在使用 Kentico MVC v12 和全新安装的 DancingGoat(MVC) 模板。
我的解决方案中有 2 个项目:
- CMSApp:后台网站
- DancingGoat:电子商务网站
我的连接器是 C# class,它位于 CMSApp 项目的文件夹中。
我的连接器的目标是在每次创建用户时注册以执行自定义逻辑。
这是我的 C# 连接器代码:
public class CmsUserIntegrationConnector : 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 = nameof(CmsUserIntegrationConnector);
SubscribeToObjects(
TaskProcessTypeEnum.AsyncSimple,
PredefinedObjectType.USER,
TaskTypeEnum.CreateObject);
}
public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
{
try
{
if (infoObj.TypeInfo.ObjectType == PredefinedObjectType.USER.ToString())
{
if (taskType == TaskTypeEnum.CreateObject)
{
EventLogProvider.LogInformation(
nameof(CmsUserIntegrationConnector),
nameof(ProcessInternalTaskAsync),
"User created on SAP !!!!!");
UserInfo user = infoObj.MainObject as UserInfo;
// Consume SAP webservice and provider user info
// Save SAPId received from webservice in user custom field
using (CMSActionContext context = new CMSActionContext())
{
context.LogWebFarmTasks = false;
context.LogEvents = false;
context.LogExport = false;
context.LogIntegration = false;
context.LogSynchronization = false;
// code that creates/saves the object goes here
user.SetValue("SAPID", Guid.NewGuid()); // (new Random()).Next(0, 100)
UserInfoProvider.SetUserInfo(user);
}
}
}
}
catch (Exception ex)
{
EventLogProvider.LogException(
nameof(CmsUserIntegrationConnector),
nameof(ProcessInternalTaskAsync),
ex);
errorMessage = ex.Message;
return IntegrationProcessResultEnum.Error;
}
errorMessage = null;
return IntegrationProcessResultEnum.OK;
}
}
现在发生了什么:
- 如果我在后台的用户模块中创建一个用户,我的连接器就会被触发
- 如果我通过电子商务网站创建用户,没有任何反应..
我是否应该创建一个库项目,将 C# 连接器 class 放入其中,并将其添加为两个网站的参考,也许在配置中做更多的事情?
我是不是做错了什么?
提前致谢!
更新:
我测试了 Dražen Janjiček 提出的使用 "IntegrationHelper.ProcessExternalTask" 的解决方案,但它没有用(更多信息在这里:https://docs.kentico.com/k12/integrating-3rd-party-systems/using-the-integration-bus/creating-integration-connectors/implementing-incoming-synchronization)
您在正确的轨道上使用单独的库并将其引用到 MVC 站点和管理。您正在使用两个应用程序,现在,代码仅通过 CmsUserIntegrationConnector Init() 事件注册到其中一个应用程序。使用自定义库,两个应用程序都将能够加载程序集并初始化连接器,因为程序集是通过 AssemblyDiscoverable 属性按引用加载的。
我正在使用 Kentico MVC v12 和全新安装的 DancingGoat(MVC) 模板。
我的解决方案中有 2 个项目:
- CMSApp:后台网站
- DancingGoat:电子商务网站
我的连接器是 C# class,它位于 CMSApp 项目的文件夹中。
我的连接器的目标是在每次创建用户时注册以执行自定义逻辑。
这是我的 C# 连接器代码:
public class CmsUserIntegrationConnector : 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 = nameof(CmsUserIntegrationConnector);
SubscribeToObjects(
TaskProcessTypeEnum.AsyncSimple,
PredefinedObjectType.USER,
TaskTypeEnum.CreateObject);
}
public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
{
try
{
if (infoObj.TypeInfo.ObjectType == PredefinedObjectType.USER.ToString())
{
if (taskType == TaskTypeEnum.CreateObject)
{
EventLogProvider.LogInformation(
nameof(CmsUserIntegrationConnector),
nameof(ProcessInternalTaskAsync),
"User created on SAP !!!!!");
UserInfo user = infoObj.MainObject as UserInfo;
// Consume SAP webservice and provider user info
// Save SAPId received from webservice in user custom field
using (CMSActionContext context = new CMSActionContext())
{
context.LogWebFarmTasks = false;
context.LogEvents = false;
context.LogExport = false;
context.LogIntegration = false;
context.LogSynchronization = false;
// code that creates/saves the object goes here
user.SetValue("SAPID", Guid.NewGuid()); // (new Random()).Next(0, 100)
UserInfoProvider.SetUserInfo(user);
}
}
}
}
catch (Exception ex)
{
EventLogProvider.LogException(
nameof(CmsUserIntegrationConnector),
nameof(ProcessInternalTaskAsync),
ex);
errorMessage = ex.Message;
return IntegrationProcessResultEnum.Error;
}
errorMessage = null;
return IntegrationProcessResultEnum.OK;
}
}
现在发生了什么:
- 如果我在后台的用户模块中创建一个用户,我的连接器就会被触发
- 如果我通过电子商务网站创建用户,没有任何反应..
我是否应该创建一个库项目,将 C# 连接器 class 放入其中,并将其添加为两个网站的参考,也许在配置中做更多的事情?
我是不是做错了什么?
提前致谢!
更新:
我测试了 Dražen Janjiček 提出的使用 "IntegrationHelper.ProcessExternalTask" 的解决方案,但它没有用(更多信息在这里:https://docs.kentico.com/k12/integrating-3rd-party-systems/using-the-integration-bus/creating-integration-connectors/implementing-incoming-synchronization)
您在正确的轨道上使用单独的库并将其引用到 MVC 站点和管理。您正在使用两个应用程序,现在,代码仅通过 CmsUserIntegrationConnector Init() 事件注册到其中一个应用程序。使用自定义库,两个应用程序都将能够加载程序集并初始化连接器,因为程序集是通过 AssemblyDiscoverable 属性按引用加载的。