Я использую Kentico MVC v12 с новой установкой шаблона DancingGoat (MVC).
В моем решении 2 проекта:
- CMSApp: веб-сайт backoffice
- DancingGoat: веб-сайт электронной коммерции
Мой коннектор - это класс C #, который помещается в папку в проекте 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 # и добавить его в качестве ссылки на обоих веб-сайтах, и, возможно, сделать что-то большее в конфигурации?
Я что-то не так делаю?
Заранее спасибо!
Обновление:
Я протестировал решение, предложенное 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)