Ejemplo n.º 1
0
        private RootAction ParseInput(string input)
        {
            // command example: "attack 1 3"
            // scheme: "<COMMAND_NAME> <?ARG_1> <?ARG_2> ... <?ARG_N>"
            // ? means optional parametr

            Dictionary <string, ActionType> commandsMap = new Dictionary <string, ActionType>()
            {
                { "attack", ActionType.Attack },
                { "heal", ActionType.Heal },
                { "play", ActionType.PlayCard },
                { "end", ActionType.EndTurn }
                // ect...
            };

            string[] chunks      = input.Split(' ');
            string   commandName = chunks[0];

            if (!commandsMap.ContainsKey(commandName))
            {
                throw new ArgumentException("Command name is not listed in commandsMap");
            }

            ActionType actionType = commandsMap[commandName];

            int[] args = chunks.Skip(1).Select(s => int.Parse(s)).ToArray();

            RootAction rootAction = ActionSet.PackAction(state, actionType, args);


            return(rootAction);
        }
        private ValidationResult ReadyToCreateMemo(RootAction rootActions)
        {
            var validation = new Validation <RootAction>()
                             .Add(x => x.HasPendingOrderActions, "Cannot create Memos until Order is synced")
                             .Add(x => x.HasPendingOrderActions, "Cannot create Memos until Payments/Refunds are synced");

            return(validation.Run(rootActions));
        }
Ejemplo n.º 3
0
        private ValidationResult ReadyToCreateMemo(RootAction rootActions)
        {
            var validation = new Validation <RootAction>()
                             .Add(x => !x.HasPendingOrderActions, "Cannot create Memo until Order is synced")
                             .Add(x => !x.HasPendingPaymentActions, "Cannot create Memo until Payments are synced and/or Released")
                             .Add(x => !x.HasPendingRefundActions, "Cannot create Memo until Refund(s) are synced and/or Released");

            return(validation.Run(rootActions));
        }
Ejemplo n.º 4
0
        public void Validate(RootAction rootAction, AdjustmentAction adjustmentAction)
        {
            adjustmentAction.Validation = new ValidationResult();

            if (adjustmentAction.ActionCode == ActionCode.CreateInAcumatica)
            {
                adjustmentAction.Validation = ReadyToCreateMemo(rootAction);
                return;
            }

            if (adjustmentAction.ActionCode == ActionCode.ReleaseInAcumatica)
            {
                adjustmentAction.Validation = ReadyToReleaseMemo(adjustmentAction);
                return;
            }
        }
Ejemplo n.º 5
0
        // TODO: add input json parsing (and create json configuration)
        public (ResponseType, string) ProcessInput(int playerIndex, string input)
        {
            try
            {
                if (playerIndex != state.CurrentPlayer.Id)
                {
                    throw new Exception("That's not your turn now");
                }

                RootAction action = ParseInput(input);
                state = GameLoop.Execute(state, action);
            }
            catch (Exception e)
            {
                return(ResponseType.Error, e.Message);
            }

            return(ResponseType.Success, "success");
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Ball on Chair!");

            // Wire up dependencies
            var ledgerService = new JsonBackedLedgerService(SystemClock.Instance, PersistenceDirectory);
            var playerService = new JsonBackedPlayerService(PersistenceDirectory);
            var roundService  = new JsonBackedRoundService(playerService, ledgerService, SystemClock.Instance, PersistenceDirectory);

            // Link Actions
            var exit = new ExitContainer();
            var autocompleteActions = new List <CliActionBase>
            {
                new AddPlayerAction(playerService),
                new RemovePlayerFromRoundAction(playerService, roundService, ledgerService),
                new CashOutPlayerAction(playerService, ledgerService),
                new CreditPlayerAction(playerService, ledgerService),
                new ViewPlayerAction(playerService, ledgerService, roundService),
                new RenamePlayerAction(playerService),
                new ListRoundsAction(roundService),
                new ViewRoundAction(roundService, playerService),
                new ListPlayersAction(playerService, ledgerService),
                new ListPositivePlayersAction(playerService, ledgerService),
                new ExitAction(exit),
                new StartRoundAction(roundService),
                new AddPlayerToRoundAction(playerService, roundService, ledgerService),
                new ListEntrantsRoundAction(roundService, playerService),
                new WinRoundAction(playerService, roundService)
            };

            var helpAction = new HelpAction(autocompleteActions);

            autocompleteActions.Add(helpAction);

            var rootCompletionContainer = new AutoCompletingCliActionsContainer(autocompleteActions);
            var rootCompletionProvider  = new TabCompletionProvider(rootCompletionContainer);

            // Run it
            var root = new RootAction(rootCompletionProvider, exit);

            root.Execute();
        }
