예제 #1
0
        /// <summary>
        /// Событие при завершении вычисления исполнителя.
        /// </summary>
        /// <param name="result"></param>
        private void OnReliseJob(Command result)
        {
            if (result.Function.GetType() != typeof(ControlFunction))
            {
                _dataCellRepository.Add(new[] { result.OutputData });
                //Console.WriteLine(string.Format("CommandManager.OnReliseJob _readyCommands.Count={0}, _commandHeaders.Count={1}", _readyCommands.Count, _commandHeaders.Count));
            }

            if (_readyCommands.Count > 0)
            {
                Command command;
                if (_readyCommands.TryDequeue(out command))
                {
                    _jobManager.AddCommand(command);
                }
            }
            else
            if (_commandHeaders.Count > 0)
            {
                CommandHeader command_header;
                if (_commandHeaders.TryDequeue(out command_header))
                {
                    PrepareOrSendToWait(new[] { command_header });
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Событие, которое выполняется при появлении свободного исполнителя.
        /// </summary>
        public void OnFreeJob()
        {
            var key = _awaitingExecutionCommands.Keys.FirstOrDefault();

            if (!string.IsNullOrEmpty(key))
            {
                if (_awaitingExecutionCommands.TryRemove(key, out Command command))
                {
                    _jobManager.AddCommand(command);
                    if (!_executingCommands.TryAdd(key, command))
                    {
                        throw new NotImplementedException("DataFlowLogicsService.OnFreeJob _executingCommands Не удалось добавить.");
                    }
                    //Console.WriteLine("! AddNewCommandHeader _awaitingExecutionCommands->_executingCommands {0}", command.Header.CallstackToString());
                }
                else
                {
                    throw new NotImplementedException("DataFlowLogicsService.OnFreeJob Не удалось извлечь.");
                }
            }
            else
            {
                key = _awaitingPreparationCommandHeaders.Keys.FirstOrDefault();
                if (!string.IsNullOrEmpty(key))
                {
                    if (_awaitingPreparationCommandHeaders.TryRemove(key, out CommandHeader command_header))
                    {
                        _preparationCommandService.PrepareCommand(command_header);
                        if (!_preparationCommandHeaders.TryAdd(key, command_header))
                        {
                            throw new NotImplementedException("DataFlowLogicsService.OnFreeJob _preparationCommandHeaders Не удалось добавить.");
                        }
                        //Console.WriteLine("! AddNewCommandHeader _awaitingPreparationCommandHeaders->_preparationCommandHeaders {0}", command_header.CallstackToString());
                    }
                    else
                    {
                        throw new NotImplementedException("DataFlowLogicsService.OnFreeJob Не удалось извлечь.");
                    }
                }
            }
        }