/// <summary>
        /// Statuses the update.
        /// </summary>
        /// <param name="context">The context.</param>
        protected void statusUpdate(pipelineModelExecutionContext context)
        {
            if (logger != null)
            {
                logger.AppendLine(String.Format(statusLineOneFormat, context.model.name, context.scheduledTasks.Count, context.lastTakeSize, context.finishedTasks.Count));

                logger.AppendLine(String.Format(statusLineTwoFormat, DateTime.Now.Subtract(context.startTime).TotalMinutes, nParallelTasks, state.ToString(), context.exitSubjects.Count, context.trashSubjects.Count));
            }

            imbACE.Services.terminal.aceTerminalInput.doBeepViaConsole();
        }
示例#2
0
        /// <summary>
        /// Starting task execution
        /// </summary>
        /// <param name="__context">Context in which </param>
        public void StartProcess(pipelineModelExecutionContext __context)
        {
            model = __context.model;

            currentNode = model;
            nextNode    = model;

            context = __context;

            lifeSpanLeft = model.taskInitialLife;

            state = pipelineTaskStateEnum.running;

            while (state.HasFlag(pipelineTaskStateEnum.running))
            {
                processNextNode();

                Thread.SpinWait(1);
            }
        }
        /// <summary>
        /// Runs the specified model.
        /// </summary>
        /// <param name="output">The output.</param>
        protected void runSeparate(pipelineModelExecutionContext output)
        {
            while (machineRunning)
            {
                output.lastTakeSize = Math.Min(nParallelTasks, output.scheduledTasks.Count);

                List <IPipelineTask> taskTake = new List <IPipelineTask>();

                if (output.lastTakeSize == 0)
                {
                    state = pipelineMachineState.done;
                    break;
                }

                state = pipelineMachineState.preparingTake;

                Int32 c = 0;
                while (taskTake.Count < output.lastTakeSize)
                {
                    c++;
                    IPipelineTask task;

                    if (output.scheduledTasks.TryPop(out task))
                    {
                        taskTake.Add(task);
                    }

                    if (c > TASKTAKE_INSANELIMIT)
                    {
                        logger.log("Popping [" + output.lastTakeSize + "] tasks from scheduled task stack [" + output.scheduledTasks.Count + "] reached insane limit switch [" + c.ToString() + "]");
                        break;
                    }
                }

                state = pipelineMachineState.runningTaskTake;

                if (settings.doUseParallelExecution)
                {
                    Parallel.ForEach(taskTake, (IPipelineTask task) =>
                    {
                        try
                        {
                            task.StartProcess(output);
                        }
                        catch (Exception ex)
                        {
                            logger.log("Pipeline task exception:" + ex.Message);
                            throw;
                        }
                    });
                }
                else
                {
                    foreach (var task in taskTake)
                    {
                        try
                        {
                            task.StartProcess(output);
                        }
                        catch (Exception ex)
                        {
                            logger.log("Pipeline task exception:" + ex.Message);
                            throw;
                        }
                    }
                }

                output.finishedTasks.PushRange(taskTake.ToArray());

                state = pipelineMachineState.preparingTake;

                output.takeCounter++;
            }

            logger.log("Pipeline machine finished [" + output.finishedTasks.Count + "] tasks in model [" + output.model.name + "] after [" + output.takeCounter + "] tasks");
        }
        /// <summary>
        /// Runs the specified model.
        /// </summary>
        /// <param name="__model">The model.</param>
        /// <param name="paramsForPrimaryTasks">The parameters for primary tasks creation, passed to the model</param>
        /// <returns></returns>
        public pipelineModelExecutionContext run(IPipelineModel __model, params Object[] paramsForPrimaryTasks)
        {
            var output = new pipelineModelExecutionContext(__model);

            var primTasks = __model.createPrimaryTasks(paramsForPrimaryTasks);

            foreach (var pTask in primTasks)
            {
                output.scheduledTasks.Push(pTask);
            }

            statusExplain();

            Task runMasterTask = new Task(() =>
            {
                runSeparate(output);
            });

            machineRunning = true;

            statusUpdate(output);

            runMasterTask.Start();

            while (machineRunning)
            {
                if (output.GetSinceLastStatusUpdate() > settings.StatusReportPeriod)
                {
                    output.lastStatusUpdate = DateTime.Now;

                    statusUpdate(output);
                }

                Thread.Sleep(settings.TickForCheck);

                if (output.scheduledTasks.Count == 0 && output.lastTakeSize == 0)
                {
                    machineRunning = false;
                    statusUpdate(output);
                }
            }

            logger.log("Sorting exit bin into dictionaries (by type and content level)");

            foreach (var item in output.exitSubjects)
            {
                Type t = item.GetType();
                if (!output.exitByType.ContainsKey(t))
                {
                    output.exitByType.Add(t, new ConcurrentBag <IPipelineTaskSubject>());
                }
                cnt_level level = item.contentLevelType;
                if (!output.exitByLevel.ContainsKey(level))
                {
                    output.exitByLevel.Add(level, new ConcurrentBag <IPipelineTaskSubject>());
                }
                output.exitByType[t].Add(item);
                output.exitByLevel[level].Add(item);
            }

            logger.log("Exit bin sorted by [" + output.exitByType.Count + "] types and [" + output.exitByLevel.Count + "] levels");

            //imbACE.Services.terminal.aceTerminalInput.doBeepViaConsole(1200, 200, 1);

            return(output);
        }