Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
11
Answers
Quartz scheduler
Chriz L
8y
522
1
Reply
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:
using
CrystalDecisions.CrystalReports.Engine;
using
CrystalDecisions.Shared;
using
Quartz;
using
System;
using
System.IO;
using
System.Net;
using
System.Web;
namespace
TestSchedule.App_code
{
public
class
LettersJob:IJob
{
public
void
Execute(IJobExecutionContext context)
{
int
appno = 2;
int
regNum = 1;
PrintLetter(appno, regNum);
}
protected
void
PrintLetter(
int
appno,
int
regNum)
{
ReportDocument cryRpt =
new
ReportDocument();
Random random =
new
Random();
int
randomNumber = random.Next(0, 100000);
try
{
if
(regNum == 1)
cryRpt.Load(System.Web.HttpContext.Current.Server.MapPath(
"~/ApproveLetterA.rpt"
));
else
{
cryRpt.Load(System.Web.HttpContext.Current.Server.MapPath(
"~/ApproveLetterB.rpt"
));
}
cryRpt.SetParameterValue(
"@appno"
, appno);
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions =
new
DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions =
new
PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName =
"C:\\temp\\CertNo"
+ appno + randomNumber +
".pdf"
;
CrExportOptions = cryRpt.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryRpt.Export();
string
FilePath =
"C:\\temp\\CertNo"
+ appno + randomNumber +
".pdf"
;
WebClient User =
new
WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if
(FileBuffer !=
null
)
{
System.Web.HttpContext.Current.Response.ContentType =
"application/pdf"
;
System.Web.HttpContext.Current.Response.AddHeader(
"content-length"
, FileBuffer.Length.ToString());
System.Web.HttpContext.Current.Response.BinaryWrite(FileBuffer);
}
}
catch
(Exception ex) { Console.Write(ex.Message); }
}
}
}
using
Quartz;
using
Quartz.Impl;
using
System;
namespace
TestSchedule.App_code
{
public
class
JobScheduler
{
public
static
void
Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<LettersJob>().Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity(
"trigger1"
,
"group1"
)
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(10)
.RepeatForever())
.Build();
scheduler.ScheduleJob(job, trigger);
}
}
}
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Optimization;
using
System.Web.Routing;
using
System.Web.Security;
using
System.Web.SessionState;
using
TestSchedule.App_code;
namespace
TestSchedule
{
public
class
Global : HttpApplication
{
void
Application_Start(
object
sender, EventArgs e)
{
// Code that runs on application startup
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
JobScheduler.Start();
}
}
}
Any kind of help would be appreciated.
Thank you in advance.
Post
Reset
Cancel
Answers (
11
)
Next Recommended Forum
Get already coloured word using word addin in C#
c# - how to assign linq result to datatable ?