public JobLog Delete(JobLog entity) { using (_connection = Utilities.GetProfiledOpenConnection()) { _connection.Delete(entity); } return entity; }
public JobLog SaveOrUpdate(JobLog entity) { using (_connection = Utilities.GetProfiledOpenConnection()) { if (entity.JobLogId > 0) { entity.JobLogId = _connection.Update(entity); } else { var insert = _connection.Insert(entity); entity.JobLogId = (int)insert; } return entity; } }
public void MorningMessage(object model, int id) { var peopletoreceivemail = _userLogic.GetList(new { SendMail1 = true }); var todayschoices = _restaurantOptionLogic.GetAndSaveOptions().ToList(); var fromaddress = System.Configuration.ConfigurationManager.AppSettings.Get("FromEmail"); //send email to each person who is eligible foreach (var user in peopletoreceivemail) { var baseurl = System.Configuration.ConfigurationManager.AppSettings.Get("BaseURL"); var link = string.Format("{0}?GUID={1}", baseurl, user.Guid); var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); var template = File.ReadAllText(new Uri(path + "/Views/_MailTemplates/Morning.cshtml").AbsolutePath); var messagemodel = new MailDetails() { User = user, Restaurants = todayschoices, Url = link, BaseUrl = baseurl }; string result = Razor.Parse(template, messagemodel); Helpers.SendMail(user.Email, fromaddress, "What's for Lunch - Message of the day", result); //add log var entity = new JobLog() { JobId = id, Category = "MorningMessage", Message = string.Format("Morning message sent to {0}", user.FullName) }; _jobLogLogic.SaveOrUpdate(entity); } }
private void CreateWhereAreWeGoingJob() { var job = new Job() { CreatedDate = DateTime.Now, MethodName = "WhereAreWeGoingMessage", ParametersJson = "{}", RunDate = Core.Helpers.AdjustTimeOffsetToUtc(DateTime.Today.AddHours(11).AddMinutes(15)) }; var _jobLogic = ObjectFactory.GetInstance<IJobLogic>(); _jobLogic.SaveOrUpdate(job); //add log var _jobLogLogic = ObjectFactory.GetInstance<IJobLogLogic>(); var entity = new JobLog() { JobId = 0, Category = "System", Message = "Create where are we going is over mail job" }; _jobLogLogic.SaveOrUpdate(entity); }
public void RunJob(string methodname, string parameters, int id) { var calledType = Type.GetType("Lunch.Core.Jobs.Jobs"); if (calledType != null) { var methods = calledType.GetMethods(BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public); foreach (var method in methods) { if (method.Name == methodname) { object jobsInstance = ObjectFactory.GetInstance(calledType); calledType.InvokeMember(methodname, BindingFlags.InvokeMethod| BindingFlags.Public | BindingFlags.Instance, null, jobsInstance, new object[] { parameters, id }); break; } } } else { //add log var _jobLogLogic = ObjectFactory.GetInstance<IJobLogLogic>(); var entity = new JobLog() { JobId = 0, Category = "Error" , Message=string.Format("Running job {0} failed",methodname) }; _jobLogLogic.SaveOrUpdate(entity); } }
public void Execute(IJobExecutionContext context) { try { Core.Jobs.Helpers.Keepalive(); //Check to see if today is a lunch day if (Core.Jobs.Helpers.IsLunchDate(Core.Helpers.AdjustTimeOffsetFromUtc(DateTime.UtcNow))) { //add log var _jobLogLogic = ObjectFactory.GetInstance<IJobLogLogic>(); var entity = new JobLog() { JobId = 0, Category = "System", Message = "Running recurring job" }; _jobLogLogic.SaveOrUpdate(entity); var _jobLogic = ObjectFactory.GetInstance<IJobLogic>(); var jobsfortoday = _jobLogic.GetAll() .Where(f => f.RunDate.ToShortDateString() == Core.Helpers.AdjustTimeOffsetFromUtc(DateTime.UtcNow).ToShortDateString()) .ToList(); //Check to see if there are jobs in the db for today //if not add jobs if (jobsfortoday.Count == 0) { new Core.Jobs.Helpers().CreateJobs(); entity = new JobLog() { JobId = 0, Category = "System", Message = "Creating Jobs" }; _jobLogLogic.SaveOrUpdate(entity); } //check to see if any tasks exist that need to run now //run those jobs and log actions //Todo: should create a logic method to get all that has not run var jobstorun = _jobLogic.GetAll().Where(f => f.RunDate < DateTime.UtcNow && f.HasRun == false); foreach (var job in jobstorun) { ObjectFactory.GetInstance<Core.Jobs.Helpers>().RunJob(job.MethodName, job.ParametersJson, job.Id); job.HasRun = true; _jobLogic.SaveOrUpdate(job); entity = new JobLog() { JobId = 0, Category = "System", Message = string.Format("Running Job {0}", job.MethodName) }; _jobLogLogic.SaveOrUpdate(entity); } } } catch (Exception ex) { var _jobLogLogic = ObjectFactory.GetInstance<IJobLogLogic>(); var entity = new JobLog() { JobId = 0, Category = "Error", Message = string.Format("Error in job execution: {0}", ex.Message) }; _jobLogLogic.SaveOrUpdate(entity); } }
public void VotingIsOverMessage(object model, int id) { var peopletoreceivemail = _userLogic.GetList(new { SendMail2 = true }); var todayschoices = _restaurantOptionLogic.GetAllByDate(null).OrderByDescending(f => f.Votes).Take(2).ToList(); var fromaddress = System.Configuration.ConfigurationManager.AppSettings.Get("FromEmail"); var allvetos = _vetoLogic.GetAllActive().ToList(); //send email to each person who is eligible foreach (var user in peopletoreceivemail) { //abort sending this message if the current user has no veto powers if (allvetos.All(f => f.UserId != user.Id)) continue; var baseurl = System.Configuration.ConfigurationManager.AppSettings.Get("BaseURL"); var link = string.Format("{0}?GUID={1}", baseurl, user.Guid); var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); var template = File.ReadAllText(new Uri(path + "/Views/_MailTemplates/VotingOver.cshtml").AbsolutePath); var messagemodel = new MailDetails() { User = user, Restaurants = todayschoices, Url = link, BaseUrl = baseurl }; string result = Razor.Parse(template, messagemodel); Helpers.SendMail(user.Email, fromaddress, "What's for Lunch - Veto Option", result); //add log var entity = new JobLog() { JobId = id, Category = "VotingIsOverMessage", Message = string.Format("Voting is over message sent to {0}", user.FullName) }; _jobLogLogic.SaveOrUpdate(entity); } }