private IList <PlugModel> GetFileModel() { string runroot = AppDomain.CurrentDomain.BaseDirectory; var subDir = Directory.GetDirectories(runroot); IOConfigurationReader configurationReader = IOConfigurationReader.GetInstance(); IList <PlugModel> list = new List <PlugModel>(); foreach (var item in subDir) { string filename = new DirectoryInfo(item).Name; PlugModel model = new PlugModel(); string plugNamepath = Path.Combine(item, string.Concat(filename, "Plug.txt")); if (!File.Exists(plugNamepath)) { continue; } var plugdic = configurationReader.Read(plugNamepath); model.JobName = plugdic["JOBNAME"]; model.GroupName = plugdic["GROUPNAME"]; string CronexPression = string.Empty; if (plugdic.TryGetValue("CRONEXPRESSION", out CronexPression)) { model.CronexPression = CronexPression; } else { model.TimeSpan = int.Parse(plugdic["TIMESPAN"]); } model.DllRelativeDir = plugdic["JOBNAME"]; model.DllIQuartzServiceImplementFile = string.Concat(plugdic["JOBNAME"], "QuartzTask.dll"); list.Add(model); } return(list); }
public IQuartzTask Add(PlugModel plug) { if (this.QuartzSchedule == null || plug == null) { return(null); } string runroot = AppDomain.CurrentDomain.BaseDirectory; string path = Path.Combine( runroot, plug.DllRelativeDir, plug.DllIQuartzServiceImplementFile ); if (!File.Exists(path)) { throw new ArgumentException("找不到需要载入的目录或文件", path); } byte[] assemblyBuf = File.ReadAllBytes(path); Assembly assembly = null; if (assemblyBuf.Length > 0) { assembly = Assembly.Load(assemblyBuf); } else { return(null); } Type[] types = assembly.GetTypes(); try { foreach (var type in types) { if (type.GetInterface("IQuartzService") != null) { QuartzModel model = null; AssemblyDynamicLoader dyNamicLoader = new AssemblyDynamicLoader(plug.DllRelativeDir); dyNamicLoader.LoadAssembly(path); TaskBase task = new TaskBase(); IDictionary <string, object> dic = task.map; dic.Add("DyNamicLoader", dyNamicLoader); dic.Add("DyNamicMethod", type.FullName); IJobDetail job = JobBuilder.Create(task.GetType()) .WithIdentity(plug.JobName, plug.GroupName) .UsingJobData(new JobDataMap(dic)) .Build(); TriggerBuilder triggerBuilder = TriggerBuilder.Create() .WithIdentity(plug.JobName + "Trigger", plug.GroupName) .StartNow(); if (!string.IsNullOrEmpty(plug.CronexPression)) { triggerBuilder.WithCronSchedule(plug.CronexPression); } else { triggerBuilder.WithSimpleSchedule (x => x.WithInterval(new TimeSpan(0, 0, 0, 0, plug.TimeSpan)) .RepeatForever()); } ITrigger trigger = triggerBuilder.Build(); model = new QuartzModel(plug.JobName, job, trigger); return(Add(model)); } } } catch (Exception oe) { Debug.WriteLine(oe.Message); } return(null); }
public PlugContext() { PlugDbContext = new PlugModel(); PlugDbContext.Configuration.LazyLoadingEnabled = false; }