2

I am trying to implement the solution in this answer to be able to restrict the number of tags which show in the tag cloud in WeBlog. Additionally, I am using these instructions from the documentation.

I have modified the WeBlog config to point to my own custom TagManager implementation.

<setting name="WeBlog.Implementation.TagManager" value="My.Namespace.CustomTagManager"/>

If I load sitecore/admin/showconfig.aspx I can confirm the config setting has been updated with the new value.

My CustomTagManager is currently a bare bones implementation of the ITagManager interface.

public class CustomTagManager : ITagManager
{
    public string[] GetTagsByBlog(ID blogId)
    {
        throw new System.NotImplementedException();
    }

    public string[] GetTagsByBlog(Item blogItem)
    {
        throw new System.NotImplementedException();
    }

    public Dictionary<string, int> GetTagsByEntry(EntryItem entry)
    {
        throw new System.NotImplementedException();
    }

    public Dictionary<string, int> GetAllTags()
    {
        throw new System.NotImplementedException();
    }

    public Dictionary<string, int> GetAllTags(BlogHomeItem blog)
    {
        throw new System.NotImplementedException();
    }

    public Dictionary<string, int> SortByWeight(IEnumerable<string> tags)
    {
        throw new System.NotImplementedException();
    }
}

I can reflect the deployed DLL and see these changes have definitely be made, but the changes have no affect. None of the exceptions are thrown and the tag cloud continues to populate as if I'd made no changes at all. It is like the config file change is being completely ignored.

What else do I need to change in order to write my own customer TagManager class?

I am using WeBlog 5.2 and Sitecore 7.1.

4

1 に答える 1

0

WeBlog のコードを確認したところ、フォールバック オブジェクトが使用されていて、構成の変更が無視されていることが明らかになりました。

これの原因は、WeBlog が行うことです。

var type = Type.GetType(typeName, false);

このGetTypeメソッドは、型が mscorlib.dll または現在のアセンブリで見つかった場合にのみ機能します。そのため、アセンブリの完全修飾名を指定するだけで簡単に修正できます。

<setting name="WeBlog.Implementation.TagManager" value="My.Assembly.CustomTagManager, My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>

これはブログのコードです:

private static T CreateInstance<T>(string typeName, Func<T> fallbackCreation) where T : class
{
    var type = Type.GetType(typeName, false);
    T instance = null;
    if (type != null)
    {
        try
        {
            instance = (T)Sitecore.Reflection.ReflectionUtil.CreateObject(type);
        }
        catch(Exception ex)
        {
            Log.Error("Failed to create instance of type '{0}' as type '{1}'".FormatWith(type.FullName, typeof(T).FullName), ex, typeof(ManagerFactory));
        }
    }

    if(instance == null)
        instance = fallbackCreation();

    return instance;
}
于 2016-03-03T11:01:48.893 に答える