Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public MtCommandTask(MtCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            Command = command;
        }
Beispiel #4
0
        public void EnqueueCommand(MtCommand command)
        {
            if (command == null)
                return;

            lock (_locker)
            {
                mCommands.Enqueue(command);

                mCurrentExecutor.NotifyCommandReady();
            }
        }
Beispiel #5
0
        public void SendResponse(MtResponse response)
        {
            MtCommand command = mCommand;

            mCommand = null;

            ICommandManager commandManager = CommandManager;

            if (commandManager != null)
            {
                commandManager.OnCommandExecuted(this, command, response);
            }
        }
Beispiel #6
0
        public void EnqueueCommand(MtCommand command)
        {
            if (command == null)
            {
                return;
            }

            lock (_locker)
            {
                mCommands.Enqueue(command);

                mCurrentExecutor.NotifyCommandReady();
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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 = new MtCommandTask(command);

            _executorManager.EnqueueCommandTask(task);

            //wait for execute command in MetaTrader
            var response = task.WaitResult(WaitResponseTime);

            return(response);
        }
Beispiel #9
0
        public MtCommandTask SendCommand(MtCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var task = new MtCommandTask(command);

            Log.DebugFormat("SendTask: begin. command = {0}", command);

            ITaskExecutor executor;

            lock (_locker)
            {
                if (_executorMap.ContainsKey(command.ExpertHandle))
                {
                    executor = _executorMap[command.ExpertHandle];
                }
                else
                {
                    executor = _executorList.Count > 0 ? _executorList[0] : null;
                }
            }

            if (executor == null)
            {
                Log.Error("SendTask: Executor is null!");
            }
            else
            {
                executor.Execute(task);
            }

            Log.Debug("SendTask: end.");

            return(task);
        }
Beispiel #10
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();
                    }
                }
            }
        }
Beispiel #11
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;
        }
Beispiel #12
0
 public MtResponse SendCommand(MtCommand command)
 {
     return(Channel.SendCommand(command));
 }
Beispiel #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();
                    }
                }
            }
        }
Beispiel #14
0
 public MtResponse SendCommand(MtCommand command)
 {
     return mServer.SendCommand(command);
 }
Beispiel #15
0
 public MtResponse SendCommand(MtCommand command)
 {
     return(mServer.SendCommand(command));
 }
Beispiel #16
0
 public MtCommandExecuteEventArgs(MtCommand command, MtResponse response)
 {
     Command = command;
     Response = response;
 }
Beispiel #17
0
 public MtCommandExecuteEventArgs(MtCommand command, MtResponse response)
 {
     Command  = command;
     Response = response;
 }
Beispiel #18
0
        public MtResponse SendCommand(MtCommand command)
        {
            Log.DebugFormat("SendCommand: called. command = {0}", command);

            return(_server.SendCommand(command));
        }
Beispiel #19
0
 public MtCommandTask(MtCommand command)
 {
     Command = command;
 }