예제 #1
0
        public void StartBatchJob_WithInfiniteItems_RunsMoreThanArbitraryTimes(int arbitraryRuns)
        {
            var batchSize = 1;

            BatchJobOptions options = new BatchJobOptions()
            {
                MaxItems    = -1,
                BatchSize   = batchSize,
                DelayInSecs = 0
            };

            BatchJob job = new BatchJob(options, Mock.Of <ILogger>());

            IOrderHandler handler = Mock.Of <IOrderHandler>();

            Mock.Get(handler).Setup(h => h.HandleBatch(batchSize)).Verifiable();

            // fire and forget since it is infinite thread
            job.Start(handler.HandleBatch).Wait(1000);

            // give time for iterations
            job.Stop();

            Mock.Get(handler).Verify((m) => m.HandleBatch(batchSize), Times.AtLeast(arbitraryRuns));
        }
예제 #2
0
 internal CommandReferences(Guid faction, Guid entity, IOrderHandler handler, ManagerSubPulse subPulse)
 {
     FactionGuid = faction;
     EntityGuid  = entity;
     Handler     = handler;
     _subPulse   = subPulse;
 }
예제 #3
0
        public void HandleOrder(IOrderHandler sender, Order order)
        {
            // If null, sender is this object otherwise the order has been redirected
            sender = sender ?? this;
            OthelloPlayerServer castedSender = sender as OthelloPlayerServer;

            switch (order)
            {
            case RegisterRequestOrder castedOrder:
                Register(castedSender);
                break;

            case SearchRequestOrder castedOrder:
                // Look for the sender
                Matchmake(castedSender, (PlayerType)castedOrder.OpponentType);
                break;

            case LoadRequestOrder castedOrder:
                RegisterGame(castedSender, castedOrder.SaveFile);
                break;

            case JoinRequestOrder castedOrder:
                JoinGame(castedSender, castedOrder.GameID);
                break;
            }
        }
예제 #4
0
 public TaskAsyncHandler(IOrderHandler handler)
 {
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     _handler = handler;
 }
예제 #5
0
        public bool Handle(Order order)
        {
            IOrderHandler handler = _handlers.Dequeue();

            handler.Handle(order);
            _handlers.Enqueue(handler);

            return(true);
        }
예제 #6
0
 public OrdersProducerController(
     IOrderHandler orderHandler,
     IBatchManager batchManager,
     ILogger <OrdersController> logger)
 {
     this.orderHandler = orderHandler;
     this.batchManager = batchManager;
     this.logger       = logger;
 }
예제 #7
0
        public OrderManager(IOrderHandler defaultHandler)
        {
            if (defaultHandler == null)
            {
                throw new NullReferenceException();
            }

            this._defaultHandler = defaultHandler;
        }
예제 #8
0
 public CommandLineConfig(
     ILogger <CommandLineConfig> logger,
     IShippingLabelHandler shippingLabelHandler,
     IOrderHandler orderHandler
     )
 {
     _logger = logger;
     _shippingLabelHandler = shippingLabelHandler;
     _orderHandler         = orderHandler;
 }
예제 #9
0
 public static IServiceCollection AddOrdersHandlerExecutor(this IServiceCollection serviceCollection)
 {
     return(serviceCollection.AddSingleton(x =>
     {
         var ordersHandlers = new IOrderHandler[]
         {
             new TalabatHandler(x.GetService <OrdersConverter>()),
             new ZomatoHandler(x.GetService <OrdersConverter>()),
             new UberHandler()
         };
         return new OrdersHandlerExecutor(ordersHandlers,
                                          x.GetService <OrdersRepositoryFactory>(), x.GetService <IErrorHandler>());
     }));
 }
