我尝试创建一个调试按钮,如下所示,参考底部的链接#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” .. 任何人都可以看到如果我没记错吗?
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;
}
}
}