Umbraco:创建没有单独项目/ DLL的自定义树?

时间:2011-11-23 23:57:57

标签: umbraco

我需要将自定义树添加到“网站”的自定义部分(即服务器的inetpub目录中的文件夹)

我可以通过创建一个新项目(因此是一个新的DLL),并将DLL复制到网站的bin文件夹来实现。但这会对网站外的另一个项目造成依赖,这在我的案例中是不可接受的。

有没有办法在不创建单独的DLL的情况下创建自定义树(例如,只需在AppCode文件夹中创建一个类)?

有没有办法在 umbracoAppTree 表的 treeHandlerAssembly 列中输入类名(而不是DLL名)?

提前致谢!

1 个答案:

答案 0 :(得分:0)

我解决了!
这篇文章帮助了我http://www.shazwazza.com/post/Dynamically-registering-custom-trees-without-writing-to-UmbracoAppTree.aspx

除此之外我无法在其他地方找到任何帮助,希望这会对某人有所帮助。

  static object _locker = new object();

  /// <summary>
  /// Adds a custom tree to a custom section in Umbraco
  /// </summary>
  /// <param name="customTreeType">Your custom tree that is inherited from BaseTree</param>
  /// <param name="alias">Your custom section alias</param>
  public static void RenderCustomTree(Type customTreeType, string alias)
  {
      // Check if customTree is already registered
      if (TreeDefinitionCollection.Instance.Count(x => x.TreeType == customTreeType) == 0)
      {
        lock (_locker)
        {
          // Double check
          if (TreeDefinitionCollection.Instance.Count(x => x.TreeType == customTreeType) == 0)
          {
            Application customApp = new Application(alias, alias, ".traycontent");

            // Create the tree definition
            var myCustomTree = new TreeDefinition(customTreeType,
                                  new umbraco.BusinessLogic.ApplicationTree(true, true, 0,
                                      alias,                      //applicationAlias,
                                      alias,                      //alias
                                      alias,                      //title
                                      ".sprTreeFolder",           //iconClosed
                                      ".sprTreeFolder_o",         //iconOpened
                                      "uComponents.Core",         //assemblyName
                                      customTreeType.ToString(),  //type
                                      null),                      //action
                                  customApp);

            // Add our tree definition to the collection at runtime
            TreeDefinitionCollection.Instance.Add(myCustomTree);
          }
        }
      }
  }

在你自己的类中继承自IHttpModule:

  public void Init(HttpApplication application)
  {
    RenderCustomTree(typeof(YourCustomTree), "yourCustomSection");
  }