Creating OOOTrainingReport scheduled job
This commit is contained in:
parent
9c5c938157
commit
167db67027
@ -11,7 +11,7 @@ using System.Web.Mvc;
|
|||||||
using Kendo.Mvc.Extensions;
|
using Kendo.Mvc.Extensions;
|
||||||
using Fab2ApprovalSystem.Misc;
|
using Fab2ApprovalSystem.Misc;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Fab2ApprovalSystem.Controllers
|
namespace Fab2ApprovalSystem.Controllers
|
||||||
{
|
{
|
||||||
@ -762,68 +762,6 @@ namespace Fab2ApprovalSystem.Controllers
|
|||||||
}
|
}
|
||||||
return isSuccess;
|
return isSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RunOOOTrainingReport()
|
|
||||||
{
|
|
||||||
bool isSuccess = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string emailBody = "<h1>Mesa Approval Open Training Assignments Report - OOO</h1> <br />";
|
|
||||||
emailBody += "<p>The following contains open training assignments in the Mesa Approval system for out of office users.";
|
|
||||||
emailBody += " Please ensure they complete their training assignments promptly upon their return.</p><br />";
|
|
||||||
emailBody += "<style>table,th,td{border: 1px solid black;}</style>";
|
|
||||||
//Get all users set up to receive the training report email.
|
|
||||||
List<TrainingReportUser> trainingReportUsers = adminDMO.GetTrainingReportUsers();
|
|
||||||
List<string> emailList = new List<string>();
|
|
||||||
//foreach (var user in trainingReportUsers)
|
|
||||||
//{
|
|
||||||
// string userEmail = userDMO.GetUserByID(user.UserId).Email;
|
|
||||||
// emailList.Add(userEmail);
|
|
||||||
//}
|
|
||||||
emailList.Add("Chase.Tucker@infineon.com");
|
|
||||||
//Get a list of open trainings
|
|
||||||
List<Training> openTrainings = trainingDMO.GetAllOpenTrainings();
|
|
||||||
|
|
||||||
foreach (Training training in openTrainings)
|
|
||||||
{
|
|
||||||
string trainingSection = "";
|
|
||||||
int trainingSectionUserCount = 0;
|
|
||||||
string ecnTitle = ecnDMO.GetECN(training.ECN).Title;
|
|
||||||
trainingSection += "<h3>" + training.ECN + " - " + ecnTitle + "</h3>";
|
|
||||||
|
|
||||||
trainingSection += "<table>";
|
|
||||||
trainingSection += "<tr><th>Name</th><th>Date Assigned</th></tr>";
|
|
||||||
List<TrainingAssignment> openAssignments = trainingDMO.GetOpenAssignmentsByTrainingID(training.TrainingID);
|
|
||||||
foreach (TrainingAssignment assignment in openAssignments)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (userDMO.GetUserByID(assignment.UserID).OOO)
|
|
||||||
{
|
|
||||||
trainingSectionUserCount++;
|
|
||||||
|
|
||||||
DateTime? assignmentDate = assignment.DateAssigned;
|
|
||||||
|
|
||||||
string DateAssigned = assignmentDate.HasValue ? assignmentDate.Value.ToString("MM/dd/yyyy") : "<not available>";
|
|
||||||
|
|
||||||
trainingSection += "<tr><td>" + assignment.FullName + "</td><td>" + DateAssigned + "</td>";
|
|
||||||
|
|
||||||
trainingSection += "</tr>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trainingSection += "</table>";
|
|
||||||
if (trainingSectionUserCount > 0) emailBody += trainingSection;
|
|
||||||
}
|
|
||||||
string recipientEmail = "";
|
|
||||||
List<string> ccRecipients = emailList;
|
|
||||||
emailer.SendNotification("MesaFabApproval@infineon.com", ccRecipients, "Mesa Approval Open Training Report - OOO", emailBody, "Open Training Report - OOO");
|
|
||||||
isSuccess = true;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
isSuccess = false;
|
|
||||||
}
|
|
||||||
return isSuccess;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -45,15 +45,6 @@ namespace Fab2ApprovalSystem.Controllers
|
|||||||
{
|
{
|
||||||
return request.CreateResponse(HttpStatusCode.InternalServerError);
|
return request.CreateResponse(HttpStatusCode.InternalServerError);
|
||||||
}
|
}
|
||||||
case "TrainingReportOOO":
|
|
||||||
if (trainingFunctions.RunOOOTrainingReport())
|
|
||||||
{
|
|
||||||
return request.CreateResponse(HttpStatusCode.OK);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return request.CreateResponse(HttpStatusCode.InternalServerError);
|
|
||||||
}
|
|
||||||
case "CARDueDates":
|
case "CARDueDates":
|
||||||
if (carFunctions.ProcessCARDueDates())
|
if (carFunctions.ProcessCARDueDates())
|
||||||
{
|
{
|
||||||
|
@ -130,6 +130,7 @@
|
|||||||
<Compile Include="Global.asax.cs">
|
<Compile Include="Global.asax.cs">
|
||||||
<DependentUpon>Global.asax</DependentUpon>
|
<DependentUpon>Global.asax</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="JobSchedules\OOOTrainingReportJobSchedule.cs" />
|
||||||
<Compile Include="Misc\DemoHelper.cs" />
|
<Compile Include="Misc\DemoHelper.cs" />
|
||||||
<Compile Include="Misc\Documentum.cs" />
|
<Compile Include="Misc\Documentum.cs" />
|
||||||
<Compile Include="Misc\EmailNotification.cs" />
|
<Compile Include="Misc\EmailNotification.cs" />
|
||||||
@ -248,6 +249,7 @@
|
|||||||
<Compile Include="ViewModels\LTMaterial.cs" />
|
<Compile Include="ViewModels\LTMaterial.cs" />
|
||||||
<Compile Include="ViewModels\OOOViewModel.cs" />
|
<Compile Include="ViewModels\OOOViewModel.cs" />
|
||||||
<Compile Include="ViewModels\ReportsViewModels.cs" />
|
<Compile Include="ViewModels\ReportsViewModels.cs" />
|
||||||
|
<Compile Include="Jobs\OOOTrainingReportJob.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Content\bootstrap-theme.css" />
|
<Content Include="Content\bootstrap-theme.css" />
|
||||||
@ -1966,6 +1968,9 @@
|
|||||||
<PackageReference Include="Owin">
|
<PackageReference Include="Owin">
|
||||||
<Version>1.0.0</Version>
|
<Version>1.0.0</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Quartz">
|
||||||
|
<Version>3.7.0</Version>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Respond">
|
<PackageReference Include="Respond">
|
||||||
<Version>1.2.0</Version>
|
<Version>1.2.0</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
@ -11,6 +11,7 @@ using System.Web.Security;
|
|||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using Fab2ApprovalSystem.DMO;
|
using Fab2ApprovalSystem.DMO;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
|
using Fab2ApprovalSystem.JobSchedules;
|
||||||
|
|
||||||
namespace Fab2ApprovalSystem
|
namespace Fab2ApprovalSystem
|
||||||
{
|
{
|
||||||
@ -46,7 +47,7 @@ namespace Fab2ApprovalSystem
|
|||||||
|
|
||||||
GlobalVars.hostURL = connectionstring.ToUpper().Contains("TEST") ? @"http://" + DevWebSiteUrl : @"http://" + ProdWebSiteUrl ;
|
GlobalVars.hostURL = connectionstring.ToUpper().Contains("TEST") ? @"http://" + DevWebSiteUrl : @"http://" + ProdWebSiteUrl ;
|
||||||
|
|
||||||
|
OOOTrainingReportJobSchedule.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using Fab2ApprovalSystem.Workers;
|
||||||
|
using Quartz.Impl;
|
||||||
|
using Quartz;
|
||||||
|
|
||||||
|
namespace Fab2ApprovalSystem.JobSchedules
|
||||||
|
{
|
||||||
|
public class OOOTrainingReportJobSchedule
|
||||||
|
{
|
||||||
|
public static void Start()
|
||||||
|
{
|
||||||
|
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
|
||||||
|
|
||||||
|
IScheduler scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult();
|
||||||
|
scheduler.Start();
|
||||||
|
|
||||||
|
IJobDetail oooTrainingReportJob = JobBuilder.Create<OOOTrainingReportJob>()
|
||||||
|
.WithIdentity("oooTrainingReportJob", "trainingReportGroup")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
ITrigger oooTrainingReportTrigger = TriggerBuilder.Create()
|
||||||
|
.WithIdentity("oooTrainingReportTrigger", "trainingReportGroup")
|
||||||
|
.WithCronSchedule("0 0 12 ? * 2 *")
|
||||||
|
.ForJob(oooTrainingReportJob)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
scheduler.ScheduleJob(oooTrainingReportJob, oooTrainingReportTrigger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
77
Fab2ApprovalSystem/Jobs/OOOTrainingReportJob.cs
Normal file
77
Fab2ApprovalSystem/Jobs/OOOTrainingReportJob.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Web;
|
||||||
|
using Fab2ApprovalSystem.Controllers;
|
||||||
|
using Fab2ApprovalSystem.DMO;
|
||||||
|
using Fab2ApprovalSystem.Models;
|
||||||
|
using Fab2ApprovalSystem.Utilities;
|
||||||
|
using Quartz;
|
||||||
|
|
||||||
|
namespace Fab2ApprovalSystem.Workers
|
||||||
|
{
|
||||||
|
public class OOOTrainingReportJob:IJob
|
||||||
|
{
|
||||||
|
UserAccountDMO userDMO = new UserAccountDMO();
|
||||||
|
AdminDMO adminDMO = new AdminDMO();
|
||||||
|
TrainingDMO trainingDMO = new TrainingDMO();
|
||||||
|
ECN_DMO ecnDMO = new ECN_DMO();
|
||||||
|
public EmailUtilities emailer = new EmailUtilities();
|
||||||
|
|
||||||
|
async Task IJob.Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
await Task.Run(() => {
|
||||||
|
|
||||||
|
string emailBody = "<h1>Mesa Approval Open Training Assignments Report - OOO</h1> <br />";
|
||||||
|
emailBody += "<p>The following contains open training assignments in the Mesa Approval system for out of office users.";
|
||||||
|
emailBody += " Please ensure they complete their training assignments promptly upon their return.</p><br />";
|
||||||
|
emailBody += "<style>table,th,td{border: 1px solid black;}</style>";
|
||||||
|
//Get all users set up to receive the training report email.
|
||||||
|
List<TrainingReportUser> trainingReportUsers = adminDMO.GetTrainingReportUsers();
|
||||||
|
List<string> emailList = new List<string>();
|
||||||
|
foreach (var user in trainingReportUsers)
|
||||||
|
{
|
||||||
|
string userEmail = userDMO.GetUserByID(user.UserId).Email;
|
||||||
|
emailList.Add(userEmail);
|
||||||
|
}
|
||||||
|
//emailList.Add("Chase.Tucker@infineon.com");
|
||||||
|
//Get a list of open trainings
|
||||||
|
List<Training> openTrainings = trainingDMO.GetAllOpenTrainings();
|
||||||
|
|
||||||
|
foreach (Training training in openTrainings)
|
||||||
|
{
|
||||||
|
string trainingSection = "";
|
||||||
|
int trainingSectionUserCount = 0;
|
||||||
|
string ecnTitle = ecnDMO.GetECN(training.ECN).Title;
|
||||||
|
trainingSection += "<h3>" + training.ECN + " - " + ecnTitle + "</h3>";
|
||||||
|
|
||||||
|
trainingSection += "<table>";
|
||||||
|
trainingSection += "<tr><th>Name</th><th>Date Assigned</th></tr>";
|
||||||
|
List<TrainingAssignment> openAssignments = trainingDMO.GetOpenAssignmentsByTrainingID(training.TrainingID);
|
||||||
|
foreach (TrainingAssignment assignment in openAssignments)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (userDMO.GetUserByID(assignment.UserID).OOO)
|
||||||
|
{
|
||||||
|
trainingSectionUserCount++;
|
||||||
|
|
||||||
|
DateTime? assignmentDate = assignment.DateAssigned;
|
||||||
|
|
||||||
|
string DateAssigned = assignmentDate.HasValue ? assignmentDate.Value.ToString("MM/dd/yyyy") : "<not available>";
|
||||||
|
|
||||||
|
trainingSection += "<tr><td>" + assignment.FullName + "</td><td>" + DateAssigned + "</td>";
|
||||||
|
|
||||||
|
trainingSection += "</tr>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trainingSection += "</table>";
|
||||||
|
if (trainingSectionUserCount > 0) emailBody += trainingSection;
|
||||||
|
}
|
||||||
|
string recipientEmail = "";
|
||||||
|
List<string> ccRecipients = emailList;
|
||||||
|
emailer.SendNotification("MesaFabApproval@infineon.com", ccRecipients, "Mesa Approval Open Training Report - OOO", emailBody, "Open Training Report - OOO");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
|
using Fab2ApprovalSystem.Workers;
|
||||||
using Microsoft.Owin;
|
using Microsoft.Owin;
|
||||||
using Owin;
|
using Owin;
|
||||||
|
using Quartz;
|
||||||
|
using Quartz.Impl;
|
||||||
|
|
||||||
[assembly: OwinStartupAttribute(typeof(Fab2ApprovalSystem.Startup))]
|
[assembly: OwinStartupAttribute(typeof(Fab2ApprovalSystem.Startup))]
|
||||||
namespace Fab2ApprovalSystem
|
namespace Fab2ApprovalSystem
|
||||||
@ -10,6 +13,22 @@ namespace Fab2ApprovalSystem
|
|||||||
protected void Application_Start()
|
protected void Application_Start()
|
||||||
{
|
{
|
||||||
GlobalConfiguration.Configure(WebApiConfig.Register);
|
GlobalConfiguration.Configure(WebApiConfig.Register);
|
||||||
|
|
||||||
|
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
|
||||||
|
|
||||||
|
IScheduler scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
IJobDetail oooTrainingReportJob = JobBuilder.Create<OOOTrainingReportJob>()
|
||||||
|
.WithIdentity("oooTrainingReportJob", "trainingReportGroup")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
ITrigger oooTrainingReportTrigger = TriggerBuilder.Create()
|
||||||
|
.WithIdentity("oooTrainingReportTrigger", "trainingReportGroup")
|
||||||
|
.WithCronSchedule("15 13 * * MON")
|
||||||
|
.ForJob(oooTrainingReportJob)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
scheduler.ScheduleJob(oooTrainingReportJob, oooTrainingReportTrigger);
|
||||||
}
|
}
|
||||||
public void Configuration(IAppBuilder app)
|
public void Configuration(IAppBuilder app)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user