TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chriz L
NA
220
50.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:
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.
Reply
Answers (
11
)
Get already coloured word using word addin in C#
c# - how to assign linq result to datatable ?