Пример #1
0
        private void Invoke()
        {
            while (true)
            {
                _eventReset.WaitOne();
                lock (object_lock)
                {
                    if (Interlocked.Read(ref _queueLength) > 0)
                    {
                        Interlocked.Decrement(ref _queueLength);
                    }
                    else
                    {
                        _eventReset.Reset();
                        continue;
                    }
                }

                try
                {
                    CommandQueue.TryDequeue(out Command command);
                    //Console.WriteLine(string.Format("{2} Job.Invoke {0} начал выполнять функцию {1}", Id, string.Join("/", ((DataCellHeader)command.OutputData.Header).CallStack), DateTime.Now));
                    //Parallel.Invoke(() => { Parallel.Invoke(() => { Parallel.Invoke(() => { throw new Exception("!"); }); }); });

                    if (command.ConditionData.Any(x => x.HasValue == null || !x.HasValue.Value))
                    {
                        throw new Exception("Хрень!");
                    }

                    _executionManager.Execute(command.Function, command.InputData, command.OutputData, new CommandContext()
                    {
                        Header = new InvokeHeader()
                        {
                            CallStack = command.Header.CallStack
                        }
                    });

                    //	Interlocked.Decrement(ref _queueLength);

                    /*command.OutputData.Data
                     * command.OutputData.HasValue = true;*/
                    //invoke

                    StackTraceLogger.Write(command);

                    /*
                     * string str = "";
                     *
                     * str += command.Header.CallstackToString() + " : ";
                     * str += command.Function.GetHeader<FunctionHeader>().CallstackToString(".") + "(";
                     *
                     * str += string.Join(", ", command.InputData.Select(x => x.GetHeader<DataCellHeader>().CallstackToString()));
                     *
                     * str += ")";
                     *
                     * str += " -> " + command.OutputData.Header.CallstackToString();
                     * Console.WriteLine(str);*/

                    //Console.WriteLine(string.Format("{2} Job.Invoke {0} выполнил функцию {1}",  Id, string.Join("/", ((DataCellHeader)command.OutputData.Header).CallStack), DateTime.Now));

                    //Console.WriteLine(string.Format("{2} Job.Invoke {0} выполнил функцию {1}", Id, string.Join("/", ((DataCellHeader)command.OutputData.Header).CallStack), DateTime.Now));

                    Parallel.Invoke(() => { Callback(command); });
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                //	Console.WriteLine("Job.Invoke");
            }
        }