protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); log4net.Config.XmlConfigurator.Configure(); LunceneHelper.lucenePath = HttpRuntime.AppDomainAppPath.ToString() + "lucenedir"; #region 创建Luncene目录 if (!Directory.Exists(LunceneHelper.lucenePath)) { Directory.CreateDirectory(LunceneHelper.lucenePath); } #endregion //启动Lucene线程防止文件并发问题 IndexManager.myManager.Start(); QuartzHelper.CreateJob(); }
/// <summary> /// 创建Quartz /// </summary> /// <param name="model"></param> /// <returns></returns> public string CreateOrUpdateQuartz(QuartzEditModel model) { try { if (string.IsNullOrWhiteSpace(model.JobGroup)) { throw new Exception("Job分组不能为空!"); } if (string.IsNullOrWhiteSpace(model.JobName)) { throw new Exception("Job名不能为空!"); } if (string.IsNullOrWhiteSpace(model.Cron)) { throw new Exception("Cron表达式不能为空不能为空!"); } if (string.IsNullOrWhiteSpace(model.JobClass)) { throw new Exception("Job类名不能为空!"); } _sql.OpenDb(); if (string.IsNullOrEmpty(model.JobInfoId)) { DataTable dt = _sql.Query("SELECT JOB_CLASS_NAME FROM QRTZ_JOB_DETAILS WITH(NOLOCK) WHERE JOB_GROUP = @group AND JOB_NAME = @name", new Dictionary <string, object> { { "@group", model.JobGroup }, { "@name", model.JobName } }); if (dt != null && dt.Rows.Count > 0) { throw new Exception("当前Job已存在,请更改组名或Job名!"); } quartz.CreateJob(_config.Job_Assembly, model); JobInfo job = new JobInfo(); model.FillTableWithModel <JobInfo>(job); job.JobStatus = Constants.JobStatusRunning; _sql.Create(job); } else { JobInfo job = _sql.Search <JobInfo>(model.JobInfoId); model.FillTableWithModel <JobInfo>(job); _sql.Update(job); } return(Constants.SaveSuccessMssg); } catch (Exception ex) { _log.Error(ex); throw ex; } finally { _sql.CloseDb(); } }