Beispiel #1
0
        // /// <summary>
        // /// 当前Job的执行次数
        // /// </summary>
        // private int _loopNumber = 0;

        /// <summary>
        /// 递归完成内部所有的Job
        /// </summary>
        protected virtual void RunMethod(IJobPool jobPool)
        {
            if (jobPool.IsOverall) //是否整组轮循
            {                      //整组轮循
                //给出一个当前池子的所有项目的标记,都置为未完成
                var all = new List <bool>();
                for (int i = 0; i < jobPool.Count; i++)
                {
                    all.Add(false);
                }
                while (all.Contains(false))//当所有工作完成后,循环结束
                {
                    for (int i = 0; i < jobPool.Count; i++)
                    {
                        if (_breakFlag)
                        {
                            break;             //当检测到中断信号时,不再运行Job
                        }
                        IJobPoolItem jobItem = jobPool.ElementAt(i);
                        if (jobItem is IJob job)
                        {
                            if (job.LoopCount == 0 || job.CountOfCompleted < job.LoopCount)
                            {
                                RunJob(job, jobPool.IsOverall); //执行单个Job的运行
                            }
                            else
                            {
                                all[i] = true;//置为已完成标记
                            }
                        }
                    }
                }
            }
            else
            {   //执行工作流的每一项工作,将本职工作脚踏实地的完成,才进行下一项工作
                foreach (IJobPoolItem jobItem in jobPool)
                {
                    if (_breakFlag)
                    {
                        break;             //当检测到中断信号时,不再运行Job
                    }
                    if (!jobItem.IsPool)
                    {
                        if (jobItem is IJob job)
                        {
                            RunJob(job, jobPool.IsOverall); //执行单个Job的运行
                        }
                    }
                    else
                    {
                        if (jobItem is IJobPool subPool)
                        {
                            RunMethod(subPool); //递归
                        }
                    }
                }
            }

            OnAllWorkDone();
        }
Beispiel #2
0
 private void SetJobFunc(IJobPoolItem job)
 {
     if (!job.IsPool && job is IJob)
     {
         if (job is SerialQuestion question)
         {
             if (IsSynchronous)
             {
                 question.Run = Talk;
             }
             else
             {
                 question.Run = Broadcast;
             }
         }
     }
     else
     {
         if (job is IJobPool pool)
         {
             foreach (var poolItem in pool)
             {
                 SetJobFunc(poolItem);
             }
         }
     }
 }