Esempio n. 1
0
        public MtResponse SendCommand(MtCommand command)
        {
            MtResponse response = null;

            if (command != null)
            {
                EventWaitHandle responseWaiter = new AutoResetEvent(false);

                lock (mResponseLocker)
                {
                    mResponseWaiters[command] = responseWaiter;
                }

                mExecutorManager.EnqueueCommand(command);

                //wait for execute command in MetaTrader
                responseWaiter.WaitOne(WAIT_RESPONSE_TIME);

                lock (mResponseLocker)
                {
                    if (mResponseWaiters.ContainsKey(command) == true)
                    {
                        mResponseWaiters.Remove(command);
                    }

                    if (mResponses.ContainsKey(command) == true)
                    {
                        response = mResponses[command];
                        mResponses.Remove(command);
                    }
                }
            }

            return(response);
        }
Esempio n. 2
0
        public MtResponse SendCommand(int commandType, ArrayList commandParameters)
        {
            Debug.WriteLine("[INFO] MtClient::SendCommand: commandType = {0}", commandType);

            MtResponse result = null;

            try
            {
                lock (mClientLocker)
                {
                    if (mProxy != null && mIsConnected == true)
                    {
                        result = mProxy.SendCommand(new MtCommand(commandType, commandParameters));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("[ERROR] MtClient::SendCommand: {0}", ex.Message);

                Close();

                throw new CommunicationException("Service connection failed! " + ex.Message);
            }

            return(result);
        }
Esempio n. 3
0
        public MtResponse SendCommand(MtCommand command)
        {
            Log.DebugFormat("SendCommand: begin. command {0}", command);

            if (command == null)
            {
                Log.Warn("SendCommand: end. command is not defined");
                return(null);
            }

            var task = _executorManager.SendCommand(command);

            //wait for execute command in MetaTrader
            MtResponse response = null;

            try
            {
                response = task.WaitResult(WaitResponseTime);
            }
            catch (Exception ex)
            {
                Log.WarnFormat("SendCommand: Exception - {0}", ex.Message);
            }

            Log.DebugFormat("SendCommand: end. response = {0}", response);

            return(response);
        }
Esempio n. 4
0
 public void SetResult(MtResponse result)
 {
     lock (_locker)
     {
         _result = result;
     }
     _responseWaiter.Set();
 }
Esempio n. 5
0
        public void SendResponse(MtResponse response)
        {
            Log.DebugFormat("SendResponse: begin. response = {0}", response);

            _currentTask.SetResult(response);
            _currentTask = null;

            Log.Debug("SendResponse: end.");
        }
Esempio n. 6
0
        public void SendResponse(MtResponse response)
        {
            Log.DebugFormat("SendResponse: begin. response = {0}", response);

            _commandTask.SetResult(response);
            _commandTask = null;
            FireOnCommandExecuted();

            Log.Debug("SendResponse: end.");
        }
Esempio n. 7
0
        public void SendResponse(MtResponse response)
        {
            MtCommand command = mCommand;

            mCommand = null;

            ICommandManager commandManager = CommandManager;

            if (commandManager != null)
            {
                commandManager.OnCommandExecuted(this, command, response);
            }
        }
Esempio n. 8
0
        public MtResponse SendCommand(MtCommand command)
        {
            MtResponse response = null;

            if (command != null)
            {
                var task = new MtCommandTask(command);
                _executorManager.EnqueueCommandTask(task);

                //wait for execute command in MetaTrader
                response = task.WaitResult(WAIT_RESPONSE_TIME);
            }

            return(response);
        }
Esempio n. 9
0
        public void SendResponse(int expertHandle, MtResponse response)
        {
            Debug.WriteLine("MtApiServerInstance::SendResponse: id = {0}, response = {1}", expertHandle, response);

            MtExpert expert = null;

            lock (mExpertsDictionary)
            {
                expert = mExpertsDictionary[expertHandle];
            }

            if (expert != null)
            {
                expert.SendResponse(response);
            }

            Debug.WriteLine("MtApiServerInstance::SendResponse: finish");
        }
Esempio n. 10
0
        public void SendResponse(int expertHandle, MtResponse response)
        {
            Log.DebugFormat("SendResponse: begin. id = {0}, response = {1}", expertHandle, response);

            MtExpert expert;
            lock (_experts)
            {
                expert = _experts[expertHandle];
            }

            if (expert != null)
            {
                expert.SendResponse(response);
            }
            else
            {
                Log.WarnFormat("SendResponse: expert with id {0} has not been found.", expertHandle);
            }

            Log.Debug("SendResponse: end");
        }
Esempio n. 11
0
        public void OnCommandExecuted(MtExpert expert, MtCommand command, MtResponse response)
        {
            if (expert == null)
            {
                return;
            }

            if (CommandExecuted != null)
            {
                CommandExecuted(this, new MtCommandExecuteEventArgs(command, response));
            }

            lock (_locker)
            {
                if (expert == mCurrentExecutor)
                {
                    if (mCommands.Count > 0)
                    {
                        mCurrentExecutor.NotifyCommandReady();
                    }
                }
            }
        }
Esempio n. 12
0
        public void SendResponse(MtResponse response)
        {
            MtCommand command = mCommand;
            mCommand = null;

            ICommandManager commandManager = CommandManager;
            if (commandManager != null)
            {
                commandManager.OnCommandExecuted(this, command, response);
            }
        }
Esempio n. 13
0
        public void OnCommandExecuted(MtExpert expert, MtCommand command, MtResponse response)
        {
            if (expert == null)
                return;

            if (CommandExecuted != null)
            {
                CommandExecuted(this, new MtCommandExecuteEventArgs(command, response));
            }

            lock (_locker)
            {
                if (expert == mCurrentExecutor)
                {
                    if (mCommands.Count > 0)
                    {
                        mCurrentExecutor.NotifyCommandReady();
                    }
                }
            }
        }
Esempio n. 14
0
 public void SendResponse(MtResponse response)
 {
     _commandTask.SetResult(response);
     _commandTask = null;
     FireOnCommandExecuted();
 }
Esempio n. 15
0
 public MtCommandExecuteEventArgs(MtCommand command, MtResponse response)
 {
     Command = command;
     Response = response;
 }
Esempio n. 16
0
        public void SendResponse(int expertHandle, MtResponse response)
        {
            Debug.WriteLine("MtApiServerInstance::SendResponse: id = {0}, response = {1}", expertHandle, response);

            MtExpert expert = null;
            lock (mExpertsDictionary)
            {
                expert = mExpertsDictionary[expertHandle];
            }

            if (expert != null)
            {
                expert.SendResponse(response);
            }

            Debug.WriteLine("MtApiServerInstance::SendResponse: finish");
        }
Esempio n. 17
0
 public MtCommandExecuteEventArgs(MtCommand command, MtResponse response)
 {
     Command  = command;
     Response = response;
 }