示例#1
0
        protected override bool HandleMessage(string message)
        {
            string  errorMessage = null;
            Message msg          = null;

            try
            {
                msg = new Message(message);
            }
            catch (Exception ex)
            {
                errorMessage = string.Format("Couldn't construct message: {0}", ex.Message);
                logger.Warn(errorMessage);
                Send(Commands.ReportError((int)Commands.ErrorCode.INVALID_CMD, errorMessage));
                return(false);
            }

            BoundCommand command = Commands.ExecutorParser.ParseMessage(msg, out errorMessage);

            if (command == null)
            {
                logger.Warn("Did not accept the message: {0}", message);
                Send(Commands.ReportError((int)Commands.ErrorCode.INVALID_CMD, errorMessage));
                return(false);
            }

            command.InvokeHandler(this, new ExecutorCommandEventArgs {
                Command = command
            });

            return(true);
        }
        public static CommandBindingManager RegisterCommand(this CommandBindingManager cmdBindingManager,
                                                            BoundCommand command, object sourceObject, string sourceEvent = "Click")
        {
            var commandBinding = new CommandBinding(command, sourceObject, sourceEvent);

            cmdBindingManager.CommandBindings.Add(commandBinding);
            return(cmdBindingManager);
        }
        public static CommandBindingManager RegisterCommand(this CommandBindingManager cmdBindingManager,
                                                            object source, Action <object> execute, Func <object, bool> canExecute, string sourceEvent = "Click")
        {
            var command        = new BoundCommand(execute, canExecute, null);
            var commandBinding = new CommandBinding(command, source, sourceEvent);

            cmdBindingManager.CommandBindings.Add(commandBinding);
            return(cmdBindingManager);
        }
示例#4
0
        //  private PathManager _pathManagerEx;//= new PathManager();

        public MainFormViewModel()
        {
            //    _pathManagerEx = pm;

            //AddEntryCommand = new BoundCommand(AddEntryAction, o=>true, null);

            //RemoveEntryCommand = new BoundCommand(RemoveEntryAction, o => true, null);
            ExportCommand   = new BoundCommand(ExportyAction, o => true, null);
            PathTextCommand = new BoundCommand(PathTextAction, o => true, null);
            // RefreshCommand = new BoundCommand(RefreshAction, o => true, null);
        }
        public AddPathViewModel()
        {
            InstalledPrograms = new List <string>();
            InstalledAppsInfo = new List <ProgramInfo>();
            InstalledAppsInfo = GetInstalledApps();
            foreach (var item in InstalledAppsInfo)
            {
                InstalledPrograms.Add(item.InstallLocation);
            }

            BrowseCommand = new BoundCommand(BrowseAction, CanBrowse, null);
        }
示例#6
0
        public static OleMenuCommand BindCommand(
            this IMenuCommandService service,
            CommandID id,
            ICommand command,
            bool hideWhenDisabled = false)
        {
            Validate.IsNotNull(service, nameof(service));
            Validate.IsNotNull(id, nameof(id));
            Validate.IsNotNull(command, nameof(command));

            var bound = new BoundCommand(id, command, hideWhenDisabled);

            service.AddCommand(bound);
            return(bound);
        }
示例#7
0
        public void BindFromBoundCommand(BoundCommand command)
        {
            if (command.shortKey)
            {
                HaEInputHandler.HaEKeyCombination keyCombination = new HaEInputHandler.HaEKeyCombination(command.key, command.modifier, command.modifier2, HaEConstants.quarterSecTimeOut, command.Execute);
                HaEPluginCore.HaEInputHandler.AddCombination(keyCombination);

                command.keyCombo = keyCombination;
            }
            else
            {
                HaEConsoleCommand consoleCommand = new HaEConsoleCommand(command.bindingName, x => { command.Execute(x); return(""); });
                consoleCommand.hidden = true;
                HaEConsole.Instance.RegisterCommand(consoleCommand);
            }
        }
示例#8
0
        public string AddBinding(List <string> args)
        {
            if (args.Count < 5)
            {
                return("not enough arguments!");
            }

            List <BoundCommand> commands     = configurationWriter.BoundCommands;
            BoundCommand        boundCommand = new BoundCommand();

            boundCommand.bindingName = args[0];
            boundCommand.Command     = args[4];
            boundCommand.shortKey    = true;

            MyKeys key;

            if (!Enum.TryParse(args[1], out key))
            {
                return("Could not parse key!");
            }
            boundCommand.key = key;

            MyKeys modifier;

            if (!Enum.TryParse(args[2], out modifier))
            {
                return("Could not parse modifier!");
            }
            boundCommand.modifier = modifier;

            MyKeys modifier2;

            if (!Enum.TryParse(args[3], out modifier2))
            {
                return("Could not parse modifier2!");
            }
            boundCommand.modifier2 = modifier2;

            commands.Add(boundCommand);
            BindFromBoundCommand(boundCommand);
            Save();
            return("Binding Added!");
        }