예제 #10
0
 public RefiningVM(Game game, CommandReferences cmdRef, RefiningDB refiningDB)
 {
     _staticData   = game.StaticData;
     _refineDB     = refiningDB;
     _orderHandler = game.OrderHandler;
     _factionGuid  = refiningDB.OwningEntity.FactionOwner;
     _cmdRef       = cmdRef;
     foreach (var kvp in _staticData.CargoGoods.GetMaterials())
     {
         ItemDictionary.Add(kvp.Key, kvp.Value.Name);
     }
     ItemDictionary.SelectedIndex = 0;
     NewJobBatchCount             = 1;
     NewJobRepeat = false;
 }
        public void Handle(T message)
        {
            while (true)
            {
                IOrderHandler <T> nextValidHander =
                    GetNextAvailableHandler();

                if (nextValidHander != null)
                {
                    nextValidHander.Handle(message);
                    break;
                }

                Thread.Sleep(1);
            }
        }
예제 #12
0
        /// <summary>
        /// Handle received orders
        /// </summary>
        /// <param name="order"></param>
        public void HandleOrder(IOrderHandler sender, Order order)
        {
            // If null, sender is this object otherwise the order has been redirected
            sender = sender ?? this;

            switch (order)
            {
                #region Forwarded orders

                #region To GameHandler
            case AvatarChangedOrder a:
            case PlayerReadyOrder b:
            case PlayMoveOrder c:
            case UndoRequestOrder d:
            case RedoRequestOrder e:
            case SaveRequestOrder f:
                orderHandler.HandleOrder(sender, order);
                break;

                #endregion

                #region To Matchmaker
            case RegisterRequestOrder castedOrder:
                Name       = !string.IsNullOrEmpty(castedOrder.Name) ? castedOrder.Name : throw new ArgumentException("name can't be null or empty");
                PlayerType = (PlayerType)castedOrder.PlayerType;

                Console.WriteLine("Send registerRequest to matchmaker");
                orderHandler.HandleOrder(this, order);
                break;

            case JoinRequestOrder castedOrder:
                orderHandler.HandleOrder(this, order);
                break;

            case SearchRequestOrder castedOrder:
                orderHandler.HandleOrder(this, order);
                break;

            case LoadRequestOrder castedOrder:
                orderHandler.HandleOrder(this, order);
                break;

                #endregion

                #endregion
            }
        }
예제 #13
0
        protected void Subscribe <T>(string topic, IOrderHandler <T> handler)
        {
            var subscribers = new Dictionary <string, List <object> >(_subscribers);

            if (subscribers.ContainsKey(topic))
            {
                subscribers[topic].Add(handler);
            }
            else
            {
                subscribers.Add(topic, new List <object>()
                {
                    handler
                });
            }

            lock (_lock)
            {
                _subscribers = subscribers;
            }
        }
예제 #14
0
        public async Task StartBatchJob_WithMaxItemsAndBatchSize_RunsAppropriateNumberOfTimes(int maxItems, int batchSize)
        {
            var expectedIterations = (maxItems / batchSize) + (maxItems % batchSize == 0 ? 0 : 1);

            BatchJobOptions options = new BatchJobOptions()
            {
                MaxItems    = maxItems,
                BatchSize   = batchSize,
                DelayInSecs = 0
            };

            BatchJob job = new BatchJob(options, Mock.Of <ILogger>());

            IOrderHandler handler = Mock.Of <IOrderHandler>();

            Mock.Get(handler).Setup(h => h.HandleBatch(It.IsAny <int>())).Verifiable();

            await job.Start(handler.HandleBatch);

            Mock.Get(handler).Verify((m) => m.HandleBatch(It.IsAny <int>()), Times.Exactly(expectedIterations));
        }
