private void PerformCommand(CommandKey key) { if (_commandManager.CanPerform(key)) { _commandManager.Perform(key); } }
private void TryAddValueItem(Match match) { var matchKey = match.Value; var isMatch = new Regex(ValuePattern).IsMatch(matchKey); if (!isMatch) { return; } var key = matchKey.Replace("{", "").Replace("}", ""); bool isOptional = key[0] == '?'; if (isOptional) { key = key.Replace("?", ""); var itemKey = new CommandKey(key, true); Keys.Add(itemKey); } else { var itemKey = new CommandKey(key); Keys.Add(itemKey); } }
void IKeyboardControl.Create(CommandKeyRef keyRef, CommandKey key) { ButtonManager manager; switch (key.CommandType) { case "Navigate": manager = NavigateCommandButtonManager.CreateInstance(_parent, key); break; case "Function": manager = FunctionCommandButtonManager.CreateInstance(_parent, key); break; case "Modifier": manager = ModifierCommandButtonManager.CreateInstance(_parent, key); break; case "Custom": manager = CustomCommandButtonManager.CreateInstance(_parent, key); break; default: throw new InvalidOperationException(); } _parent.AddManager(this, keyRef, manager); }
public bool OnKey(Keys key) { if (key == Keys.Return) { // Note: This is temporary, should be handled as other commands if we want to implement support for '/' search for instance. this.context = this.context.Clear(); return(false); } var handledKey = false; if (this.context.DeferredCommand != null) { var result = this.context.DeferredCommand.Execute(this.context, key); this.context = result.Context; handledKey = result.State == CommandState.Handled; } if (!handledKey) { var commandKey = new CommandKey(this.context.Mode, key); if (this.commands.TryGetValue(commandKey, out ICommand command)) { var result = command.Execute(this.context, key); this.context = result.Context; handledKey = result.State == CommandState.Handled; } } this.logger.Log($"{key} handled = {handledKey}"); return(handledKey); }
public bool AddChannelHandle(string id, MarketMessageType type, IUserChannelNotification channel) { CommandKey key = new CommandKey(type, id); bool firstHandle = false; if (!messageListeners.TryGetValue(key, out IEnumerable <IUserChannelNotification> list)) { list = new ConcurrentBag <IUserChannelNotification>(); messageListeners.TryAdd(key, list); firstHandle = true; } else { if (bookCache.TryGetValue(id, out BookMessageCache cache)) { channel.Arrived(cache.Snapshot()); } } if (!list.Contains(channel)) { ((ConcurrentBag <IUserChannelNotification>)list).Add(channel); } return(firstHandle); }
private void ExecuteCommand(CommandKey cmdKey) { if (this.CommandAction != null) { this.CommandAction(this, cmdKey); } }
private void PerformCommand(CommandKey key, object param) { if (CanPerformCommand(key, param)) { _commandManager.Perform(key, param); } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } if (CommandKey.Any(x => context.Message.StartsWith(x))) { string[] tmp = context.Message.Split(' '); var reg = new Regex("([0-9]{7,11})"); if (tmp.Length == 2) { var phone = reg.Match(tmp[1]); if (phone.Success) { var result = GetPhone(phone.Value); if (result != null) { context.Answers.Add(string.Join(",", result)); } } else { context.Alerts.Add("格式不对,参考:" + Example()[0]); } } } }
/// <summary> /// Initializes a new instance of the <see cref="DefaultLinkNavigator"/> class. /// </summary> public DefaultLinkNavigator() { // register all ApperanceManager commands this.Commands.Add(CommandKey.GetOrCreate(@"cmd:/accentcolor"), AppearanceManager.Current.AccentColorCommand); this.Commands.Add(CommandKey.GetOrCreate(@"cmd:/darktheme"), AppearanceManager.Current.DarkThemeCommand); this.Commands.Add(CommandKey.GetOrCreate(@"cmd:/largefontsize"), AppearanceManager.Current.LargeFontSizeCommand); this.Commands.Add(CommandKey.GetOrCreate(@"cmd:/lighttheme"), AppearanceManager.Current.LightThemeCommand); this.Commands.Add(CommandKey.GetOrCreate(@"cmd:/settheme"), AppearanceManager.Current.SetThemeCommand); this.Commands.Add(CommandKey.GetOrCreate(@"cmd:/smallfontsize"), AppearanceManager.Current.SmallFontSizeCommand); // register application commands foreach (var cmd in GetRoutedUiCommandsFrom(typeof(ApplicationCommands))) { this.Commands.Add(CommandKey.GetOrCreate($@"cmd:/{cmd.Name}"), cmd); } foreach (var cmd in GetRoutedUiCommandsFrom(typeof(SystemCommands))) { this.Commands.Add(CommandKey.GetOrCreate($@"cmd:/{cmd.Name}"), cmd); } //// foreach (var cmd in GetRoutedUiCommandsFrom(typeof(MediaCommands))) //// { //// this.Commands.Add(new CommandKey(string.Format(@"cmd:/{0}", cmd.Name)), cmd); //// } foreach (var cmd in GetRoutedUiCommandsFrom(typeof(NavigationCommands))) { this.Commands.Add(CommandKey.GetOrCreate($@"cmd:/{cmd.Name}"), cmd); } this.NavigatesToContentOnLoad = true; }
//private ICommand CreateCommand<TCommandType>(CommandKey commandKey) where TCommandType : ICommand //{ // if (!_commands.ContainsKey(commandKey)) // { // _commands.Add(commandKey, Activator.CreateInstance<TCommandType>()); // } // return _commands[commandKey]; //} private ICommand CreateCommand(CommandKey commandKey, Type type, object[] parameters) { if (!_commands.ContainsKey(commandKey)) { _commands.Add(commandKey, (ICommand)Activator.CreateInstance(type, parameters)); } return(_commands[commandKey]); }
private void Invalidate(CommandKey key) { if (_commandMap.ContainsKey(key)) { ToolStripButton item = _commandMap[key]; item.Enabled = CanPerformCommand(key); item.Checked = IsCommandSelected(key); } }
private void MapMenuItem(CommandKey key, ToolStripMenuItem item) { if (key != CommandKey.Unknown && item != null) { _menuMap.Add(key, item); item.Click += BoundMenuClickHandler; Invalidate(key); } }
private void Invalidate(CommandKey key) { ToolStripButton button; if (_commandButtonMap.TryGetValue(key, out button)) { button.Enabled = CanPerformCommand(key); button.Checked = IsCommandSelected(key); } }
/// <summary> /// Determines whether the specified object is equal to the current instance. /// </summary> /// <param name="obj">An object to compare.</param> /// <returns>True if they are considered equal, otherwise false.</returns> public override bool Equals(object obj) { CommandKey key = obj as CommandKey; if (key == null) { return(false); } return(CommandKey.AreEqual(this, key)); }
/// <summary> /// Initializes a new instance of the CommandWarningEvent class. /// </summary> /// <param name="commandKey">The key for the command raising the warning.</param> /// <param name="commandGroup">The group for the command raising the warning.</param> /// <param name="commandName">The name for the command raising the warning.</param> /// <param name="message">A warning message.</param> internal CommandWarningEvent(CommandKey commandKey, string commandGroup, string commandName, string message) : base(commandKey) { Throw.IfArgumentNullOrWhitespace(commandGroup, "commandGroup"); Throw.IfArgumentNullOrWhitespace(commandName, "commandName"); Throw.IfArgumentNullOrWhitespace(message, "message"); this.Message = message; this.CommandGroup = commandGroup; this.CommandName = commandName; }
public CommandRecord Lookup(CommandKey key) { CommandRecord inst; if (_registry.TryGetValue(key, out inst)) { return(inst); } else { return(null); } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } var anwer = ""; if (CommandKey.Any(x => context.Message.StartsWith(x))) { // bool EnableFlag = false; // if (context.State != null && context.GetState<bool>(SettingKey)) // { // EnableFlag = true; // } // else if(context.MessageType=="message"){ // EnableFlag = true; // } // if (EnableFlag) // { string[] tmp = context.Message.Split(' '); if (tmp.Length == 2) { anwer = GetStock(tmp[1], ""); } else if (tmp.Length == 3) { anwer = GetStock(tmp[1], tmp[2]); } else { context.Alerts.AddRange(Example()); } if (!string.IsNullOrEmpty(anwer)) { context.Answers.Add(anwer); var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "stock"; newlog.P1 = tmp[tmp.Length - 1]; newlog.Data = anwer; OrmManager.Insert(newlog); // } } } }
/// <summary> /// Compares the objects for equality. /// </summary> /// <param name="lhs">The left hand side.</param> /// <param name="rhs">The right hand side.</param> /// <returns>True if they are equal.</returns> public static bool operator ==(CommandKey lhs, CommandKey rhs) { if (object.ReferenceEquals(lhs, rhs)) { return(true); } if ((object)lhs == null || (object)rhs == null) { return(false); } return(CommandKey.AreEqual(lhs, rhs)); }
private void TryAddConstItem(Match match) { var matchKey = match.Value; var isMatch = new Regex(ConstPattern).IsMatch(matchKey); if (!isMatch) { return; } var itemKey = new CommandKey(matchKey, isOptional: false, isConst: true); Keys.Add(itemKey); }
private void Invalidate(CommandKey key) { if (_buttonMap.ContainsKey(key)) { ToolStripButton item = _buttonMap[key]; item.Enabled = CanPerformCommand(key, TagValueFromItem(item)); item.Checked = IsCommandSelected(key); } if (_menuMap.ContainsKey(key)) { ToolStripMenuItem item = _menuMap[key]; item.Enabled = CanPerformCommand(key, TagValueFromItem(item)); item.Checked = IsCommandSelected(key); } }
public virtual void UnregisterCommand(ICommand command, String parameterKey, int priority) { CommandKey commandKey = new CommandKey(command, parameterKey, priority); ICommandContainer commandContainer = keyToCommandContainer.GetExtension(commandKey); if (!AlwaysExecutable) { commandContainer.CanExecuteChanged -= OnCanExecuteChanged; } if ((command is IAsyncCommand) || ((command is CommandRegistry) && ((CommandRegistry)command).IsAsync)) { --nAsyncCommandsRegistered; } keyToCommandContainer.Unregister(commandContainer, commandKey); }
public IConsoleCommand GetCommand(ParsedCommand userCmd) { var lookupData = new CommandKey(userCmd.Command, userCmd.NumArguments); if (!m_CmdData.TryGetValue(lookupData, out IConsoleCommand cmd)) { // see if "cmd" was a help command (these are separate since they rely on the command // table being built prior to their construction). if (userCmd.Command == "help" && userCmd.NumArguments == 0) { cmd = m_OverallHelpCmd; } } return(cmd); }
private static void Register(CommandKey key, string displayName, Image resource = null, Keys shortcut = Keys.None, string description = null, string shortcutDisplay = null) { CommandRecord record = new CommandRecord(key) { DisplayName = displayName, Description = description, Shortcut = shortcut, ShortcutDisplay = shortcutDisplay, }; if (resource != null) { record.Image = resource; } _default.Register(record); }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } List <string> anwer = null; if (CommandKey.Any(x => context.Message.StartsWith(x))) { bool EnableFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableFlag = true; } else if (context.MessageType == "message") { EnableFlag = true; } if (EnableFlag) { string[] tmp = context.Message.Trim().Split(' '); if (tmp.Length == 2) { anwer = GetWeather(tmp[1]); } else { context.Alerts.AddRange(Example()); } if (anwer != null && anwer.Count > 0) { context.Answers.AddRange(anwer); var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "weather"; newlog.P1 = tmp[1]; newlog.Data = string.Join(",", anwer); OrmManager.Insert(newlog); } } } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } //var message = context.Message.ToLower(); if (CommandKey.Any(x => context.Message.IndexOf(x, StringComparison.InvariantCultureIgnoreCase) >= 0)) { bool EnableFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableFlag = true; } else if (context.MessageType == "message") { EnableFlag = true; } if (EnableFlag) { var result = GetResult(context.Message); if (result.Count() == 1 && string.IsNullOrEmpty(result[0])) { return; } else { context.Answers.AddRange(result); try { var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "orchard"; newlog.P1 = context.Message; newlog.Data = string.Join("回复了:", result); OrmManager.Insert(newlog); } catch { } } } } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } if (CommandKey.Any(x => context.Message.StartsWith(x))) { string[] tmp = context.Message.Split(' '); var reg15 = new Regex("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3$"); var reg18 = new Regex("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$"); if (tmp.Length == 2) { var id15 = reg15.Match(tmp[1]); if (id15.Success) { var result = GetID(id15.Value); if (result != null) { context.Answers.Add(string.Join(Environment.NewLine, result)); } } else { var id18 = reg18.Match(tmp[1]); if (id18.Success) { var result = GetID(id18.Value); if (result != null) { context.Answers.Add(string.Join(",", result)); } } else { context.Alerts.Add("格式不对,参考:" + Example()[0]); } } } else { context.Alerts.Add("格式不对,参考:" + Example()[0]); } } }
public bool RemoveChannelHandle(string id, MarketMessageType type, IUserChannelNotification channel) { CommandKey key = new CommandKey(type, id); if (messageListeners.TryGetValue(key, out IEnumerable <IUserChannelNotification> list)) { var tmp = list.ToList(); tmp.Remove(channel); if (!tmp.Any()) { messageListeners.Remove(key, out list); return(true); } } return(false); }
private void webBrowser2_Navigating(object sender, WebBrowserNavigatingEventArgs e) { string kbPath; IDictionary <string, string> parms = new Dictionary <string, string>(); if (UriHelper.Parse(e.Url.ToString(), out kbPath, parms)) { CommandKey cmdKey = CommandKey.Empty; object[] cmdParams = null; if (parms.ContainsKey(UriHelper.CommandKey)) { string[] commandKey = parms[UriHelper.CommandKey].Split(';'); if (commandKey.Length == 2) { cmdKey.Package = new Guid(commandKey[0]); cmdKey.Name = commandKey[1]; cmdParams = new object[1]; cmdParams[0] = parms; } else { if (commandKey.Length == 1) { cmdKey.Package = Guid.Empty; cmdKey.Name = commandKey[0]; cmdParams = new object[1]; cmdParams[0] = parms; } } } else { /*cmdKey = CommandKeys..Core.OpenKnowledgeBase; * cmdParams = new object[1] { url };*/ } ICommandDispatcherService service = UIServices.CommandDispatcher; if (service != null) { service.Dispatch(cmdKey, new CommandData(cmdParams)); } } }
public bool OnKey(Keys key) { if (key == Keys.Return) { this.executionContext = this.executionContext.Clear(); return(false); } var handledKey = false; if (this.executionContext.DeferredExecutable != null) { var result = this.executionContext.DeferredExecutable.Execute(this.executionContext, key); this.executionContext = result.ExecutionContext; handledKey = result.State == CommandState.Handled; } if (!handledKey) { var commandKey = new CommandKey(this.executionContext.Mode, key); if (this.commands.TryGetValue(commandKey, out ICommand command)) { try { var result = command.Execute(this.executionContext, key); this.executionContext = result.ExecutionContext; handledKey = result.State == CommandState.Handled; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } else if (this.executionContext.Mode == InputMode.Yank || this.executionContext.Mode == InputMode.Go) { handledKey = true; this.executionContext = this.executionContext.Clear(); } } this.logger.Log($"{key} handled = {handledKey}"); return(handledKey); }
protected virtual void RegisterCommandIntern(ICommand command, Object parameter, int priority, String parameterKey) { ICommandContainer commandContainer = new CommandContainer(); commandContainer.Command = command; commandContainer.CommandParameter = parameter; commandContainer.Priority = priority; CommandKey commandKey = new CommandKey(command, parameterKey, priority); keyToCommandContainer.Register(commandContainer, commandKey); if ((command is IAsyncCommand) || ((command is CommandRegistry) && ((CommandRegistry)command).IsAsync)) { ++nAsyncCommandsRegistered; } if (!AlwaysExecutable) { commandContainer.CanExecuteChanged += OnCanExecuteChanged; OnCanExecuteChanged(commandContainer, EventArgs.Empty); } }
static CommandKeys() { OpenWindowsAppCommand = new CommandKey(Package.guid, "OpenWindowsApp"); OpenAndroidAppCommand = new CommandKey(Package.guid, "OpenAndroidApp"); OpeniOSAppCommand = new CommandKey(Package.guid, "OpeniOSApp"); }
public CommandSubscriberEventArgs(CommandKey key) { CommandKey = key; }
/// <summary> /// Run QueryStatus and return whether or not it should be enabled /// </summary> private bool RunQueryStatus(OleCommandData oleCommandData) { // First check and see if this represents a cached call to QueryStatus. Visual Studio // will cache the result of QueryStatus for most types of commands that Vim will be // interested in handling. // // I haven't figured out the exact rules by which this cache is reset yet but it appears // to be when a QueryStatus / Exec pair executes succesfully or when Visual Studio loses // and gains focus again. These may be related bool result; var key = new CommandKey(oleCommandData.CommandGroup, oleCommandData.CommandId); if (_cachedQueryStatusMap.TryGetValue(key, out result)) { return result; } result = RunQueryStatusCore(oleCommandData); _cachedQueryStatusMap[key] = result; return result; }