Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Timerjob is not working - it doesn't show up in central admin monitoring tab

$
0
0

Dear all,

I have enabled the timer job using the following class file and event receiver file. After enabling in powershell - the job is not appearing in job definition in central administration.

Any inputs are highly appreciated. Since I am new to SP2010 - I will then try to debug the timer job.

C# class file

using System; using System.Collections.Generic; using System.Linq; using System.Net.Mail; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace TrainingTimerJobs { public class TJ_ProcessInstructorSchedules : SPJobDefinition { public TJ_ProcessInstructorSchedules() : base() { } public TJ_ProcessInstructorSchedules(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType) { } public TJ_ProcessInstructorSchedules(string jobName, SPWebApplication webApplication) : base(jobName, webApplication, null, SPJobLockType.ContentDatabase) { this.Title = "Training Registration Portal - Process Instructor Schedules"; } public override void Execute(Guid targetInstanceId) { //Access the Trainers list SPWebApplication webApp = this.Parent as SPWebApplication; SPSite trainingSite = webApp.Sites["sites/training"]; SPWeb rootWeb = trainingSite.RootWeb; SPList trainersList = rootWeb.Lists["Trainers"]; SPListItemCollection trainers = trainersList.Items; foreach (SPListItem trainer in trainers) { //Store the trainer's email address string trainerEmail = trainer["E-mail Address"].ToString(); //Store the trainer's full name for future use string trainerFullName = trainer["Full Name"].ToString(); //Access the Classes list and retrieve classes for this trainer that occur in the future SPList classesList = rootWeb.Lists["Classes"]; SPQuery getClassesForTrainer = new SPQuery(); getClassesForTrainer.ViewFields = "<FieldRef Name='CourseTitle'/><FieldRef Name='Trainer'/><FieldRef Name='Venue'/><FieldRef Name='Registrations'/><FieldRef Name='StartDate'/><FieldRef Name='_EndDate'/>"; //CAML getClassesForTrainer.Query = "<Where><And><Eq><FieldRef Name='Trainer' /><Value Type='Lookup'>" + trainerFullName + "</Value></Eq><Geq><FieldRef Name='StartDate'/><Value Type='DateTime'><Today /></Value></Geq></And></Where>"; SPListItemCollection classesForTrainer = classesList.GetItems(getClassesForTrainer); //Iterate through the classes and build an email to send to the Trainer string emailSubject = "Instructor Schedule for " + trainerFullName; string emailBody = ""; emailBody += "Hello " + trainerFullName + ",<br/><br/>"; emailBody += "Here is your upcoming schedule. If you have any questions, please contact Judy Moore (jmoore@ifmr.co.in) or Amanda Stevenson (astevenson@ifmr.co.in).<br/><br/>"; foreach (SPListItem scheduledClass in classesForTrainer) { emailBody += scheduledClass["CourseTitle"].ToString().Remove(0, 3) + " at " + scheduledClass["Venue"].ToString() + " starting at " + scheduledClass["StartDate"].ToString() + " and ending at " + scheduledClass["_EndDate"].ToString() + ", which has " + scheduledClass["Registrations"].ToString() + " registrations.<br/>"; } emailBody += "<br/>Thank you!<br/><br/>"; emailBody += "Do not reply to this message; it is an automatically generated system message."; //Send the email MailMessage instructorScheduleEmail = new MailMessage("SharePointadmin@ifmr.co.in", trainerEmail, emailSubject, emailBody); instructorScheduleEmail.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient("inmaa3bms0036"); smtpClient.Send(instructorScheduleEmail); } } } }

Event Receiver

using System; using System.Runtime.InteropServices; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint.Security; namespace TrainingTimerJobs.Features.Feature_TrainingTimerJobs { /// <summary> /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade. /// </summary> /// <remarks> /// The GUID attached to this class may be used during packaging and should not be modified. /// </remarks> [Guid("6824fc32-2347-49b2-9a85-fbe53e7c8cee")] public class Feature_TrainingTimerJobsEventReceiver : SPFeatureReceiver { // Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication webApp = properties.Feature.Parent as SPWebApplication; if (webApp.Name == "tandoor.ifmr.co.in") { foreach (SPJobDefinition job in webApp.JobDefinitions) { if (job.Name == "Training Registration Portal - Process Instructor Schedules") { job.Delete(); } } TJ_ProcessInstructorSchedules tjSendSchedules = new TJ_ProcessInstructorSchedules("Training Registration Portal - Process Instructor Schedules", webApp); tjSendSchedules.Title = "Training Registration Portal - Process Instructor Schedules"; SPWeeklySchedule weeklySchedule = new SPWeeklySchedule(); weeklySchedule.BeginDayOfWeek = DayOfWeek.Friday; weeklySchedule.BeginHour = 16; weeklySchedule.EndDayOfWeek = DayOfWeek.Friday; weeklySchedule.EndHour = 17; tjSendSchedules.Schedule = weeklySchedule; tjSendSchedules.Update(); } } // Uncomment the method below to handle the event raised before a feature is deactivated. public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPWebApplication webApp = properties.Feature.Parent as SPWebApplication; if (webApp.Name == "tandoor.ifmr.co.in") { foreach (SPJobDefinition job in webApp.JobDefinitions) { if (job.Name == "Training Registration Portal - Process Instructor Schedules") { job.Delete(); } } } } // Uncomment the method below to handle the event raised after a feature has been installed. //public override void FeatureInstalled(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised before a feature is uninstalled. //public override void FeatureUninstalling(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised when a feature is upgrading. //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters) //{ //} } }




Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>