예제 #15
0
        public override void HandleOrder(IOrderHandler sender, Order handledOrder)
        {
            lock (stateMutex)
            {
                switch (handledOrder)
                {
                case RegisterSuccessfulOrder order:
                    player1.SearchOpponent(player2.PlayerType);
                    orderHandler.HandleOrder(sender, order);
                    break;

                case OpponentFoundOrder order:
                    OpponentFoundOrder opponentFoundOrder = order;
                    player2.Name = opponentFoundOrder.OpponentName;
                    orderHandler.HandleOrder(sender, order);
                    break;

                case GameReadyOrder order:
                    orderHandler.HandleOrder(sender, order);
                    break;

                case GameStartedOrder order:
                    orderHandler.HandleOrder(sender, order);
                    break;

                case OpponentAvatarChangedOrder order:
                    player2.AvatarId = order.AvatarID;
                    orderHandler.HandleOrder(sender, order);
                    break;

                case UpdateGameStateOrder order:
                    orderHandler.HandleOrder(sender, order);
                    break;

                case GameEndedOrder order:
                    orderHandler.HandleOrder(sender, order);
                    break;
                }
            }
        }
예제 #16
0
 public void SetOrderHandler(IOrderHandler orderHandler)
 {
     this.orderHandler = orderHandler;
 }
예제 #17
0
 public OrderEngine(IOrderHandler orderHandlerChain)
 {
     this.orderHandlerChain = orderHandlerChain;
 }
예제 #18
0
 public void HandleOrder(IOrderHandler sender, Order order)
 {
     orderReceived.Enqueue(order);
 }
예제 #19
0
 public void SetOrderHandler(IOrderHandler handler)
 {
     throw new NotImplementedException("[SetOrderHandler] : ApplicationManager");
 }
예제 #20
0
 public ShipmentController(IOrderHandler orderHandler, IProductRepository repository)
 {
     _orderHandler = orderHandler;
     _productRepository = repository;
 }
예제 #21
0
 public TaskAsyncHandler(IOrderHandler handler)
 {
     if (handler == null) throw new ArgumentNullException("handler");
     _handler = handler;
 }
예제 #22
0
        public override void HandleOrder(IOrderHandler sender, Order handledOrder)
        {
            lock (stateMutex)
            {
                switch (handledOrder)
                {
                case RegisterSuccessfulOrder order:
                    if (!load)
                    {
                        if (player1.PlayerState == player2.PlayerState && player2.PlayerState == PlayerState.REGISTERED)
                        {
                            player1.SearchOpponent(player2.PlayerType);
                            player2.SearchOpponent(player1.PlayerType);
                        }
                    }
                    else
                    {
                        if (player1.PlayerState == PlayerState.REGISTERED)
                        {
                            player1.Load();
                        }
                        else if (player2.PlayerState == PlayerState.REGISTERED)
                        {
                            player2.JoinGame(loadedGameID);
                        }
                        else
                        {
                            Console.Error.WriteLine("[LocalGameHandler] - Can't load a game");
                        }
                    }
                    orderHandler.HandleOrder(sender, order);
                    break;

                case OpponentFoundOrder order:
                    if (player1.PlayerState == player2.PlayerState && player1.PlayerState == PlayerState.BINDED)
                    {
                        orderHandler.HandleOrder(sender, order);
                    }
                    break;

                case GameReadyOrder order:
                    readyToNextState++;
                    if (player1.PlayerState == player2.PlayerState && player1.PlayerState == PlayerState.LOBBY_CHOICE && readyToNextState == 2)
                    {
                        readyToNextState = 0;
                        orderHandler.HandleOrder(sender, order);
                    }
                    break;

                case GameStartedOrder order:
                    if (player1.PlayerState == PlayerState.MY_TURN && player2.PlayerState == PlayerState.OPPONENT_TURN ||
                        player1.PlayerState == PlayerState.OPPONENT_TURN && player2.PlayerState == PlayerState.MY_TURN)
                    {
                        orderHandler.HandleOrder(sender, order);
                    }
                    break;

                case UpdateGameStateOrder order:
                    orderHandler.HandleOrder(sender, order);
                    break;

                case GameEndedOrder order:
                    if (duplicatedGameEnded)
                    {
                        orderHandler.HandleOrder(sender, order);
                    }
                    duplicatedGameEnded = !duplicatedGameEnded;
                    break;

                case SaveResponseOrder order:
                    orderHandler.HandleOrder(sender, order);
                    break;

                case LoadResponseOrder order:
                    loadedGameID = order.GameID;
                    orderHandler.HandleOrder(sender, order);
                    break;

                case OpponentAvatarChangedOrder order:
                    // Nothing -> no need to update imagePlayer in local game
                    break;
                }
            }
        }
