/// <summary> /// Called by the <see cref="T:Quartz.IScheduler"/> when a <see cref="T:Quartz.ITrigger"/> /// fires that is associated with the <see cref="T:Quartz.IJob"/>. /// </summary> /// <remarks> /// The implementation may wish to set a result object on the /// JobExecutionContext before this method exits. The result itself /// is meaningless to Quartz, but may be informative to /// <see cref="T:Quartz.IJobListener"/>s or /// <see cref="T:Quartz.ITriggerListener"/>s that are watching the job's /// execution. /// </remarks> /// <param name="context">The execution context.</param> public bool Execute(JobExecutionContext context) { _log.DebugFormat("job Execute - {0}", Utility.GetMethodDescription()); try { // ========================================================== // Loop per tutti i gruppi azienda // ========================================================== var gruppiAziende = SferaAziendeCache.Instance.Aziende.GroupBy(item => item.Gruppo); var gruppi = gruppiAziende.Aggregate(string.Empty, (current, gru) => current + (gru.Key + "; ")); _log.DebugFormat("Inizio INVIO MAIL - {0} - gruppi:{1}", Utility.GetMethodDescription(), gruppi); foreach (var item in gruppiAziende) { _log.DebugFormat("Inizio GRUPPO - {0} - gruppo:{1}", Utility.GetMethodDescription(), item.Key); var container = getContainerFromKey(item.Key); var daoFactory = container.Resolve<IDaoFactory>(); _mailSenderService.SendMails(daoFactory); _log.DebugFormat("Fine GRUPPO - {0} - gruppo:{1}", Utility.GetMethodDescription(), item.Key); } _log.DebugFormat("Fine INVIO MAIL - {0} - gruppi:{1}", Utility.GetMethodDescription(), gruppi); } catch (Exception e) { _log.Error(" Quartz job throw an exeption", e); throw; } _log.DebugFormat("job Finish - {0}", Utility.GetMethodDescription()); return true; }
public bool Execute(JobExecutionContext context) { try { _log.DebugFormat("Iniziata l'esecuzione della funzione di lettura info messaggi - {0}", Library.Utility.GetMethodDescription()); try { // ========================================================== // Gruppi di aziende // ========================================================== var gruppiAziende = SferaAziendeCache.Instance.Aziende.GroupBy(item => item.Gruppo); foreach (var item in gruppiAziende) { try { var container = getContainerFromKey(item.Key); var daoFactory = container.Resolve<IDaoFactory>(); foreach (var messageService in _messageServices) { try { messageService.SetDaoFactory(daoFactory); messageService.GetInfoMessaggio(null, null); daoFactory.GetStoricoMessaggioDao().CommitChanges(); } catch (Exception ex) { _log.ErrorFormat("Controllo info messaggio - SINGOLO SERVICE - {0} - messageService:{1}", ex, Library.Utility.GetMethodDescription(), messageService.ToString()); throw; } } } catch (Exception ex) { _log.ErrorFormat("Controllo info messaggio - SINGOLA KEY - {0} - key:{1}", ex, Library.Utility.GetMethodDescription(), item.Key); throw; } } } catch (Exception ex) { _log.Error("Notify: Errore generico", ex); return false; } return true; } catch (Exception ex) { _log.Error(string.Format("Errore inaspettato durante la lettura delle info dei messaggi - {0}", Library.Utility.GetMethodDescription()), ex); return false; } }
/// <inheritdoc /> public IAsyncResult BeginExecute(JobExecutionContext context, AsyncCallback asyncCallback, object asyncState) { Logger.Debug("Beginning execute"); IJob job; try { job = jobFactory.GetJob(context.JobSpec.JobKey); Logger.Debug("Getting the job " + context.JobSpec.Name); } catch (Exception ex) { throw new SchedulerException(String.Format(CultureInfo.CurrentCulture, "The job factory failed to construct a job instance for job key '{0}' " + "associated with job '{1}'.", context.JobSpec.JobKey, context.JobSpec.Name), ex); } return new JobAsyncResult(job, asyncCallback, context, asyncState); }
public JobAsyncResult(IJob job, AsyncCallback asyncCallback, JobExecutionContext context, object asyncState) { this.job = job; this.executeDelegate = job.Execute; this.asyncCallback = asyncCallback; this.asyncState = asyncState; inner = executeDelegate.BeginInvoke(context, Callback, asyncState); }
public bool Execute(JobExecutionContext context) { try { var result = controlliSertea(); // =================================================================================================== // Controlli EMAIL // =================================================================================================== // --------------------------------- // Loop per tutti i gruppi azienda // --------------------------------- var gruppiAziendeMail = SferaAziendeCache.Instance.Aziende.GroupBy(item => item.Gruppo); var rapportiniNotifica = _mailService.GetEmailByMessageId(null, null, Hostname, 110, Username, Password); foreach (var item in gruppiAziendeMail) { var container = getContainerFromKey(item.Key); var daoFactory = container.Resolve<IDaoFactory>(); var messaggi = daoFactory.GetStoricoMessaggioDao().GetAllDaConfermare(TipoMessaggio.Email); foreach (var storicoMessaggio in messaggi) { var messaggiInviati = rapportiniNotifica.Where(rapp => rapp.Value.Contains(storicoMessaggio.CodiceMessaggio)).ToList(); if (messaggiInviati.Count > 0) { _messaggisticaService.SetDaoFactory(daoFactory); foreach (var kvp in messaggiInviati) { storicoMessaggio.Stato = StatoMessaggio.Ricevuto; storicoMessaggio.DataRicezione = DateTime.Now; _messaggisticaService.SetConfermaRicezioneNotifica(storicoMessaggio.CodiceMessaggio, kvp.Value); } } } daoFactory.GetStoricoMessaggioDao().CommitChanges(); } return result; } catch (IOException ex) { _log.Error("Errore inaspettato durante l'accesso al server per il controllo dei rapportini - " + Utility.GetMethodDescription(), ex); return false; } }
public JobExecuteAsyncState(JobDetails jobDetails, JobExecutionContext context) { JobDetails = jobDetails; Context = context; }
private void BeginExecuteJob(JobDetails jobDetails) { ILogger jobLogger = logger.CreateChildLogger("Job: " + jobDetails.JobSpec.Name); JobExecutionContext context = new JobExecutionContext(this, jobLogger, jobDetails.JobSpec, jobDetails.JobSpec.JobData); try { jobLogger.InfoFormat("Job '{0}' started at {1}.", jobDetails.JobSpec.Name, jobDetails.LastJobExecutionDetails.StartTimeUtc); JobExecuteAsyncState asyncState = new JobExecuteAsyncState(jobDetails, context); jobRunner.BeginExecute(context, EndExecuteJob, asyncState); } catch (Exception ex) { DateTime endTime = DateTime.UtcNow; jobLogger.ErrorFormat(ex, "Job '{0}' failed because the job runner could not start it.", jobDetails.JobSpec.Name); jobDetails.LastJobExecutionDetails.Succeeded = false; jobDetails.LastJobExecutionDetails.EndTimeUtc = endTime; jobDetails.LastJobExecutionDetails.StatusMessage = String.Format(CultureInfo.CurrentCulture, "Job runner failed to start the job due to an exception:\n{0}", ex); jobDetails.JobState = JobState.Completed; jobStore.SaveJobDetails(jobDetails); } }
public bool Execute(JobExecutionContext context) { try { // ========================================================== // Gruppi di aziende // ========================================================== var gruppiAziende = SferaAziendeCache.Instance.Aziende.GroupBy(item => item.Gruppo); foreach (var item in gruppiAziende) { _log.DebugFormat("Inizio ALERT PREMIO: {0}", item.Key); var container = getContainerFromKey(item.Key); var daoFactory = container.Resolve<IDaoFactory>(); _messageService = container.Resolve<IMessageService>("messageservice.email"); _messageService.SetDaoFactory(daoFactory); var impostazioniAzienda = daoFactory.GetImpostazioniAziendaDao().GetAll(); var alertDao = daoFactory.GetAlertPremioContrattoDao(); var alertColl = alertDao.GetAll(); foreach (var alert in alertColl) { if (alert.ToNotify) { try { var impostazioneAzienda = impostazioniAzienda.FirstOrDefault(imp => imp.Azienda.ID == alert.ContrattoRiferimento.CondominioRiferimento.Azienda.ID); if(impostazioneAzienda == null || impostazioneAzienda.AlertScadenzaPremioContrattoAbilitato) notifySingleAlert(alert, daoFactory); } catch (Exception ex) { _log.ErrorFormat("Notify: Errore Alert PREMIO - Vedi messaggio successivo per dettagli - {0}", ex, Library.Utility.GetMethodDescription()); _log.ErrorFormat("Notify: Errore Alert PREMIO - {0} - contratto:{1} - alert:{2} - azienda:{3}", ex, Library.Utility.GetMethodDescription(), alert.ContrattoRiferimento.ID, alert.ID, alert.ContrattoRiferimento.CondominioRiferimento.Azienda.ID); } } } _log.DebugFormat("Inizio ALERT SCADENZA: {0}", item.Key); var alertContrattoDao = daoFactory.GetAlertScadenzaContrattoDao(); var alertContrattoColl = alertContrattoDao.GetAll(); foreach (var alert in alertContrattoColl) { if (alert.ToNotify) { try { var impostazioneAzienda = impostazioniAzienda.FirstOrDefault(imp => imp.Azienda.ID == alert.ContrattoRiferimento.CondominioRiferimento.Azienda.ID); if (impostazioneAzienda == null || impostazioneAzienda.AlertScadenzaContrattoAbilitato) notifySingleAlert(alert, daoFactory); } catch (Exception ex) { _log.ErrorFormat("Notify: Errore Alert CONTRATTO - Vedi messaggio successivo per dettagli - {0}", ex, Library.Utility.GetMethodDescription()); _log.ErrorFormat("Notify: Errore Alert CONTRATTO - {0} - contratto:{1} - alert:{2} - azienda:{3}", ex, Library.Utility.GetMethodDescription(), alert.ContrattoRiferimento.ID, alert.ID, alert.ContrattoRiferimento.CondominioRiferimento.Azienda.ID); } } } _log.DebugFormat("Inizio ALERT ATTIVITA': {0}", item.Key); var listaAlertAttivita = daoFactory.GetAlertAttivitaDao().GetAll(); foreach (var alert in listaAlertAttivita) { if (alert.ToNotify) { try { var impostazioneAzienda = impostazioniAzienda.FirstOrDefault(imp => imp.Azienda.ID == alert.Attivita.AziendaID); if (impostazioneAzienda == null || impostazioneAzienda.AlertAttivitaAbilitato) notifySingleAlert(alert, daoFactory); } catch (Exception ex) { _log.ErrorFormat("Notify: Errore Alert ATTIVITA' - Vedi messaggio successivo per dettagli - {0}", ex, Library.Utility.GetMethodDescription()); _log.ErrorFormat("Notify: Errore Alert ATTIVITA' - {0} - attività:{1} - alert:{2} - azienda:{3}", ex, Library.Utility.GetMethodDescription(), alert.Attivita.ID, alert.ID, alert.Attivita.AziendaID); } } } _log.DebugFormat("Inizio FINE: {0}", item.Key); daoFactory.GetAlertAttivitaDao().CommitChanges(); _delivery = null; } } catch (Exception ex) { _log.Error("Notify: Errore generico", ex); return false; } _log.InfoFormat("Notify: Notifica alert terminata con successo il: {0} - Ora:{1}", DateTime.Today.ToShortDateString(), DateTime.Now.ToShortTimeString()); return true; }