/// <summary>
        /// Constructor.
        /// </summary>
        public MBTradingOrders(BackgroundMessageLoopOperator messageLoopOperator)
        {
            _messageLoopOperator = messageLoopOperator;
            _operationStub = new OperationPerformerStub();

            ChangeOperationalState(OperationalStateEnum.Constructed);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public MBTradingConnectionManager(MBTradingAdapter adapter)
        {
            ChangeOperationalState(OperationalStateEnum.Constructed);

            _adapter = adapter;
            _messageLoopOperator = new BackgroundMessageLoopOperator(false);
            _quotes = new MBTradingQuote(_messageLoopOperator);
            _history = new MBTradingHistory(_messageLoopOperator);
            _orders = new MBTradingOrders(_messageLoopOperator);
        }
        //volatile MBTradingQuote _quotes;
        //public MBTradingQuote Quotes
        //{
        //    get { return _quotes; }
        //}
        //volatile MBTradingHistory _history;
        //public MBTradingHistory History
        //{
        //    get { return _history; }
        //}
        //volatile MBTradingOrders _orders;
        ///// <summary>
        ///// 
        ///// </summary>
        //public MBTradingOrders Orders
        //{
        //    get { return _orders; }
        //}
        //MBTradingAdapter _adapter;
        /// <summary>
        /// Constructor.
        /// </summary>
        public MBTradingTestConnectionManager()
        {
            ChangeOperationalState(OperationalStateEnum.Constructed);

            _messageLoopOperator = new BackgroundMessageLoopOperator(false);
            //_quotes = new MBTradingQuote(_messageLoopOperator);
            //_history = new MBTradingHistory(_messageLoopOperator);
            //_orders = new MBTradingOrders(_messageLoopOperator);

            _messageLoopOperator.Start();
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public FXCMConnectionManager(FXCMAdapter adapter)
        {
            ChangeOperationalState(OperationalStateEnum.Constructed);

            _subscriptionResponse = -1;
            _adapter = adapter;
            _messageLoopOperator = new BackgroundMessageLoopOperator(false);
            _orders = new FXCMOrders(_messageLoopOperator);

            _messageLoopOperator.Start();
        }
        public void Dispose()
        {
            if (_historyClient != null)
            {
                _historyClient.OnDataEvent -= new _IMbtHistEvents_OnDataEventEventHandler(_historyClient_OnDataEvent);
                _historyClient.OnError -= new _IMbtHistEvents_OnErrorEventHandler(_historyClient_OnError);
                _historyClient = null;
            }

            if (_messageLoopOperator != null)
            {
                _messageLoopOperator = null;
            }
        }
 public void Dispose()
 {
     UnInitialize();
     _messageLoopOperator = null;
 }
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            lock (this)
            {
                //if (_quotes != null)
                //{
                //    _quotes.Dispose();
                //    _quotes = null;
                //}

                //if (_history != null)
                //{
                //    _history.Dispose();
                //    _history = null;
                //}

                //if (_orders != null)
                //{
                //    _orders.UnInitialize();
                //    _orders.Dispose();
                //    _orders = null;
                //}

                //if (_adapter != null)
                //{
                //    _adapter = null;
                //}

                if (_communicationManager != null)
                {
                    //_communicationManager.OnLogonSucceed -= new IMbtComMgrEvents_OnLogonSucceedEventHandler(_communicationManager_OnLogonSucceed);
                    _communicationManager = null;

                }

                if (_messageLoopOperator != null)
                {
                    _messageLoopOperator.Stop();
                    _messageLoopOperator.Dispose();
                    _messageLoopOperator = null;
                }

                ChangeOperationalState(OperationalStateEnum.Disposed);
            }

            //GC.Collect();
        }
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            lock (this)
            {
                if (_orders != null)
                {
                    _orders.UnInitialize();
                    _orders.Dispose();
                    _orders = null;
                }

                if (_adapter != null)
                {
                    _adapter = null;
                }

                if (_core != null)
                {
                    _desk = null;
                    _core = null;
                }

                if (_messageLoopOperator != null)
                {
                    _messageLoopOperator.Stop();
                    _messageLoopOperator.Dispose();
                    _messageLoopOperator = null;
                }

                ChangeOperationalState(OperationalStateEnum.Disposed);
            }

            //GC.Collect();
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public MBTradingHistory(BackgroundMessageLoopOperator messageLoopOperator)
 {
     _messageLoopOperator = messageLoopOperator;
     _operationStub = new OperationPerformerStub(this);
 }
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            try
            {
                if (_quotesClient != null)
                {
                    _quotesClient.UnadviseAll(this);
                    _quotesClient = null;
                }
            }
            catch (Exception ex)
            {
                SystemMonitor.OperationError(ex.Message);
            }

            _messageLoopOperator = null;
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public MBTradingQuote(BackgroundMessageLoopOperator messageLoopOperator)
 {
     // Calls to the COM must be done in the requestMessage loop operator.
     _messageLoopOperator = messageLoopOperator;
 }
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            try
            {
                lock (this)
                {
                    if (_quotes != null)
                    {
                        _quotes.Dispose();
                        _quotes = null;
                    }

                    if (_history != null)
                    {
                        _history.Dispose();
                        _history = null;
                    }

                    if (_orders != null)
                    {
                        _orders.UnInitialize();
                        _orders.Dispose();
                        _orders = null;
                    }

                    if (_adapter != null)
                    {
                        _adapter = null;
                    }

                    if (_communicationManager != null)
                    {
                        _communicationManager.OnLogonSucceed -= new IMbtComMgrEvents_OnLogonSucceedEventHandler(_communicationManager_OnLogonSucceed);
                        _communicationManager = null;
                    }

                    if (_messageLoopOperator != null)
                    {
                        _messageLoopOperator.Stop();
                        _messageLoopOperator.Dispose();
                        _messageLoopOperator = null;
                    }

                    ChangeOperationalState(OperationalStateEnum.Disposed);
                }
            }
            catch (Exception ex)
            {
                SystemMonitor.OperationError(ex.Message);
            }

            //GC.Collect();
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public FXCMConnectionManager()
        {
            ChangeOperationalState(OperationalStateEnum.Constructed);

            _messageLoopOperator = new BackgroundMessageLoopOperator(false);
        }
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            ChangeOperationalState(OperationalStateEnum.Disposed);

            _desk = null;
            _core = null;
            _tradeDeskEventsSink = null;

            BackgroundMessageLoopOperator messageLoopOperator = _messageLoopOperator;
            if (messageLoopOperator != null)
            {
                messageLoopOperator.Stop();
                messageLoopOperator.Dispose();
            }

            _messageLoopOperator = null;

            GC.Collect();
        }