/// <summary>开始</summary> public override void Start() { var jf = _File = JobFile.Current; var list = new List <JobModel>(); if (jf.Jobs != null && jf.Jobs.Length > 0) { list.AddRange(jf.Jobs); } // 扫描所有Worker并添加到作业文件 var flag = false; foreach (var item in GetAll()) { if (!list.Any(e => e.Name == item.Key)) { // 新增作业项 var model = new JobModel(); // 获取默认设置 var job = item.Value.CreateInstance() as Handler; var df = job?.Job; if (df != null) { model.Copy(df); } if (model.Start.Year <= 2000) { model.Start = DateTime.Now.Date; } if (model.Step <= 0) { model.Step = 30; } if (model.BatchSize <= 0) { model.BatchSize = 10000; } if (model.MaxTask <= 0) { model.MaxTask = Environment.ProcessorCount; } if (model.Name.IsNullOrEmpty()) { model.Name = item.Key; model.Enable = true; } list.Add(model); flag = true; } } if (flag) { if (jf.Jobs == null || jf.Jobs.Length == 0) { jf.CreateTime = DateTime.Now; } jf.Jobs = list.ToArray(); } jf.Save(); base.Start(); }