/// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool Login(string username, string password)
        {
            bool result = false;

            if (OperationalState == OperationalStateEnum.Disposed)
            {
                return(false);
            }

            _messageLoopOperator.Invoke(delegate()
            {
                // This is a slow blocking call, make sure to execute outside of lock.
                MbtComMgr manager     = new MbtComMgr();
                _communicationManager = manager;
                //_communicationManager.OnLogonSucceed += new IMbtComMgrEvents_OnLogonSucceedEventHandler(_communicationManager_OnLogonSucceed);

                _orderClient            = _communicationManager.OrderClient;
                _orderClient.SilentMode = true;

                //_quotes.Initialize(_communicationManager.Quotes);
                //_history.Initialize(_communicationManager.HistMgr);
                ///_orders.Initialize(_adapter, this, _communicationManager);

                //_communicationManager.OnAlertAdded += new IMbtComMgrEvents_OnAlertAddedEventHandler(_communicationManager_OnAlertAdded);
                _communicationManager.EnableSplash(false);

                ChangeOperationalState(OperationalStateEnum.Initialized);
                _communicationManager.EnableSplash(false);
                _communicationManager.SilentMode = true;

                result = _communicationManager.DoLogin(HostId, username, password, "");
            }, TimeSpan.FromSeconds(25));

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool Login(string username, string password)
        {
            bool result = false;

            if (OperationalState != OperationalStateEnum.Initialized &&
                OperationalState != OperationalStateEnum.Initializing &&
                OperationalState != OperationalStateEnum.Constructed)
            {
                return(false);
            }

            _messageLoopOperator.Start();

            _messageLoopOperator.Invoke(delegate()
            {
                try
                {
                    // *Never* subscribe to COM events of a property, always make sure to hold the object alive
                    // http://www.codeproject.com/Messages/2189754/Re-Losing-COM-events-handler-in-Csharp-client.aspx

                    if (_communicationManager == null)
                    {
                        // This is a slow blocking call, make sure to execute outside of lock.
                        MbtComMgr manager     = new MbtComMgr();
                        _communicationManager = manager;
                        _communicationManager.OnLogonSucceed += new IMbtComMgrEvents_OnLogonSucceedEventHandler(_communicationManager_OnLogonSucceed);
                    }

                    lock (this)
                    {
                        _quotes.Initialize(this, _communicationManager.Quotes);
                        _history.Initialize(_communicationManager.HistMgr);
                        _orders.Initialize(_adapter, this, _communicationManager);

                        _communicationManager.OnAlertAdded += new IMbtComMgrEvents_OnAlertAddedEventHandler(_communicationManager_OnAlertAdded);
                        _communicationManager.EnableSplash(false);
                    }

                    ChangeOperationalState(OperationalStateEnum.Initialized);
                    _communicationManager.EnableSplash(false);
                    _communicationManager.SilentMode = true;

                    result = _communicationManager.DoLogin(HostId, username, password, "");
                }
                catch (Exception ex)
                {
                    SystemMonitor.OperationError(ex.Message);
                    result = false;
                    throw;
                }
            }, TimeSpan.FromSeconds(25));

            return(result);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool Login(string username, string password)
        {
            bool result = false;

            if (OperationalState == OperationalStateEnum.Disposed)
            {
                return false;
            }

            _messageLoopOperator.Invoke(delegate()
            {
                // This is a slow blocking call, make sure to execute outside of lock.
                MbtComMgr manager = new MbtComMgr();
                _communicationManager = manager;
                //_communicationManager.OnLogonSucceed += new IMbtComMgrEvents_OnLogonSucceedEventHandler(_communicationManager_OnLogonSucceed);

                _orderClient = _communicationManager.OrderClient;
                _orderClient.SilentMode = true;

                //_quotes.Initialize(_communicationManager.Quotes);
                //_history.Initialize(_communicationManager.HistMgr);
                ///_orders.Initialize(_adapter, this, _communicationManager);

                //_communicationManager.OnAlertAdded += new IMbtComMgrEvents_OnAlertAddedEventHandler(_communicationManager_OnAlertAdded);
                _communicationManager.EnableSplash(false);

                ChangeOperationalState(OperationalStateEnum.Initialized);
                _communicationManager.EnableSplash(false);
                _communicationManager.SilentMode = true;

                result = _communicationManager.DoLogin(HostId, username, password, "");

            }, TimeSpan.FromSeconds(25));

            return result;
        }