Exemplo n.º 1
0
        private void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            OrdersDiff diff = new OrdersDiff();

            if (_radnom.Probability(5))
            {
                Order addedOrder = _randomizer.AddRandomOrder(Orders);
                diff.AddedOrders.Add(addedOrder);
            }

            if (_radnom.Probability(1))
            {
                Order deletedorder = _randomizer.DeleteRandomOrder(Orders);
                diff.DeletedOrdersIds.Add(deletedorder.Id);
            }

            if (Orders.Count > 50)
            {
                while (Orders.Count > 25)
                {
                    Order deletedOrder = _randomizer.DeleteRandomOrder(Orders);
                    diff.DeletedOrdersIds.Add(deletedOrder.Id);
                }
            }

            Order updatedOrder = _randomizer.UpdateRandomOrder(Orders);

            diff.UpdatedOrders.Add(updatedOrder);

            OrdersChanged?.Invoke(this, new OrdersChangedEventArgs(diff));

            _ordersHub.SendDiffAsync(diff);
            _ordersHub.SendMessageAsync("Diff object was sent to you with love");
        }