为什么没有触发集成总线连接器?

问题描述 投票:0回答:1

我正在使用Kentico MVC v12和全新的DancingGoat(MVC)模板。

我的解决方案中有2个项目:

  • CMSApp:后台网站
  • DancingGoat:电子商务网站

enter image description here

我的连接器是一个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ženJanjiček提出的使用“IntegrationHelper.ProcessExternalTask​​”的解决方案,但它不起作用(更多信息在这里:https://docs.kentico.com/k12/integrating-3rd-party-systems/using-the-integration-bus/creating-integration-connectors/implementing-incoming-synchronization

kentico
1个回答
1
投票

您正在使用单独的库并将其引用到MVC站点和管理。您正在使用两个应用程序,现在,代码只通过CmsUserIntegrationConnector Init()事件注册到其中一个。使用自定义库,两个应用程序都可以加载程序集并初始化连接器,因为程序集是通过AssemblyDiscoverable属性按引用加载的。

© www.soinside.com 2019 - 2024. All rights reserved.