示例#9
0
        public string Alias(List <string> args)
        {
            if (args.Count < 2)
            {
                return("not enough arguments!");
            }

            List <BoundCommand> commands     = configurationWriter.BoundCommands;
            BoundCommand        boundCommand = new BoundCommand();

            boundCommand.bindingName = args[0];
            boundCommand.Command     = args[1];
            boundCommand.shortKey    = false;

            commands.Add(boundCommand);
            BindFromBoundCommand(boundCommand);
            Save();
            return("Alias Added!");
        }
示例#10
0
        private bool HandleMessage(Server.ClientContext context, string message)
        {
            string  errorMessage = null;
            Message msg          = null;

            try
            {
                msg = new Message(message);
            }
            catch (Exception ex)
            {
                errorMessage = string.Format("Couldn't construct message: {0}", ex.Message);
                logger.Warn(errorMessage);
                Send(context, Commands.ReportError((int)Commands.ErrorCode.INVALID_CMD, errorMessage));
                return(false);
            }

            BoundCommand command = Commands.ServerParser.ParseMessage(msg, out errorMessage);

            if (command == null)
            {
                logger.Warn("Did not accept the message: {0}", message);
                Send(context, Commands.ReportError((int)Commands.ErrorCode.INVALID_CMD, errorMessage));
                return(false);
            }

            // Requires authentication?
            if (command.RequiresAuth && !IsRegistered(context))
            {
                //	errorMessage = "Not authorized";
                return(false);
            }

            command.InvokeHandler(this, new ServerCommandEventArgs {
                Context = context, Command = command
            });

            return(true);
        }
示例#11
0
        private void OnLoad(object sender, EventArgs eventArgs)
        {
            try
            {
                var commandBindingManager = new CommandBindingManager();
                var commandBinding        = new CommandBinding();
                _saveCommandButton          = new BoundCommand(SaveMessage, CanSave, "Button");
                commandBinding.SourceObject = Save;
                commandBinding.SourceEvent  = ControlEvent.Click.ToString();
                commandBinding.Command      = _saveCommandButton;
                commandBindingManager.CommandBindings.Add(commandBinding);
                _saveCommandToolStrip = new BoundCommand(SaveMessage, CanSave, "ToolStrip");
                commandBindingManager.CommandBindings.Add(new CommandBinding(_saveCommandToolStrip, Tool, ToolStripItemEvent.Click.ToString()));
                _closeComamand = new BoundCommand(Close, CanClose, null);
                commandBindingManager.CommandBindings.Add(new CommandBinding(_closeComamand, CloseForm, ControlEvent.Click.ToString()));

                var bindingManager = new BindingManager();
                bindingManager.Bindings.Add(new TypedBinding <MainForm, TextBox>(this, t => t.FullNameText, FullName, s => s.Text));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
示例#12
0
        private static void GetCommands([NotNull] List <BoundCommand> boundCommands, [NotNull] Dictionary <ShellMenuCommandPlacement, List <UnboundCommand> > unboundCommands)
        {
            Debug.ArgumentNotNull(boundCommands, nameof(boundCommands));
            Debug.ArgumentNotNull(unboundCommands, nameof(unboundCommands));

            var commands = CommandManager.Commands;

            foreach (var command in commands)
            {
                var attributes = command.GetType().GetCustomAttributes(typeof(CommandIdAttribute), true);

                foreach (CommandIdAttribute attribute in attributes)
                {
                    var commandId = attribute.CommandId;

                    if (boundCommands.Any(c => c.CommandId == commandId))
                    {
                        continue;
                    }

                    ICommand wrapper = null;

                    if (attribute.ExpectedCommandContext.Equals(typeof(ContentEditorContext)))
                    {
                        wrapper = new ContentEditorMenuCommand(command);
                    }
                    else if (attribute.ExpectedCommandContext.Equals(typeof(ContentTreeContext)))
                    {
                        wrapper = new ContentTreeMenuCommand(command);
                    }

                    if (wrapper == null)
                    {
                        continue;
                    }

                    var cmd = new BoundCommand
                    {
                        Command   = wrapper,
                        CommandId = commandId
                    };

                    boundCommands.Add(cmd);
                }

                attributes = command.GetType().GetCustomAttributes(typeof(ShellMenuCommandAttribute), true);

                foreach (ShellMenuCommandAttribute attribute in attributes)
                {
                    if (attribute.IsBound)
                    {
                        var cmd = new BoundCommand
                        {
                            Command   = command,
                            CommandId = attribute.CommandId
                        };

                        boundCommands.Add(cmd);
                    }
                    else
                    {
                        var cmd = new UnboundCommand
                        {
                            Command  = command,
                            Priority = attribute.Priority
                        };

                        unboundCommands[attribute.Placement].Add(cmd);
                    }
                }
            }
        }