/// <summary>
        /// Perform a login.
        /// </summary>
        public bool Login(string username, string password, string serviceUrl, string accountType, out string operationResultMessage)
        {
            _messageLoopOperator.Start();

            if (OperationalState != OperationalStateEnum.Initialized &&
                OperationalState != OperationalStateEnum.Initializing &&
                OperationalState != OperationalStateEnum.Constructed)
            {
                operationResultMessage = "Login already started.";
                return(false);
            }

            this._serviceUrl = serviceUrl;

            string operationResultMessageCopy = string.Empty;

            ChangeOperationalState(OperationalStateEnum.Initializing);

            object result = false;

            GeneralHelper.GenericReturnDelegate <bool> del = delegate()
            {
                if (_core == null)
                {
                    _core = new FXCore.CoreAutClass();
                    _desk = (FXCore.TradeDeskAut)_core.CreateTradeDesk("trader");
                }

                try
                {
                    _desk.Login(username, password, serviceUrl, accountType);

                    Managed_Subscribe();

                    SystemMonitor.Report("FXCM Service subscribed.");
                    ChangeOperationalState(OperationalStateEnum.Operational);
                }
                catch (Exception exception)
                {
                    operationResultMessageCopy = "Failed to log in [" + exception.Message + "].";
                    SystemMonitor.OperationError(operationResultMessageCopy);
                    ChangeOperationalState(OperationalStateEnum.NotOperational);
                }

                return(_desk.IsLoggedIn());
            };

            if (_messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180), out result) == false || (bool)result == false)
            {
                ChangeOperationalState(OperationalStateEnum.NotOperational);
                operationResultMessage = operationResultMessageCopy;
                return(false);
            }

            operationResultMessage = operationResultMessageCopy;
            return((bool)result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool Login(string username, string password, string serviceUrl, string accountType)
        {
            if (OperationalState != OperationalStateEnum.Initialized &&
                OperationalState != OperationalStateEnum.Initializing &&
                OperationalState != OperationalStateEnum.Constructed)
            {
                return(false);
            }

            object result = false;

            GeneralHelper.GenericReturnDelegate <bool> del = delegate()
            {
                if (_core == null)
                {
                    _core = new FXCore.CoreAutClass();
                    _desk = (FXCore.TradeDeskAut)_core.CreateTradeDesk("trader");
                }

                lock (this)
                {
                    _orders.Initialize(_adapter, this);
                }

                ChangeOperationalState(OperationalStateEnum.Initializing);

                try
                {
                    _desk.Login(username, password, serviceUrl, accountType);
                    Subscribe();
                    ChangeOperationalState(OperationalStateEnum.Operational);
                }
                catch (Exception exception)
                {
                    SystemMonitor.OperationError("Failed to log in [" + exception.Message + "].");
                    ChangeOperationalState(OperationalStateEnum.NotOperational);
                }

                return(_desk.IsLoggedIn());
            };

            _messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180), out result);

            return((bool)result);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool Login(string username, string password, string serviceUrl, string accountType)
        {
            if (OperationalState != OperationalStateEnum.Initialized
                 && OperationalState != OperationalStateEnum.Initializing
                && OperationalState != OperationalStateEnum.Constructed)
            {
                return false;
            }

            object result = false;

            GeneralHelper.GenericReturnDelegate<bool> del = delegate()
            {
                if (_core == null)
                {
                    _core = new FXCore.CoreAutClass();
                    _desk = (FXCore.TradeDeskAut)_core.CreateTradeDesk("trader");
                }

                lock (this)
                {
                    _orders.Initialize(_adapter, this);
                }

                ChangeOperationalState(OperationalStateEnum.Initializing);

                try
                {
                    _desk.Login(username, password, serviceUrl, accountType);
                    Subscribe();
                    ChangeOperationalState(OperationalStateEnum.Operational);
                }
                catch (Exception exception)
                {
                    SystemMonitor.OperationError("Failed to log in [" + exception.Message + "].");
                    ChangeOperationalState(OperationalStateEnum.NotOperational);
                }

                return _desk.IsLoggedIn();
            };

            _messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180), out result);

            return (bool)result;
        }
        /// <summary>
        /// Perform a login.
        /// </summary>
        public bool Login(string username, string password, string serviceUrl, string accountType, out string operationResultMessage)
        {
            _messageLoopOperator.Start();

            if (OperationalState != OperationalStateEnum.Initialized
                 && OperationalState != OperationalStateEnum.Initializing
                && OperationalState != OperationalStateEnum.Constructed)
            {
                operationResultMessage = "Login already started.";
                return false;
            }

            this._serviceUrl = serviceUrl;

            string operationResultMessageCopy = string.Empty;

            ChangeOperationalState(OperationalStateEnum.Initializing);

            object result = false;
            GeneralHelper.GenericReturnDelegate<bool> del = delegate()
            {
                if (_core == null)
                {
                    _core = new FXCore.CoreAutClass();
                    _desk = (FXCore.TradeDeskAut)_core.CreateTradeDesk("trader");
                }

                try
                {
                    _desk.Login(username, password, serviceUrl, accountType);

                    Managed_Subscribe();

                    SystemMonitor.Report("FXCM Service subscribed.");
                    ChangeOperationalState(OperationalStateEnum.Operational);
                }
                catch (Exception exception)
                {
                    operationResultMessageCopy = "Failed to log in [" + exception.Message + "].";
                    SystemMonitor.OperationError(operationResultMessageCopy);
                    ChangeOperationalState(OperationalStateEnum.NotOperational);
                }

                return _desk.IsLoggedIn();
            };

            if (_messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180), out result) == false || (bool)result == false)
            {
                ChangeOperationalState(OperationalStateEnum.NotOperational);
                operationResultMessage = operationResultMessageCopy;
                return false;
            }

            operationResultMessage = operationResultMessageCopy;
            return (bool)result;
        }