private void AddObject(object state)
        {
            StrategyAdapter obj = CreateObject();

            InvokeAddItem(obj);
            InvokeAddLog(string.Format("Item added : {0}", obj));
            _objectAddTimer.Change(GetAddTimerDelay(), Timeout.Infinite);
        }
        internal void InsertManualItem(StrategyAdapter manualItem)
        {
            if (manualItem == null)
            {
                throw new ArgumentNullException("manualItem");
            }
            manualItem.SendTime = DateTime.Now;
            manualItem.IsManual = true;

            InvokeAddItem(manualItem.Clone());
            InvokeAddLog(string.Format("Item added : {0}", manualItem));
        }
 public void InvokeAddItem(StrategyAdapter obj)
 {
     lock (_sync)
     {
         _objectCache.Add(obj);
         Debug.WriteLine("Adding item");
         AddItemHandler handler = AddItem;
         if (handler != null)
         {
             handler(obj);
         }
     }
 }
 public void InvokeRemoveItem(StrategyAdapter obj)
 {
     lock (_sync)
     {
         _objectCache.Remove(obj);
         Debug.WriteLine("Removing item");
         RemoveItemHandler handler = RemoveItem;
         if (handler != null)
         {
             handler(obj);
         }
     }
 }
        private void ObjectPropertyChanged(object state)
        {
            lock (_sync)
            {
                List <StrategyAdapter> progressItems =
                    _objectCache.Where(p => p.StratStat == StrategyStatus.InProgress).ToList();

                var newStatus = (StrategyStatus)_random.Next(1, 4);

                int count = progressItems.Count();
                if (count > 0)
                {
                    _uiDispatcher.Invoke(new Action(delegate
                    {
                        int propChangedIndex = _random.Next(0,
                                                            count -
                                                            1);
                        Debug.WriteLine("Changing item properties");
                        StrategyAdapter changedItem =
                            progressItems[propChangedIndex];
                        InvokeAddLog(
                            string.Format("Item status changed from {0} to {1}",
                                          changedItem.StratStat, newStatus));
                        changedItem.StratStat = newStatus;
                        changedItem.Message   = "Status changed !";
                        if (newStatus == StrategyStatus.Done)
                        {
                            int sign01 = _random.Next(1, 2) == 1
                                                                                 ? -1
                                                                                 : 1;
                            int sign02 = _random.Next(1, 2) == 1
                                                                                 ? -1
                                                                                 : 1;
                            changedItem.ExecutedAmount =
                                changedItem.RequestedAmount +
                                (sign01 * _random.Next(1000, 50000));
                            changedItem.ExecutedPrice =
                                changedItem.RequestedPrice +
                                (sign02 *
                                 (decimal)_random.NextDouble());
                        }
                    }), null);
                }


                _objectPropertyChangedTimer.Change(GetPropertyChangedTimerDelay(), Timeout.Infinite);
            }
        }
        private StrategyAdapter CreateObject()
        {
            var a = new StrategyAdapter
            {
                SendTime        = DateTime.Now,
                StratStat       = StrategyStatus.InProgress,
                StratType       = GetStrategyTypeByRandomNumber(_random.Next(0, 3)),
                Dir             = GetDirectionByRandomNumber(_random.Next(0, 2)),
                Message         = "message " + _random.Next(0, 1000),
                Product         = GetProduct(_random.Next(0, 5)),
                ExecutedAmount  = 0,
                RequestedAmount = _random.Next(100000, 50000000),
                ExecutedPrice   = 0,
                RequestedPrice  = (decimal)_random.NextDouble() + _random.Next(0, 24),
                Markets         = GetMarkets(_random.Next(0, 5))
            };

            return(a);
        }
        private void RemoveObject(object state)
        {
            lock (_sync)
            {
                List <StrategyAdapter> nonProgressItems =
                    _objectCache.Where(p => p.StratStat != StrategyStatus.InProgress).ToList();

                int count = nonProgressItems.Count();
                if (count > 0)
                {
                    int removeIndex = _random.Next(0, count - 1);

                    StrategyAdapter objToRemove = nonProgressItems[removeIndex];
                    InvokeRemoveItem(objToRemove);
                    InvokeAddLog(string.Format("Item removed : {0}", objToRemove));
                }
                _objectRemoveTimer.Change(GetRemoveTimerDelay(), Timeout.Infinite);
            }
        }
        internal void InsertManualItem(StrategyAdapter manualItem)
        {
            if (manualItem == null) throw new ArgumentNullException("manualItem");
            manualItem.SendTime = DateTime.Now;
            manualItem.IsManual = true;

            InvokeAddItem(manualItem.Clone());
            InvokeAddLog(string.Format("Item added : {0}", manualItem));
        }
 void ItemsPoolerAddItem(StrategyAdapter obj)
 {
     _uiDispatcher.Invoke(new Action <StrategyAdapter>(AddItem), obj);
 }
 public void InvokeAddItem(StrategyAdapter obj)
 {
     lock (_sync)
     {
         _objectCache.Add(obj);
         Debug.WriteLine("Adding item");
         AddItemHandler handler = AddItem;
         if (handler != null) handler(obj);
     }
 }
 public void InvokeRemoveItem(StrategyAdapter obj)
 {
     lock (_sync)
     {
         _objectCache.Remove(obj);
         Debug.WriteLine("Removing item");
         RemoveItemHandler handler = RemoveItem;
         if (handler != null) handler(obj);
     }
 }
        void ItemsPoolerAddItem(StrategyAdapter obj)
        {

            _uiDispatcher.Invoke(new Action<StrategyAdapter>(AddItem), obj);
        }
 private void RemoveItem(StrategyAdapter obj)
 {
     RealTimeDataSourceStrategies.Remove(obj);
 }
 void AddItem(StrategyAdapter strategyAdapter)
 {
     RealTimeDataSourceStrategies.Add(strategyAdapter);
 }
 void AddItem(StrategyAdapter strategyAdapter)
 {
     RealTimeDataSourceStrategies.Add(strategyAdapter);
 }
 private StrategyAdapter CreateObject()
 {
     var a = new StrategyAdapter
                 {
                     SendTime = DateTime.Now,
                     StratStat = StrategyStatus.InProgress,
                     StratType = GetStrategyTypeByRandomNumber(_random.Next(0, 3)),
                     Dir = GetDirectionByRandomNumber(_random.Next(0, 2)),
                     Message = "message " + _random.Next(0, 1000),
                     Product = GetProduct(_random.Next(0, 5)),
                     ExecutedAmount = 0,
                     RequestedAmount = _random.Next(100000, 50000000),
                     ExecutedPrice = 0,
                     RequestedPrice = (decimal)_random.NextDouble() + _random.Next(0, 24),
                     Markets = GetMarkets(_random.Next(0, 5))
                 };
     return a;
 }
 private void RemoveItem(StrategyAdapter obj)
 {
     RealTimeDataSourceStrategies.Remove(obj);
 }