简体   繁体   English

如何为Sitecore 8.2.5配置数据提供程序,以便Sitecore内核调用其构造函数?

[英]How do I have to configure a dataprovider for Sitecore 8.2.5 so its constructor is called by the Sitecore Kernel?

We upgraded from Sitecore 8.1 to 8.2.5 and one of the dataproviders we use, but did not code ourselves is not working anymore. 我们从Sitecore 8.1升级到8.2.5,并且使用了其中一个数据提供程序,但没有编写自己的代码已无法正常工作。

So far we could trace the problem to the constructor never being called by the Sitecore Kernel on the intial loading of the page, which prevents the dataprovider from working properly. 到目前为止,我们可以将问题追溯到页面初始加载时Sitecore内核从未调用过构造函数,这使dataprovider无法正常工作。

We have not changed anything in our config files, but as far as we know 8.2 has changed how dependency injections work. 我们没有更改配置文件中的任何内容,但据我们所知8.2已更改了依赖项注入的工作方式。

Config file entries: 配置文件条目:

<sitecore database="SqlServer">

<events timingLevel="none">
    <!-- Dataprovider Events -->
    <event name="item:saved">
        <handler type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProviderNotification, Company.WCMS.PROJECT.Common" method="OnItemSaved"/>
    </event>
    <event name="item:saved:remote">
        <handler type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProviderNotification, Company.WCMS.PROJECT.Common" method="OnItemSavedRemote"/>
    </event>
    <event name="publish:end">
        <handler type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProviderNotification, Company.WCMS.PROJECT.Common" method="OnPublishComplete"/>
    </event>
    <event name="publish:end:remote">
        <handler type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProviderNotification, Company.WCMS.PROJECT.Common" method="OnPublishComplete"/>
    </event>
    <!-- /Dataprovider Events -->
</events>

<pipelines>

    <publishItem>
    <processor patch:before="processor[@type='Sitecore.Publishing.Pipelines.PublishItem.DetermineAction, Sitecore.Kernel']" type="Company.WCMS.PROJECT.Common.DataProvider.PublishPreventer, Company.WCMS.PROJECT.Common" />
    </publishItem>

</pipelines>

<!-- DataProvider -->
<dataProviders>
    <DynamicDataProvider type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProvider, Company.WCMS.PROJECT.Common" patch:before="*[@type='Sitecore.Data.$(database).$(database)DataProvider, Sitecore.Kernel']"/>
</dataProviders>
<!-- /DataProvider -->

<!-- DATABASES -->
<databases>
    <database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
        <param desc="name">$(id)</param>
        <icon>Images/database_master.png</icon>
        <dataProviders hint="list:AddDataProvider">
        <dataProvider ref="dataProviders/main" param1="$(id)">
            <prefetch hint="raw:AddPrefetch">
            <sc.include file="/App_Config/Prefetch/Common.config" />
            <sc.include file="/App_Config/Prefetch/Master.config" />
            </prefetch>
        </dataProvider>

            <!-- Custom Changes Start -->
        <dataProvider ref="dataProviders/DynamicDataProvider"  patch:after="*[@ref='dataProviders/main']"/>
            <!-- Custom Changes End -->

        </dataProviders>
    </database>
    ...
<databases>

Beginning and constructor of our dataprovider: 我们的数据提供程序的开头和构造函数:

using System.Reflection;
using Sitecore.Diagnostics;

namespace Company.WCMS.PROJECT.Common.DataProvider.Dynamic
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

using Sitecore.Caching;
using Sitecore.Collections;
using Sitecore.Data;
using Sitecore.Data.DataProviders;
using Sitecore.Data.Fields;
using Sitecore.Data.Items;

using System.Collections.Concurrent;

using Name.Framework.ClassGenerator;

using Sitecore.Configuration;
using Sitecore.Events;
using Sitecore.Publishing;

public class DynamicDataProvider : DataProvider
{
    public static readonly ID OrginalFieldId = new ID("{f8ea7f10-f7f6-4c5a-a409-097728cc3f55}");

    private static readonly MD5CryptoServiceProvider Md5 = new MD5CryptoServiceProvider();
    private static readonly List<Action<IBaseSitecoreItem>> RefreshHandler = new List<Action<IBaseSitecoreItem>>();
    private static readonly List<Action<Database, bool>> ClearIdsHandler = new List<Action<Database, bool>>();

    private readonly HashSet<ID> rootItems = new HashSet<ID>();
    private readonly ConcurrentDictionary<ID, HashSet<ID>> realToFakeId = new ConcurrentDictionary<ID, HashSet<ID>>();
    private readonly ConcurrentDictionary<ID, FakeIdBucket> fakeCache = new ConcurrentDictionary<ID, FakeIdBucket>();
    private readonly List<IDynamicDataProvider> providers = new List<IDynamicDataProvider>();
    private readonly Dictionary<ID, List<IDynamicDataProvider>> tempalteToProviders = new Dictionary<ID, List<IDynamicDataProvider>>();

    private static string ItemIcon = Settings.GetSetting("Leister.Internet.DataProvider.ItemIcon", string.Empty);

    public static event Func<IBaseSitecoreItem, bool> RefreshItem;

    public DynamicDataProvider()
    {

        this.LoadProviders();

        RefreshHandler.Add(this.RefreshLocal);
        ClearIdsHandler.Add(this.ClearIds);
    }

RefreshHandler is always empty as the constructor is never called which prevents other functions from working. RefreshHandler始终为空,因为从不调用构造函数,这会阻止其他函数正常工作。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

As we suspected it was a problem in the config files. 由于我们怀疑这是配置文件中的问题。 Sitecore changed the Database type name from Database to DefaultDatabase and we did not notice that and so our patch referred to the wrong type. Sitecore将数据库类型名称从数据库更改为DefaultDatabase,我们没有注意到这一点,因此我们的补丁程序引用了错误的类型。 We adjusted that and now it works. 我们对此进行了调整,现在可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM