protected override void BeforeAwake()
    {
        base.BeforeAwake();

        btnCmd    = new VoidCommand(btnCmd_CanExecute, btnCmd_Execute);
        sliderCmd = new FloatCommand(sliderCmd_CanExecute, sliderCmd_Execute);
    }
Esempio n. 2
0
        public void Validate_Void_ReurnsValidResult()
        {
            var voidCommand      = new VoidCommand();
            var validationResult = voidCommand.Validate();

            Assert.Equal(CommandValidationResult.Valid, validationResult);
        }
        public TextFileViewModel()
        {
            this.TextFile = new TextFile();

            this.NewCommand  = new VoidCommand(New);
            this.OpenCommand = new VoidCommand(Open);
            this.SaveCommand = new VoidCommand(Save);
            this.ExitCommand = new VoidCommand(Exit);
        }
Esempio n. 4
0
        public async Task ExecuteAsync_ValidParameters_ReturnsVoidResult()
        {
            var beforCommandCreated = DateTime.Now;
            var voidCommand         = new VoidCommand();
            var afterCommandCreated = DateTime.Now;

            voidCommand.SetParameters(null, null, null);
            var result = await voidCommand.ExecuteAsync();

            Assert.Equal("void command", result.Content.ContentAsString());
            Assert.Equal(DocumentViewType.Warning, result.Type);
            Assert.Null(voidCommand.Subject);
            Assert.Null(voidCommand.Modifiers);
            Assert.Null(voidCommand.CommandText);
            Assert.True(voidCommand.CreationDate >= beforCommandCreated && voidCommand.CreationDate <= afterCommandCreated);
        }
Esempio n. 5
0
 protected override void BeforeAwake()
 {
     base.BeforeAwake();
     btnCmd     = new VoidCommand(null, btnCmd_Execute);
     itemBtnCmd = new VoidCommand(null, itemBtnCmd_Execute);
 }
Esempio n. 6
0
 public abstract void Visit(VoidCommand command);
 protected override void BeforeAwake()
 {
     base.BeforeAwake();
     testCmd = new VoidCommand(null, testCmd_Execute);
 }
Esempio n. 8
0
        public static ICommand GenerateCommandWithLuaTable(LuaTable vmTable, LuaTable cmdLua)
        {
            XLuaCommandCanExecuteHandler commandCanExecute  = cmdLua.Get <XLuaCommandCanExecuteHandler>("can_execute");
            Func <object, bool>          canExecuteDelegate = delegate(object parameter)
            {
                if (commandCanExecute == null)
                {
                    return(true);
                }
                else
                {
                    return(commandCanExecute.Invoke(vmTable, parameter));
                }
            };

            ICommand        command     = null;
            XLuaCommandType commandType = cmdLua.Get <XLuaCommandType>("type");

            switch (commandType)
            {
            case XLuaCommandType.Void:
                XLuaCommandExecuteHandler commandExecute = cmdLua.Get <XLuaCommandExecuteHandler>("execute");
                command = new VoidCommand(
                    canExecuteDelegate,
                    delegate(object parameter)
                {
                    if (commandExecute != null)
                    {
                        commandExecute.Invoke(vmTable, parameter);
                    }
                }
                    );
                break;

            case XLuaCommandType.Bool:
                XLuaCommandExecuteHandler <bool> boolCommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <bool> >("execute");
                command = new BoolCommand(
                    canExecuteDelegate,
                    delegate(bool v, object parameter)
                {
                    if (boolCommandExecute != null)
                    {
                        boolCommandExecute.Invoke(vmTable, v, parameter);
                    }
                }
                    );
                break;

            case XLuaCommandType.Float:
                XLuaCommandExecuteHandler <float> floatCommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <float> >("execute");
                command = new FloatCommand(
                    canExecuteDelegate,
                    delegate(float v, object parameter)
                {
                    if (floatCommandExecute != null)
                    {
                        floatCommandExecute.Invoke(vmTable, v, parameter);
                    }
                }
                    );
                break;

            case XLuaCommandType.Int:
                XLuaCommandExecuteHandler <int> intCommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <int> >("execute");
                command = new IntCommand(
                    canExecuteDelegate,
                    delegate(int v, object parameter)
                {
                    if (intCommandExecute != null)
                    {
                        intCommandExecute.Invoke(vmTable, v, parameter);
                    }
                }
                    );
                break;

            case XLuaCommandType.String:
                XLuaCommandExecuteHandler <string> stringCommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <string> >("execute");
                command = new StringCommand(
                    canExecuteDelegate,
                    delegate(string v, object parameter)
                {
                    if (stringCommandExecute != null)
                    {
                        stringCommandExecute.Invoke(vmTable, v, parameter);
                    }
                }
                    );
                break;

            case XLuaCommandType.Vector2:
                XLuaCommandExecuteHandler <Vector2> vector2CommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <Vector2> >("execute");
                command = new Vector2Command(
                    canExecuteDelegate,
                    delegate(Vector2 v, object parameter)
                {
                    if (vector2CommandExecute != null)
                    {
                        vector2CommandExecute.Invoke(vmTable, v, parameter);
                    }
                }
                    );
                break;
            }

            return(command);
        }
            public override void Visit(VoidCommand command)
            {
                var p = command.Nd;

                Console.WriteLine($"Void <{p.X},{p.Y},{p.Z}>");
            }
Esempio n. 10
0
        public async Task <IList <string> > Handle(VoidCommand command, CancellationToken cancellationToken)
        {
            var paymentTransaction = command.PaymentTransaction;

            if (paymentTransaction == null)
            {
                throw new ArgumentNullException(nameof(command.PaymentTransaction));
            }

            var canVoid = await _mediator.Send(new CanVoidQuery()
            {
                PaymentTransaction = paymentTransaction
            });

            if (!canVoid)
            {
                throw new GrandException("Cannot do void for order.");
            }

            VoidPaymentResult result = null;

            try
            {
                result = await _paymentService.Void(paymentTransaction);

                //event notification
                await _mediator.VoidPaymentTransactionDetailsEvent(result, paymentTransaction);

                if (result.Success)
                {
                    //update order info
                    paymentTransaction.TransactionStatus = result.NewTransactionStatus;
                    await _paymentTransactionService.UpdatePaymentTransaction(paymentTransaction);

                    var order = await _orderService.GetOrderByGuid(paymentTransaction.OrderGuid);

                    if (order == null)
                    {
                        throw new ArgumentNullException(nameof(order));
                    }

                    if (paymentTransaction.TransactionStatus == Domain.Payments.TransactionStatus.Voided)
                    {
                        order.PaymentStatusId = Domain.Payments.PaymentStatus.Voided;
                        await _orderService.UpdateOrder(order);

                        //check order status
                        await _mediator.Send(new CheckOrderStatusCommand()
                        {
                            Order = order
                        });
                    }
                }
            }
            catch (Exception exc)
            {
                if (result == null)
                {
                    result = new VoidPaymentResult();
                }
                result.AddError(string.Format("Error: {0}. Full exception: {1}", exc.Message, exc.ToString()));
            }

            //process errors
            string error = "";

            for (int i = 0; i < result.Errors.Count; i++)
            {
                error += string.Format("Error {0}: {1}", i, result.Errors[i]);
                if (i != result.Errors.Count - 1)
                {
                    error += ". ";
                }
            }
            if (!String.IsNullOrEmpty(error))
            {
                string logError = string.Format("Error voiding order #{0}. Error: {1}", paymentTransaction.OrderCode, error);
                await _logger.InsertLog(LogLevel.Error, logError, logError);
            }
            return(result.Errors);
        }
Esempio n. 11
0
 public virtual T Visit(VoidCommand command)
 {
     return(default(T));
 }