2012-04-24 106 views
5

有人可以告訴我做錯了什麼。 我想安裝qurtz,以便在啓動時它會讀取一個XML配置文件。在文件內部有一個作業激活我的HelloEmail_Job.cs類(它被正確創建,使用execute方法中的邏輯來擴展IJob)。 xml還有一個cron觸發器,用於每分鐘觸發一次的作業(純粹用於測試)quartz.net從配置XML在asp.net

但是一切都沒有錯誤地啓動,但作業從不觸發。我相信,我在配置錯誤

我有一個處理我的調度產生一個單,在程序器在我的應用程序啓動時開始(在Global.asax文件)

NameValueCollection properties = new NameValueCollection(); 
    properties["quartz.scheduler.instanceName"] = "RemoteServer"; 

    ////// set thread pool info 
    properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; 
    properties["quartz.threadPool.threadCount"] = "5"; 
    properties["quartz.threadPool.threadPriority"] = "Normal"; 

    properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"; 
    properties["quartz.jobStore.useProperties"] = "true"; 
    properties["quartz.jobStore.dataSource"] = "default"; 
    properties["quartz.jobStore.tablePrefix"] = "QRTZ_"; 
    properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz"; 

    properties["quartz.dataSource.default.connectionString"] = "Data Source=CRAIG-PC\\SQLEXPRESS;Initial Catalog=MCWdb;User ID=sa;Password=mastercrud;"; 
    properties["quartz.dataSource.default.provider"] = "SqlServer-20"; 

    // job initialization plugin handles our xml reading, without it defaults are used 
    properties["quartz.plugin.xml.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz"; 
    properties["quartz.plugin.xml.fileNames"] = "~/quartz_jobs.xml"; 

    ISchedulerFactory sf = new StdSchedulerFactory(properties); 
    _sched = sf.GetScheduler(); 

我quartz_jobs.xml文件看起來像這樣

 <?xml version="1.0" encoding="UTF-8"?> 

     <job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         version="2.0"> 

      <processing-directives> 
      <overwrite-existing-data>true</overwrite-existing-data> 
      </processing-directives> 

      <schedule>   
       <job> 
        <job-detail> 
        <name>MyJob</name> 
        <group>MyJobs</group> 
        <description>sends out a test email</description> 
         <job-type>HelloEmail_Job</job-type> 
         <volatile>false</volatile> 
        <durable>true</durable> 
        <recover>false</recover> 
        <job-data-map> 
         <entry> 
         <key>Body</key> 
         <value>Hello From your website!!!!!!!!</value> 
         </entry> 
        </job-data-map> 
        </job-detail> 
        <trigger> 
        <cron> 
         <name>MyJobTrigger</name> 
         <group>MyJobs</group> 
         <description>A description</description> 
         <job-name>MyJob</job-name> 
         <job-group>MyJobs</job-group> 
         <cron-expression>0 0/1 * 1/1 * ? *</cron-expression> 
        </cron> 
        </trigger> 
       </job> 
      </schedule> 

     </job-scheduling-data> 

我知道程序器與一個簡單的觸發器,因爲當我的應用程序創建它們,並安排他們動態的它完美運行正常特設工作。但我希望邏輯可重複(通過cron),並且可以通過xml配置,我的直覺是JOB_TYPE值是錯誤的。

感謝

+0

注:這是一個網站,我HelloEmail_Job.cs在App_Code文件\調度\文件的工作生活。如果這有幫助 – Crudler 2012-04-24 10:47:44

回答

6

你的工作類型需要被指定爲

<job-type>Fully.Qualified.Type.Name, AssemblyNameWithoutTheDllExtension</job-type> 
+1

謝謝。關於這個壽命的問題。我的是一個asp.net網站。我的課生活在app_code文件夾中。我還沒有編譯我的網站到一個DLL。我如何確定完全合格的名稱?謝謝! – Crudler 2012-04-30 10:35:39

+1

var name = yourVariable.GetType()。Name爲您指定名稱,.Namespace爲您提供名稱空間,.Assembly爲您提供程序集名稱。我不知道你是否可以從應用程序代碼加載,因爲我假設彙編名稱每次編譯時都會改變。 – jvilalta 2012-05-04 13:09:01

+0

謝謝。你的提示告訴我什麼是錯的。我的app_code文件夾變得有趣的名字,因爲它被動態編譯。如果我預編譯我的應用程序,它是排序。所以一切都是 HelloJob,APP_CODE感謝您的幫助 – Crudler 2012-05-09 10:31:37