예제 #23
0
        public void Subscribe <T>(IOrderHandler <T> handler)
        {
            string topic = typeof(T).Name;

            Subscribe(topic, handler);
        }
예제 #24
0
 public void SetOrderHandler(IOrderHandler handler)
 {
     throw new Exception("This object can not receive an handler");
 }
예제 #25
0
 public void AddHandler(IOrderHandler handler)
 {
     this._handlers.Add(handler);
 }
예제 #26
0
        public void HandleOrder(IOrderHandler sender, Order order)
        {
            // If null, sender is this object otherwise the order has been redirected
            sender = sender ?? this;

            switch (order)
            {
            case PlayMoveOrder castedOrder:
                // Place a token on the board
                GameManager.PlayMove(castedOrder.Coords, (sender as OthelloPlayerServer).Color);

                // Send gameBoard to clients
                BroadcastGameboard();
                break;

            case GameStateRequestOrder castedOrder:
                // A client asked for the gameState, send it back to him
                (sender as OthelloPlayerServer).UpdateGameboard(GameManager.Export());
                break;

            case AvatarChangedOrder castedOrder:
                OthelloPlayerServer opponent = GetOpponent((sender as OthelloPlayerServer));
                opponent.OpponentAvatarChanged(castedOrder.AvatarID);
                break;

            case SaveRequestOrder castedOrder:
                // Send the saved game
                (sender as OthelloPlayerServer).SaveSuccessful(GameManager.Save());
                break;

            case UndoRequestOrder castedOrder:
                try
                {
                    // Goes one step back
                    GameManager.MoveBack();

                    // Goes back one more if the battle is against an IA
                    if (BattleType == BattleType.AgainstAI)
                    {
                        GameManager.MoveBack();
                    }

                    // Send gameboard
                    BroadcastGameboard();
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Undo not available");
                    Toolbox.LogError(ex);
                }
                break;

            case RedoRequestOrder castedOrder:
                try
                {
                    // Goes one step forward
                    GameManager.MoveForward();

                    // Goes forward one more if the battle is against an IA
                    if (BattleType == BattleType.AgainstAI)
                    {
                        GameManager.MoveForward();
                    }

                    // Send gameboard
                    BroadcastGameboard();
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Redo not available");
                    Toolbox.LogError(ex);
                }
                break;

            case PlayerReadyOrder castedOrder:
                lock (locker)
                {
                    var castedSender = (sender as OthelloPlayerServer);

                    if (castedSender.Color == Color.Black)
                    {
                        client1Ready = true;
                    }
                    else if (castedSender.Color == Color.White)
                    {
                        client2Ready = true;
                    }

                    if (client1Ready && client2Ready)
                    {
                        StartGame();
                    }
                }
                break;

            case Order unknownOrder:
                throw new Exception("Unknown order received !");
            }
        }
 public TimeToLiveHandler(IOrderHandler <T> handler)
 {
     _handler = handler;
 }
예제 #28
0
 public async Task <IOrderHandler> SetNext(IOrderHandler handler)
 {
     this._nextHandler = handler;
     return(_nextHandler);
 }
 public OrderController(IOrderHandler orderHandler)
 {
     this.orderHandler = orderHandler;
 }
예제 #30
0
 public Service()
 {
     _errorHandler = new ErrorHandlerByFile("Log.txt");
     _orderHandler = new OrderHandler();
     _repository   = new SqlRepository();
 }
예제 #31
0
 public CargoOrdersVM(Game game)
 {
     _orderHandler = game.OrderHandler;
 }
 public virtual IOrderHandler setNext(IOrderHandler handler)
 {
     this.nextHandler = handler;
     return(handler);
 }