1

我尝试创建一个调试按钮,如下所示,参考底部的链接#3,我已经编译并配置了核心数据库中的按钮并配置了 Commands.config,但是当我单击时,我在主数据库上收到错误消息功能区和 sitecore 管理客户端已重新启动。我没有得到错误消息指向的内容..!

功能区按钮屏幕

在调试器中打开

错误消息文本

控制“系统”在表单上不存在。在 Sitecore.Shell.Framework.Commands.CommandManager.GetMethodCommand(String command) 在 Sitecore.Shell.Framework.Commands.CommandManager.GetDispatchCommand(String command) 在 Sitecore.Web.UI.Sheer.ClientPage.Dispatch(String command) 在 Sitecore .Web.UI.Sheer.ClientPage.RaiseEvent() 在 Sitecore.Web.UI.Sheer.ClientPage.OnPreRender(EventArgs e)

错误信息屏幕

错误信息屏幕

底部提到的链接#2的另一件事似乎不包含 John 在此处的博客文章中所说的“资源部分中可用的原型 zip” .. 任何人都可以看到如果我没记错吗?

PS:链接#1链接#2的旧帖子

Debug.cs 代码

using System;

namespace SitecoreDemo.Shell.Framework.Commands.System
{
    [Serializable]
    // implements the debug command on the Sitecore menu of the desktop
    // and in the ribbon of the Content Editor
    public class Debug : Sitecore.Shell.Framework.Commands.System.Debug
    {
        public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
        {
            // validate arguments and processing context
            Sitecore.Diagnostics.Assert.ArgumentNotNull(context, "context");
            Sitecore.Diagnostics.Assert.IsNotNull(Sitecore.Context.ClientPage, "ClientPage");
            Sitecore.Diagnostics.Assert.IsNotNull(Sitecore.Context.ClientPage, "ClientResponse");

            // ensure the new browser window authenticates as the current CMS user
            // (in case the user formerly previewed as another user)
            Sitecore.Publishing.PreviewManager.RestoreUser();

            // open the new browser window
            Sitecore.Web.UI.Sheer.SheerResponse.Eval("window.open('" + this.GetDebuggingUrl(context) + "', '_blank');");
        }

        // construct a URL to launch the debugger
        private string GetDebuggingUrl(Sitecore.Shell.Framework.Commands.CommandContext context)
        {
            // whether to use the sc_lang query string parameter to specify the language
            bool includeLanguage = Sitecore.Links.LinkManager.LanguageEmbedding != Sitecore.Links.LanguageEmbedding.Never;

            // URL of the debugging window defaults to home page of managed site
            Sitecore.Text.UrlString url = new Sitecore.Text.UrlString("/");

            // enable all debugging options
            url.Add("sc_debug", "1"); // enable the debugger
            url.Add("sc_prof", "1"); // enable profiling
            url.Add("sc_trace", "1"); // enable tracing
            url.Add("sc_ri", "1"); // enable rendering information

            // if the user has selected an item, ensure they have saved,
            // then debug the item in the database and language associated with that item
            if (context != null && context.Items != null && context.Items.Length > 0 && context.Items[0] != null)
            {
                Sitecore.Context.ClientPage.ClientResponse.CheckModified(false);

                Sitecore.Data.Items.Item item = context.Items[0];
                url.Add("sc_database", item.Database.Name);
                url.Add("sc_itemid", item.ID.ToString());

                if (includeLanguage)
                {
                    url.Add("sc_lang", item.ID.ToString());
                }
            }

            // if the user has not selected an item,
            // if there is a content database, debug that database
            // using the content language
            else if (Sitecore.Context.ContentDatabase != null)
            {
                url.Add("sc_database", Sitecore.Context.ContentDatabase.Name);
                if (includeLanguage)
                {
                    url.Add("sc_lang", Sitecore.Context.ContentLanguage.Name);
                }
            }

            // return a URL to open the debugger
            return url.GetUrl();
        }

        public override Sitecore.Shell.Framework.Commands.CommandState QueryState(Sitecore.Shell.Framework.Commands.CommandContext context)
        {
            // if the user has selected at least one item
            if (context.Items != null && context.Items.Length > 0 && context.Items[0] != null)
            {
                // if that item does not specify a layout for any device, disable this command
                if (!this.HasLayoutForAnyDevice(context.Items[0]))
                {
                    return Sitecore.Shell.Framework.Commands.CommandState.Disabled;
                }
            }
            return base.QueryState(context);
        }

