コード例 #1
0
ファイル: JobBaseList.cs プロジェクト: dzhendong/JobAgent
 public void Insert(int p, JobBase job)
 {
     WaitHandle.WaitAll(this.reads);
     this.writes[0].Reset();
     this.bases.Insert(p, job);
     this.writes[0].Set();
 }
コード例 #2
0
ファイル: JobBaseList.cs プロジェクト: dzhendong/JobAgent
        private static string info(JobBase job)
        {
            string jobInfo = "";
            object obj = jobInfo;
            jobInfo = string.Concat(new object[]
				{
					obj,
					"★",
					job.GetJobInfo(),
					"(",
					job.Param,
					"):",
					job.JobStatus,
					"\r\n"
				});

            if (job.JobStatus != JobStatus.Stop)
            {
                jobInfo = jobInfo + "开始时间:" + job.StartTime;
                if (job.JobStatus == JobStatus.Stoped)
                {
                    object obj2 = jobInfo;
                    jobInfo = string.Concat(new object[]
						{
							obj2,
							",结束时间:",
							job.lastEndTime,
							",上次共运行:",
							(job.lastEndTime - job.StartTime).TotalSeconds,
							"秒"
						});
                }
                else
                {
                    object obj3 = jobInfo;
                    jobInfo = string.Concat(new object[]
						{
							obj3,
							",已运行:",
							(DateTime.Now - job.StartTime).TotalSeconds,
							"秒\r\n"
						});
                }
            }

            if (job.JobStatus == JobStatus.Stoped)
            {
                object obj4 = jobInfo;
                jobInfo = string.Concat(new object[]
					{
						obj4,
						",结果:",
						job.JobResult,
						"\r\n"
					});
            }
            return jobInfo;
        }
コード例 #3
0
ファイル: JobManager1.cs プロジェクト: dzhendong/JobAgent
        public void RunJob(JobMsgEntity jme, bool needParallel)
        {
            string jobClassFullName = jme.JobClassFullName;
            string jobNameSpace     = jme.JobNameSpace;
            string param            = jme.Param;

            string[] array = null;

            if (jme.JobInfo.IndexOf(":") > -1)
            {
                array = jme.JobInfo.Split(new char[] { ':' });
                if (!string.IsNullOrEmpty(array[1]) && !string.IsNullOrEmpty(array[2]))
                {
                    //组中是否存在相同的作业
                    if (!this.ExistGroupInfo(jobClassFullName))
                    {
                        this.groupInfo.Add(new GroupInfo
                        {
                            JobClass = jobClassFullName,
                            Flag     = array[1],
                            Prority  = int.Parse(array[2])
                        });
                    }

                    //优先级处理
                    for (int i = this.groupInfo.Count - 1; i >= 0; i--)
                    {
                        if (this.groupInfo[i].Flag == array[1])
                        {
                            //停止优先级低的作业
                            if (this.groupInfo[i].Prority < int.Parse(array[2]))
                            {
                                this.StopJob(this.groupInfo[i].JobClass);
                            }
                            else
                            {
                                if (this.GetStauts(this.groupInfo[i].JobClass) == JobStatus.Running)
                                {
                                    jme.JobInfo = array[1] + "组内,有更高优先级的实例(" + this.groupInfo[i].JobClass + ")在运行,此次请求忽略!";
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            if (this.pool.ContainsKey(jobClassFullName))
            {
                JobBase jobBase = this.pool[jobClassFullName][0];

                //有实例运行
                if ((jobBase.JobStatus == JobStatus.Running || jobBase.JobStatus == JobStatus.Stopping) &&
                    !needParallel)
                {
                    jme.JobInfo = "有实例在运行,此次请求忽略!";
                    return;
                }

                for (int j = this.pool[jobClassFullName].Count - 1; j >= 0; j--)
                {
                    if (this.pool[jobClassFullName][j].JobStatus == JobStatus.Stoped)
                    {
                        if (this.pool[jobClassFullName][j].lastEndTime > jme.LastEndTime)
                        {
                            jme.LastEndTime = this.pool[jobClassFullName][j].lastEndTime;
                            jme.JobResult   = this.pool[jobClassFullName][j].JobResult;
                        }
                        this.pool[jobClassFullName].RemoveAt(j);
                    }
                }
            }

            this.AddJobToRun(jobNameSpace, jobClassFullName, param, (array == null) ? jme.JobInfo : array[0]);
            jme.JobInfo = "开始运行新实例!";
        }