本文整理汇总了C#中CommandContext类的典型用法代码示例。如果您正苦于以下问题:C# CommandContext类的具体用法?C# CommandContext怎么用?C# CommandContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandContext类属于命名空间,在下文中一共展示了CommandContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryState
public override CommandState QueryState(CommandContext context)
{
if (context.Items.Length != 1)
{
return CommandState.Disabled;
}
Item poll = context.Items[0];
if (!poll.Access.CanWrite())
{
return CommandState.Disabled;
}
PollItem pollItem = new PollItem(context.Items[0]);
if (pollItem.IsClosed)
{
return CommandState.Disabled;
}
if (pollItem.IsArchived)
{
return CommandState.Disabled;
}
return CommandState.Enabled;
}
示例2: Create
public static CommandContext Create(CommandContext parent, FileInfo fileInfo, TagCache cache, StringIdCache stringIds, HaloTag tag, Model model)
{
var context = new CommandContext(parent, string.Format("{0:X8}.hlmt", tag.Index));
context.AddCommand(new HlmtListVariantsCommand(model, stringIds));
context.AddCommand(new HlmtExtractModeCommand(cache, fileInfo, model, stringIds));
return context;
}
示例3: BotAddCommand
public void BotAddCommand(CommandContext context, IEnumerable<string> arguments)
{
if (arguments.Count() < 1)
{
SendInContext(context, "Usage: !bot add name [nick [arguments]]");
return;
}
string botID = arguments.ElementAt(0);
if (!GameManager.Bots.ContainsKey(botID))
{
SendInContext(context, "Invalid bot!");
return;
}
string botNick = arguments.ElementAtOrDefault(1) ?? botID;
try
{
Manager.AddBot(botNick, (IBot)GameManager.Bots[botID].GetConstructor(new Type[] { typeof(GameManager), typeof(IEnumerable<string>) }).Invoke(new object[] { Manager, arguments.Skip(2) }));
Manager.SendPublic(context.Nick, "Added <{0}> (a bot of type {1})", botNick, botID);
}
catch (ArgumentException e)
{
SendInContext(context, "Error adding {0}: {1}", botNick, e.Message);
}
}
示例4: Render
public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
{
var contextChunks = context.CustomData as List<Item>;
if (contextChunks != null)
{
var chunk = contextChunks[0];
contextChunks.RemoveAt(0);
var psButtons = chunk.Children;
var contextItem = context.Items.Length > 0 ? context.Items[0] : null;
var ruleContext = new RuleContext
{
Item = contextItem
};
foreach (var parameter in context.Parameters.AllKeys)
{
ruleContext.Parameters[parameter] = context.Parameters[parameter];
}
foreach (Item psButton in psButtons)
{
if (!RulesUtils.EvaluateRules(psButton["ShowRule"], ruleContext))
{
continue;
}
RenderLargeButton(output, ribbon, Control.GetUniqueID("script"),
Translate.Text(psButton.DisplayName),
psButton["__Icon"], string.Empty,
$"ise:runplugin(scriptDb={psButton.Database.Name},scriptId={psButton.ID})",
context.Parameters["ScriptRunning"] == "0" && RulesUtils.EvaluateRules(psButton["EnableRule"], ruleContext),
false, context);
}
}
}
示例5: Execute
public override void Execute(CommandContext context)
{
if (context is DeleteScheduleContext)
{
Execute((DeleteScheduleContext) context);
}
}
示例6: GetSubmenuItems
public override Control[] GetSubmenuItems(CommandContext context)
{
var controls = base.GetSubmenuItems(context);
if (controls == null || context.Items.Length != 1 || context.Items[0] == null)
{
return controls;
}
var menuItems = new List<Control>();
var roots = ModuleManager.GetFeatureRoots(IntegrationPoints.ContentEditorInsertItemFeature);
foreach (var root in ModuleManager.GetFeatureRoots(IntegrationPoints.ContentEditorInsertItemFeature))
{
ScriptLibraryMenuItem.GetLibraryMenuItems(context.Items[0], menuItems, root);
}
if (roots.Count > 0 && controls.Length > 0)
{
menuItems.Add(new MenuDivider());
}
menuItems.AddRange(controls);
return menuItems.ToArray();
}
示例7: Execute
// Methods
public override void Execute(CommandContext context)
{
var searchStringModel = ExtractSearchQuery(context.Parameters.GetValues("url")[0].Replace("\"", ""));
var hitsCount = 0;
var listOfItems = context.Items[0].Search(searchStringModel, out hitsCount).ToList();
Items.CloneTo(listOfItems.Select(i => i.GetItem()).ToArray());
}
示例8: QueryState
/// <summary>
/// Get the state of the command. The command is always visible, but disabled if
/// there is already a version in each language or if the user has no permission
/// to edit the item.
/// </summary>
/// <param name="context">The current context.</param>
/// <returns>State of the command.</returns>
public override CommandState QueryState(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
if (context.Items.Length != 1)
{
return CommandState.Hidden;
}
Item item = context.Items[0];
if (!Sitecore.Context.IsAdministrator && (!item.Access.CanWrite() || (!item.Locking.CanLock() && !item.Locking.HasLock())))
{
return CommandState.Disabled;
}
foreach (Language language in LanguageManager.GetLanguages(item.Database))
{
Item itemInLanguage = ItemManager.GetItem(item.ID, language, Sitecore.Data.Version.Latest, item.Database);
if (itemInLanguage.Versions.GetVersions().Length == 0)
{
return CommandState.Enabled;
}
}
return CommandState.Disabled;
}
示例9: Execute
/// <summary>
/// Executes the command in the specified context.
/// </summary>
/// <param name="context">The context.</param>
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
string id = context.Parameters["id"];
if (!ID.IsID(id))
{
return;
}
Item orderItem = Sitecore.Context.ContentDatabase.GetItem(new ID(id));
if (orderItem == null)
{
return;
}
ICatalogView view = context.CustomData as ICatalogView;
if (view == null)
{
return;
}
ClientPipelineArgs args = new ClientPipelineArgs(new NameValueCollection(context.Parameters));
args.Parameters.Add("uri", orderItem.Uri.ToString());
args.Parameters["fields"] = this.GetFields(view.EditorFields);
args.CustomData.Add("catalogView", view);
ContinuationManager.Current.Start(this, "Run", args);
}
示例10: Execute
public override void Execute(CommandContext context)
{
if (context.Items.Length != 1) return;
//TODO put the GUIDS used here somewhere central
//If this is a template, launch the single template generator
if (context.Items[0].TemplateID.ToString() == "{AB86861A-6030-46C5-B394-E8F99E8B87DB}")
{
//Build the url for the control
string controlUrl = UIUtil.GetUri("control:xmlGenerateCustomItem");
string id = context.Items[0].ID.ToString();
string url = string.Format("{0}&id={1}", controlUrl, id);
//Open the dialog
Context.ClientPage.ClientResponse.Broadcast(Context.ClientPage.ClientResponse.ShowModalDialog(url), "Shell");
}
//If this is a template folder, launch the folder template generateor
else if (context.Items[0].TemplateID.ToString() == "{0437FEE2-44C9-46A6-ABE9-28858D9FEE8C}")
{
//Build the url for the control
string controlUrl = UIUtil.GetUri("control:xmlGenerateCustomItemByFolder");
string id = context.Items[0].ID.ToString();
string url = string.Format("{0}&id={1}", controlUrl, id);
//Open the dialog
Context.ClientPage.ClientResponse.Broadcast(Context.ClientPage.ClientResponse.ShowModalDialog(url), "Shell");
}
else
{
SheerResponse.Alert("You can only run the Custom Item Generator on a Template or Template Folder.", new string[0]);
}
}
示例11: Execute
public override void Execute(CommandContext context)
{
PersonaHelper personaHelper = PersonaHelper.GetHelper();
personaHelper.ResetProfiles();
SheerResponse.Redraw();
}
示例12: Execute
public override void Execute(CommandContext context)
{
if (Context.Request.FilePath == "/sitecore/shell/~/xaml/sitecore.shell.applications.analytics.trackingfielddetails.aspx")
{
SheerResponse.Eval("window.location.href = window.location.href");
}
}
示例13: Render
public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
{
var psButtons = button.GetChildren();
foreach (Item psButton in psButtons)
{
var msg = Message.Parse(this, psButton["Click"]);
var scriptDb = msg.Arguments["scriptDB"];
var scriptId = msg.Arguments["script"];
if (string.IsNullOrWhiteSpace(scriptDb) || string.IsNullOrWhiteSpace(scriptId))
{
continue;
}
var scriptItem = Factory.GetDatabase(scriptDb).GetItem(scriptId);
if (scriptItem == null || !RulesUtils.EvaluateRules(scriptItem["ShowRule"], context.Items[0]))
{
continue;
}
RenderLargeButton(output, ribbon, Control.GetUniqueID("script"),
Translate.Text(scriptItem.DisplayName),
scriptItem["__Icon"], string.Empty,
psButton["Click"],
RulesUtils.EvaluateRules(scriptItem["EnableRule"], context.Items[0]),
false, context);
return;
}
}
示例14: Execute
public override void Execute(CommandContext context)
{
var selectedItem = context.Items.FirstOrDefault();
if (selectedItem == null)
return;
string templateId = "{CC80011D-8EAE-4BFC-84F1-67ECD0223E9E}";
TemplateItem newTemplate = new TemplateItem(Sitecore.Context.Database.GetItem(templateId));
if (newTemplate != null)
{
try
{
using (new Sitecore.SecurityModel.SecurityDisabler())
{
selectedItem.Editing.BeginEdit();
selectedItem.ChangeTemplate(newTemplate);
}
}
catch (Exception ex)
{
Log.Error(ex.Message, ex, this);
throw;
}
finally
{
selectedItem.Editing.EndEdit();
}
}
}
示例15: Execute
public override void Execute(CommandContext context)
{
ID id = ID.Null;
bool isId = false;
var fieldId = context.Parameters["fieldId"];
if (!string.IsNullOrEmpty(fieldId))
{
var form = System.Web.HttpContext.Current.Request.Form;
if (form != null)
{
string targetId = form[string.Format("{0}{1}", fieldId, Constants.Selected)];
if (string.IsNullOrEmpty(targetId))
{
targetId = form[string.Format("{0}{1}", fieldId, Constants.Unselected)];
}
isId = ID.TryParse(targetId, out id);
}
}
Sitecore.Context.ClientPage.SendMessage(this, "item:load(id=" + (isId ? id.ToString() : string.Empty) + ")");
}