private bool CanCommandExecute(CommandConfig command) { if (command == null) { throw new ArgumentNullException("command"); } if (!Enabled && command.Actions[0].Type != "EnableCommandEngine" && command.Actions[0].Type != "Reload") { return(false); } if (command.Context != null) { switch (command.Context.Type) { case "Context": return(String.Equals(Context, command.Context["Value"], StringComparison.OrdinalIgnoreCase)); case "Process": { var process = WinApi.GetForegroundProcess(); var processName = process != null ? process.ProcessName : ""; return(string.Equals(processName, command.Context["Value"], StringComparison.OrdinalIgnoreCase)); } default: throw new IndexOutOfRangeException(command.Context.Type); } } return(true); }
private void ExecuteCommand(CommandConfig command, Dictionary <string, string> parameters) { if (command == null) { throw new ArgumentNullException("command"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } foreach (var action in command.Actions) { IAction iAction; if (!actions.TryGetValue(action.Type, out iAction)) { Console.WriteLine("Error: Unknown action type {0}", action.Type); continue; } iAction.Execute(this, action, parameters); } }