        // returns true if the item specifies a layout for any device
        protected bool HasLayoutForAnyDevice(Sitecore.Data.Items.Item item)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(item, "item");

            // evaluate each device in the database containing the item
            foreach (Sitecore.Data.Items.DeviceItem compare in item.Database.Resources.Devices.GetAll())
            {
                // if the item specifies layout details for that device, return true
                if (item.Visualization.GetLayout(compare) != null)
                {
                    return true;
                }
            }

            // layout details for the item do not specify a layout for any device
            return false;
        }
    }
}

参考链接:

  1. 向 Sitecore 内容编辑器功能区添加一个按钮以调试任何数据库中的任何项目
  2. 更新:将调试命令添加到 Sitecore ASP.NET CMS 中的内容编辑器
  3. 专业 Sitecore 开发 - Google 图书
4

2 回答 2

0

原型链接有一个 zip 文件并包含 Debug.cs 文件。下面的代码

using System;

namespace Sitecore.Sharedsource.Shell.Framework.Commands.System
{
  [Serializable]
  public class Debug : Sitecore.Shell.Framework.Commands.Command
  {
    public override void Execute(
      Sitecore.Shell.Framework.Commands.CommandContext context)
    {
      Context.ClientPage.ClientResponse.CheckModified(false);
      Sitecore.Data.Database contentDatabase = Context.ContentDatabase;

      if ((context.Items != null) && (context.Items.Length == 1))
      {
        Sitecore.Data.Database database = context.Items[0].Database;
      }

      Sitecore.Text.UrlString webSiteUrl = 
        Sitecore.Sites.SiteContext.GetWebSiteUrl();
      webSiteUrl.Add("sc_debug", "1");

      if ((context.Items != null) && (context.Items.Length == 1))
      {
        Sitecore.Data.Items.Item item = context.Items[0];

        if (item.Visualization.Layout != null)
        {
          webSiteUrl.Add("sc_itemid", item.ID.ToString());
        }

        webSiteUrl.Add("sc_lang", item.Language.ToString());
      }

      if (contentDatabase != null)
      {
        webSiteUrl.Add("sc_database", contentDatabase.Name);
      }

      webSiteUrl.Add("sc_prof", "1");
      webSiteUrl.Add("sc_trace", "1");
      webSiteUrl.Add("sc_ri", "1");
      Context.ClientPage.ClientResponse.Eval(
        "window.open('" + webSiteUrl + "', '_blank')");
    }
  }
}

让我知道此代码是否对您有帮助,如果我找到更多信息会回复您。

于 2013-04-19T13:55:10.317 回答
0

博客文章更新:在 Sitecore ASP.NET CMS 中将调试命令添加到内容编辑器中提供的解决方案原型解决我的问题,我在命令中配置了自己的类文件,并将文件从指定的文件夹位置复制在帖子中(也在下面提到),它现在正在工作。Debug.csDebug.itemsolution prototype zip

出于我的目的,将“调试项目”菜单添加到上下文项目中

对于将来的参考,请查看博客文章中显示的步骤,以配置对我有帮助的解决方案原型。

使用序列化文件创建命令定义项:

  1. 将 Debug.item 文件从本博 文末尾的资源部分中提供的原型 zip 复制到/data/serialization/core/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish您的 Sitecore 解决方案的子目录,该/data文件夹通常是该文件夹的同级 Website文件夹。
  2. 以管理员身份登录 Sitecore 桌面。
  3. 单击右下角的数据库图标,然后从出现的菜单中选择 Core(如 Sitecore Client Configuration Cookbook 中所述)。
  4. 打开内容编辑器,导航到 /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish 项目(将该路径复制到剪贴板,将其粘贴到内容树上方的搜索框中,按 Enter,选择第一个结果)。
  5. 在 Developer 选项卡上的 Serialize 组中,单击 Revert Tree。如果您右键单击/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish内容树中的项目,然后从出现的子菜单中单击刷新,则应该会出现一个新的调试项目。
  6. 请记住使用数据库图标来选择主数据库。

PS:但是,当我自己在核心数据库的内容编辑器中创建调试项目时,它不起作用,不知道为什么。

于 2013-04-22T07:00:21.353 回答