示例#1
0
        /// <summary>
        /// 监听Redis执行命令
        /// </summary>
        /// <param name="command"></param>
        public static void Excute(TbCommand command)
        {
            var success = 0;
            var job     = TbJob.Find("ID", command.Jobid);

            if (job == null)
            {
                return;
            }

            Type jobtype;
            var  type = (CommandType)command.Commandtype;

            switch (type)
            {
            case CommandType.Pause:
                jobtype = GetJobType(command.Jobid);
                if (jobtype == null)
                {
                    return;
                }
                PauseToQuartz(jobtype, job);
                job.State = 0;
                //job.Lastedend = DateTime.Now.TimeSpan();
                success = job.SaveAsync() ? 1 : 0;
                break;

            case CommandType.Delete:
                jobtype = GetJobType(command.Jobid);
                if (jobtype == null)
                {
                    return;
                }
                if (job.State == 0)
                {
                    DelteToQuartz(jobtype, job);
                }
                DeleteDll(job.ID);
                if (job.Delete() > 0)
                {
                    var zip = TbZip.Find("JobID", command.Jobid);
                    zip?.Delete();
                    success = 1;
                }
                break;

            case CommandType.Stop:
                jobtype = GetJobType(command.Jobid);
                if (jobtype == null)
                {
                    return;
                }
                DelteToQuartz(jobtype, job);
                job.State = 0;
                //job.Lastedend = DateTime.Now.TimeSpan();
                job.SaveAsync();
                success = 1;
                break;

            case CommandType.Start:
                if (job.State == 1)
                {
                    jobtype = GetJobType(command.Jobid);
                    PauseToQuartz(jobtype, job);
                    File.Delete(GetJobPath(job.ID) + "zip");
                }
                if (Dictionary.ContainsKey(job.Name))
                {
                    jobtype = GetJobType(command.Jobid);
                    ResumeToQuartz(jobtype, job);
                    job.State = 1;
                    //job.Runcount++;
                    //job.Lastedstart = DateTime.Now.TimeSpan();
                    success = job.SaveAsync() ? 1 : 0;
                    break;
                }
                var path = CreateFile(job.ID, job.NodeID);
                DownLoadZip(job.ID, path);
                var json = new Dictionary <string, object>();
                if (!job.Datamap.IsNullOrWhiteSpace())
                {
                    json = job.Datamap.ToJsonEntity <Dictionary <string, object> >();
                }
                if (!json.ContainsKey("jobid"))
                {
                    json.Add("jobid", job.ID);
                }
                JoinToQuartz(GetJobType(command.Jobid), job, json);
                job.State = 1;
                //job.Runcount++;
                //job.Lastedstart = DateTime.Now.TimeSpan();
                success = job.SaveAsync() ? 1 : 0;
                break;

            case CommandType.ReStart:
                //var jsons = new Dictionary<string, object>();
                //if (!job.Datamap.IsNullOrWhiteSpace())
                //    jsons = job.Datamap.ToJsonEntity<Dictionary<string, object>>();
                //if (!jsons.ContainsKey("jobid"))
                //    jsons.Add("jobid", job.ID);
                //jobtype = GetJobType(command.Jobid);
                //ResumeToQuartz(jobtype);
                //job.State = 1;
                //job.Runcount++;
                //job.Lastedstart = DateTime.Now.TimeSpan();
                //success = job.SaveAsync() ? 1 : 0;
                break;

            default:
                break;
            }
            command.Success = success;
        }
示例#2
0
        /// <summary>
        /// 删除压缩文件
        /// </summary>
        /// <param name="jobid"></param>
        public static bool DeleteZip(int jobid)
        {
            var zip = TbZip.Find("JobID", jobid);

            return(zip?.Delete() > 0);
        }