2016-03-03 93 views
2

我試圖在this answer中實施解決方案,以便能夠限制WeBlog中標籤雲中顯示的標籤數量。另外,我從文檔中使用these instructions如何在Sitecore中的WeBlog模塊中覆蓋ITagManager

我修改了WeBlog配置以指向我自己的自定義TagManager實現。

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

如果我加載sitecore/admin/showconfig.aspx我可以確認配置設置已經更新了新的價值。

我的CustomTagManager目前是ITagManager接口的裸機實現。

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(); 
    } 
} 

我可以反映部署的DLL,看到這些更改是肯定做出的,但這些更改沒有影響。沒有任何例外被拋出,標籤雲繼續填充,就好像我根本沒有做任何改變。這就像配置文件的變化被完全忽略。

爲了編寫我自己的客戶TagManager類,還需要更改哪些內容?

我正在使用WeBlog 5.2和Sitecore 7.1。

+0

您可以檢查是否有在日誌什麼?如果WeBlog無法創建在配置中定義的管理器,它會記錄異常:「無法創建類型」{0}「的實例爲類型」{1}「」 –

+0

您能否將程序集添加到config <<設置名稱=「WeBlog.Implementation.TagManager」value =「My.Namespace.CustomTagManager,MyAssembly」/>'? –

+0

Hi @MarekMusielak - 這是問題所在。我已經添加了包含程序集完全限定名的答案。 – psych

回答

0

查看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; 
}