2014-02-27 37 views
1

我正在使用Quartz.Net 2.X,並且據我所知,它正在掃描執行目錄以查找IJob的實例。有沒有辦法來定義其他目錄(理想情況下多個目錄)在哪裏尋找「IJobs」?Quartz.Net在多個目錄中查找

回答

0

有幾種方法,其中之一是編寫自定義ITypeLoadHelper。在我的設置我用AppDomain.AssemblyResolve事件實際上有任何依賴負載從我的自定義文件夾:

public class CustomFolderTypeLoadHelper : SimpleTypeLoadHelper 
{ 
    private Dictionary<string, string> dllPaths; 
    public override void Initialize() 
    { 
     string path = @"C:\"; // quick&dirty way 
     dllPaths = new DirectoryInfo(path) 
      .GetFiles("*.dll") 
      .ToDictionary(fi => Path.GetFileNameWithoutExtension(fi.Name), fi => fi.FullName); 

     AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => 
      dllPaths.ContainsKey(args.Name) ? Assembly.LoadFrom(dllPaths[args.Name]) : null; 

     base.Initialize(); 
    } 
} 

那麼這行添加到quartz.config

quartz.scheduler.typeLoadHelper.type = MyNamespace.CustomFolderTypeLoadHelper, MyAssembly 

或者你可以使用的方法LoadType()該接口上做石英的方式。

在任何一種情況下,將此引導程序類放在Quartz bin文件夾中。