Chriz L

Chriz L

  • NA
  • 220
  • 48.8k

Quartz scheduler

Dec 1 2016 4:07 AM
Hello,
I've create a job with quartz scheduler but it doesn't work.My project is a web application (webforms). Here's my code:
 
  1. using CrystalDecisions.CrystalReports.Engine;  
  2. using CrystalDecisions.Shared;  
  3. using Quartz;  
  4. using System;  
  5. using System.IO;  
  6. using System.Net;  
  7. using System.Web;  
  8.   
  9. namespace TestSchedule.App_code  
  10. {  
  11.     public class LettersJob:IJob  
  12.     {  
  13.         public void Execute(IJobExecutionContext context)  
  14.         {  
  15.             int appno = 2;  
  16.             int regNum = 1;  
  17.   
  18.             PrintLetter(appno, regNum);  
  19.         }  
  20.   
  21.         protected void PrintLetter(int appno,int regNum)  
  22.         {      
  23.             ReportDocument cryRpt = new ReportDocument();  
  24.             Random random = new Random();  
  25.             int randomNumber = random.Next(0, 100000);  
  26.   
  27.             try  
  28.             {  
  29.                 if (regNum == 1)  
  30.                     cryRpt.Load(System.Web.HttpContext.Current.Server.MapPath("~/ApproveLetterA.rpt"));  
  31.                 else  
  32.                 {  
  33.                     cryRpt.Load(System.Web.HttpContext.Current.Server.MapPath("~/ApproveLetterB.rpt"));  
  34.                 }  
  35.   
  36.                 cryRpt.SetParameterValue("@appno", appno);  
  37.                   
  38.   
  39.                 ExportOptions CrExportOptions;  
  40.                 DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();  
  41.                 PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();  
  42.                 CrDiskFileDestinationOptions.DiskFileName = "C:\\temp\\CertNo" + appno + randomNumber + ".pdf";  
  43.                 CrExportOptions = cryRpt.ExportOptions;  
  44.                   {  
  45.                     CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;  
  46.                     CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;  
  47.                     CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;  
  48.                     CrExportOptions.FormatOptions = CrFormatTypeOptions;  
  49.                   }  
  50.                     cryRpt.Export();  
  51.   
  52.                   string FilePath = "C:\\temp\\CertNo" + appno + randomNumber + ".pdf";  
  53.                   WebClient User = new WebClient();  
  54.                   Byte[] FileBuffer = User.DownloadData(FilePath);  
  55.                   if (FileBuffer != null)  
  56.                     {  
  57.                     System.Web.HttpContext.Current.Response.ContentType = "application/pdf";  
  58.                     System.Web.HttpContext.Current.Response.AddHeader("content-length", FileBuffer.Length.ToString());  
  59.                     System.Web.HttpContext.Current.Response.BinaryWrite(FileBuffer);  
  60.                     }  
  61.             }  
  62.             catch (Exception ex) { Console.Write(ex.Message); }  
  63.         }  
  64.   
  65.     }  
  66. }  
  1. using Quartz;  
  2. using Quartz.Impl;  
  3. using System;  
  4.   
  5. namespace TestSchedule.App_code  
  6. {  
  7.     public class JobScheduler  
  8.     {  
  9.         public static void Start()  
  10.         {  
  11.             IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();  
  12.             scheduler.Start();  
  13.   
  14.             IJobDetail job = JobBuilder.Create<LettersJob>().Build();  
  15.   
  16.             ITrigger trigger = TriggerBuilder.Create()  
  17.     .WithIdentity("trigger1""group1")  
  18.     .StartNow()  
  19.     .WithSimpleSchedule(x => x  
  20.         .WithIntervalInSeconds(10)  
  21.         .RepeatForever())  
  22.     .Build();  
  23.   
  24.             scheduler.ScheduleJob(job, trigger);  
  25.         }  
  26.     }  
  27. }  
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Optimization;  
  6. using System.Web.Routing;  
  7. using System.Web.Security;  
  8. using System.Web.SessionState;  
  9. using TestSchedule.App_code;  
  10.   
  11. namespace TestSchedule  
  12. {  
  13.     public class Global : HttpApplication  
  14.     {  
  15.         void Application_Start(object sender, EventArgs e)  
  16.         {  
  17.             // Code that runs on application startup  
  18.             RouteConfig.RegisterRoutes(RouteTable.Routes);  
  19.             BundleConfig.RegisterBundles(BundleTable.Bundles);  
  20.             JobScheduler.Start();  
  21.         }  
  22.     }  
  23. }  
 
Any kind of help would be appreciated.
Thank you in advance. 
 

Answers (11)