Ejemplo n.º 7
0
        public void CanAddRootActionIfCaptureIsOn()
        {
            // given
            var configuration = new TestConfiguration();

            configuration.EnableCapture();

            var target = new Beacon(logger, new BeaconCache(),
                                    configuration, "127.0.0.1", threadIdProvider, timingProvider);
            const string RootActionName = "TestRootAction";


            // when adding the root action
            var action = new RootAction(logger, target, RootActionName, new SynchronizedQueue <IAction>()); // the action is added to the beacon in the constructor

            action.LeaveAction();

            // then
            Assert.That(target.ActionDataList, Is.EquivalentTo(new[] { $"et=1&na={RootActionName}&it=0&ca=1&pa=0&s0=1&t0=0&s1=2&t1=0" }));
        }
Ejemplo n.º 8
0
        public RootAction Create(ShopifyOrder orderRecord, bool validate = true)
        {
            var output = new RootAction();

            output.OrderAction            = BuildOrderPendingAction(orderRecord);
            output.PaymentAction          = BuildPaymentActions(orderRecord);
            output.RefundPaymentActions   = BuildRefundPaymentActions(orderRecord);
            output.AdjustmentMemoActions  = BuildRefundAdjustmentActions(orderRecord);
            output.ShipmentInvoiceActions = BuildShipmentInvoiceActions(orderRecord);

            output.ErrorCount        = orderRecord.ErrorCount;
            output.ExceedsErrorLimit = orderRecord.ExceedsErrorLimit();
            output.Ignore            = orderRecord.Ignore;


            if (validate)
            {
                _orderValidation.Validate(output.OrderAction);
                _paymentValidation.ValidatePayment(orderRecord, output.PaymentAction);

                foreach (var action in output.RefundPaymentActions)
                {
                    _paymentValidation.ValidateRefundPayment(orderRecord, action);
                }

                foreach (var action in output.ShipmentInvoiceActions)
                {
                    _fulfillmentStatusService.Validate(orderRecord, action);
                }

                foreach (var action in output.AdjustmentMemoActions)
                {
                    _memoValidationService.Validate(output, action);
                }
            }

            return(output);
        }
Ejemplo n.º 9
0
        // Implementation

        private void Compile(XPathNavigator stylesheet, XmlResolver resolver)
        {
            Debug.Assert(stylesheet != null);

            Compiler compiler = (Debugger == null) ? new Compiler() : new DbgCompiler(this.Debugger);
            NavigatorInput input = new NavigatorInput(stylesheet);
            compiler.Compile(input, resolver ?? XmlNullResolver.Singleton);

            Debug.Assert(compiler.CompiledStylesheet != null);
            Debug.Assert(compiler.QueryStore != null);
            Debug.Assert(compiler.QueryStore != null);
            _CompiledStylesheet = compiler.CompiledStylesheet;
            _QueryStore = compiler.QueryStore;
            _RootAction = compiler.RootAction;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Static method, that returns an Action
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static Action GetAction(XmlNode node)
        {
            if (node == null)
                return null;

            ActionType actionType;
            if (!Enum.TryParse(node.Name, true, out actionType))
                return null;

            var actionParams = new Dictionary<ActionParam, string>();
            if (node.Attributes != null)
            {
                foreach (var attr in node.Attributes)
                {
                    var xmlAttr = attr as XmlAttribute;
                    if (xmlAttr != null)
                    {
                        ActionParam param;
                        if (Enum.TryParse(xmlAttr.Name, true, out param))
                        {
                            actionParams.Add(param, xmlAttr.Value);
                        }
                    }
                }
            }

            Action action;

            switch (actionType)
            {
                case ActionType.Website:
                    action = new WebAction(actionParams);
                    break;

                case ActionType.RDC:
                    action = new RemoteDesktopAction(actionParams);
                    break;

                case ActionType.Dir:
                    action = new DirAction(actionParams);
                    break;

                case ActionType.Console:
                    action = new ConsoleAction(actionParams);
                    break;

                case ActionType.Exe:
                    action = new ExeAction(actionParams);
                    break;

                case ActionType.Email:
                    action = new EmailAction(actionParams);
                    break;

                case ActionType.Copy:
                    action = new CopyToClipboardAction(actionParams);
                    break;

                case ActionType.Alert:
                    action = new AlertAction(actionParams);
                    break;

                default:
                    action = new RootAction(actionParams);
                    break;
            }

            return action;
        }