Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kentico 为什么集成总线连接器未触发?_Kentico - Fatal编程技术网

Kentico 为什么集成总线连接器未触发?

Kentico 为什么集成总线连接器未触发?,kentico,Kentico,我正在使用Kentico MVC v12,并安装了新的DancingGoat(MVC)模板 我的解决方案中有两个项目: CMSApp:后台网站 DancingGoat:电子商务网站 我的连接器是一个C#类,放在CMSApp项目的文件夹中 我的连接器的目标是在每次创建用户时注册以执行自定义逻辑 这是我的C#连接器代码: public class CmsUserIntegrationConnector : BaseIntegrationConnector { /// <summa

我正在使用Kentico MVC v12,并安装了新的DancingGoat(MVC)模板

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

  • CMSApp:后台网站
  • 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;
    }
}
公共类CmsUserIntegrationConnector:BaseIntegrationConnector { /// ///初始化连接器名称。 /// 公共重写void Init() { //初始化连接器名称(必须与系统中连接器对象的代码名匹配) //GetType().Name使用类的名称作为ConnectorName ConnectorName=名称(CmsUserIntegrationConnector); 下标对象( TaskProcessTypeEnum.AsyncSimple, 预定义的ObjectType.USER, TaskTypeEnum.CreateObject); } 公共覆盖集成ProcessResultenum ProcessInternalTaskAsync(GeneralizedInfo infoObj、TranslationHelper translations、TaskTypeEnum taskType、TaskDataTypeEnum dataType、string siteName、out string errorMessage) { 尝试 { if(infoObj.TypeInfo.ObjectType==预定义的ObjectType.USER.ToString()) { if(taskType==TaskTypeEnum.CreateObject) { EventLogProvider.LogInformation( 名称(CMSUSERINTEGORIONCONNECTOR), 名称(ProcessInternalTaskAsync), “用户在SAP上创建!!!”; UserInfo user=infoObj.MainObject作为UserInfo; //使用SAP Web服务和提供商用户信息 //在用户自定义字段中保存从webservice接收的SAPId 使用(CMSActionContext=new CMSActionContext()) { context.LogWebFarmTasks=false; context.LogEvents=false; context.LogExport=false; context.LogIntegration=false; context.LogSynchronization=false; //创建/保存对象的代码位于此处 user.SetValue(“SAPID”,Guid.NewGuid());/(new Random())。下一步(01100) UserInfoProvider.SetUserInfo(用户); } } } } 捕获(例外情况除外) { EventLogProvider.LogException( 名称(CMSUSERINTEGORIONCONNECTOR), 名称(ProcessInternalTaskAsync), ex); errorMessage=ex.Message; 返回IntegrationProcessResultEnum.Error; } errorMessage=null; 返回IntegrationProcessResultEnum.OK; } } 现在发生了什么:

  • 如果在backoffice的用户模块中创建用户,则会触发连接器
  • 如果我通过电子商务网站创建了一个用户,什么都不会发生
我是否应该创建一个库项目,将C#connector类放入其中,并将其添加为两个网站中的引用,或者在配置中执行更多操作

我做错什么了吗

提前谢谢你

更新:


我测试了Dražen Janjiček提出的使用“IntegrationHelper.ProcessExternalTask”的解决方案,但它不起作用(更多信息请参见:)

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

在单独的dll中外部化连接器解决了此问题,谢谢!