Example #1
0
        /// <summary>Конструктор команды</summary>
        /// <param name="executeAction">Выполняемый метод команды</param>
        /// <param name="canExecuteAction">Метод разрешающий выполнение команды</param>
        public RelayCommandAction(ExecuteActionHandler execute, CanExecuteActionHandler canExecute = null)
        {
            this.execute    = ExecuteAction;
            this.canExecute = CanExecuteAction;

            executeAction    = execute ?? throw new ArgumentNullException(nameof(execute));
            canExecuteAction = canExecute ?? CanExecuteActionTrue;
        }
        /// <inheritdoc cref="WpfRelayCommand(ExecuteHandler,CanExecuteHandler,Dispatcher)"/>
        public WpfRelayCommandAction(ExecuteActionHandler execute, CanExecuteActionHandler canExecute = null, Dispatcher dispatcher = null)
            : base(null, null, dispatcher)
        {
            this.execute    = ExecuteAction;
            this.canExecute = CanExecuteAction;

            executeAction    = execute ?? throw new ArgumentNullException(nameof(execute));
            canExecuteAction = canExecute ?? CanExecuteActionTrue;
        }
Example #3
0
 /// <summary>Конструктор команды</summary>
 /// <param name="execute">Выполняемый метод команды</param>
 /// <param name="canExecute">Метод разрешающий выполнение команды</param>
 public RelayActionCommand(ExecuteActionHandler execute, CanExecuteActionHandler canExecute = null)
     : base(_ => execute(), _ => canExecute())
     => CanExecuteChanged += (s, e)
Example #4
0
 /// <summary>Конструктор команды</summary>
 /// <param name="execute">Выполняемый метод команды</param>
 /// <param name="canExecute">Метод разрешающий выполнение команды</param>
 public RelayActionCommand(ExecuteActionHandler execute, CanExecuteActionHandler canExecute = null)
     : base(_ => execute(), _ => canExecute())
 {
 }
Example #5
0
        //        public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, new EventArgs());

        public void Execute(object parameter)
        {
            ExecuteActionHandler?.Invoke(parameter);
        }
Example #6
0
        /// <summary>
        /// Fill the possible actions <see cref="Actions"/>
        /// </summary>
        static ExpressionGraph()
        {
            // Some helpers to make filling the Actions[][][] easier.
            var actions = new Dictionary <int, Dictionary <int, Dictionary <int, ExecuteActionHandler> > >();

            void AddAction(int groupId, int typeId, int methodId, ExecuteActionHandler action)
            {
                if (!actions.TryGetValue(groupId, out var groupActions))
                {
                    groupActions = new Dictionary <int, Dictionary <int, ExecuteActionHandler> >();
                    actions.Add(groupId, groupActions);
                }

                if (!groupActions.TryGetValue(typeId, out var typeActions))
                {
                    typeActions = new Dictionary <int, ExecuteActionHandler>();
                    groupActions.Add(typeId, typeActions);
                }

                typeActions.Add(methodId, action);
            }

            ExecuteActionHandler[][][] ActionsToArray()
            {
                var groupActionsCount = actions.Keys.Max() + 1;

                ExecuteActionHandler[][][] groupActions = new ExecuteActionHandler[groupActionsCount][][];

                foreach (var groupIdActions in actions)
                {
                    var typeActionsCount = groupIdActions.Value.Keys.Max() + 1;
                    ExecuteActionHandler[][] typeActions = new ExecuteActionHandler[typeActionsCount][];

                    foreach (var typeIdActions in groupIdActions.Value)
                    {
                        var methodActionsCount = typeIdActions.Value.Keys.Max() + 1;
                        ExecuteActionHandler[] methodActions = new ExecuteActionHandler[methodActionsCount];
                        foreach (var methodIdAction in typeIdActions.Value)
                        {
                            methodActions[methodIdAction.Key] = methodIdAction.Value;
                        }
                        typeActions[typeIdActions.Key] = methodActions;
                    }
                    groupActions[groupIdActions.Key] = typeActions;
                }

                return(groupActions);
            }

            // Main node
            AddAction(1, 1, 0, (_) => { });
            // Random float
            AddAction(1, 2, 0, (node) => { node.Return <float>(0, _rng.NextFloat()); });

            // Add
            AddAction(3, 1, 0, (node) => { node.Return <float>(0, node.InputAs <float>(0) + node.InputAs <float>(1)); });
            // Subtract
            AddAction(3, 2, 0, (node) => { node.Return <float>(0, node.InputAs <float>(0) - node.InputAs <float>(1)); });
            // Multiply
            AddAction(3, 3, 0, (node) => { node.Return <float>(0, node.InputAs <float>(0) * node.InputAs <float>(1)); });
            // Modulo
            AddAction(3, 4, 0, (node) => { node.Return <float>(0, node.InputAs <float>(0) % node.InputAs <float>(1)); });
            // Divide
            AddAction(3, 5, 0, (node) => { node.Return <float>(0, node.InputAs <float>(0) / node.InputAs <float>(1)); });
            // Absolute
            AddAction(3, 7, 0, (node) => { node.Return <float>(0, Mathf.Abs(node.InputAs <float>(0))); });
            // Ceil
            AddAction(3, 8, 0, (node) => { node.Return <float>(0, Mathf.Ceil(node.InputAs <float>(0))); });
            // Cosine
            AddAction(3, 9, 0, (node) => { node.Return <float>(0, Mathf.Cos(node.InputAs <float>(0))); });
            // Floor
            AddAction(3, 10, 0, (node) => { node.Return <float>(0, Mathf.Floor(node.InputAs <float>(0))); });
            // Round
            AddAction(3, 13, 0, (node) => { node.Return <float>(0, Mathf.Round(node.InputAs <float>(0))); });
            // Saturate
            AddAction(3, 14, 0, (node) => { node.Return <float>(0, Mathf.Saturate(node.InputAs <float>(0))); });
            // Sine
            AddAction(3, 15, 0, (node) => { node.Return <float>(0, Mathf.Sin(node.InputAs <float>(0))); });
            // Sqrt
            AddAction(3, 16, 0, (node) => { node.Return <float>(0, Mathf.Sqrt(node.InputAs <float>(0))); });
            // Tangent
            AddAction(3, 17, 0, (node) => { node.Return <float>(0, Mathf.Tan(node.InputAs <float>(0))); });

            // Power
            AddAction(3, 23, 0, (node) => { node.Return <float>(0, Mathf.Pow(node.InputAs <float>(0), node.InputAs <float>(1))); });

            // Parameter
            AddAction(6, 1, 0, (node) => { node.Return <object>(0, node.InputValues[0]); });

            Actions = ActionsToArray();
        }
 /// <inheritdoc cref="WpfRelayCommandAction(ExecuteActionHandler,CanExecuteActionHandler,Dispatcher)"/>
 public WpfRelayCommandAction(ExecuteActionHandler execute, Dispatcher dispatcher = null)
     : this(execute, null, dispatcher)
 {
 }