/// <summary> /// Handles the SaveClick event of the mdRunNcoa control. This is the Start NCOA dialog. Save = Start /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void mdRunNcoa_SaveClick(object sender, EventArgs e) { Ncoa ncoa = new Ncoa(); var sparkDataConfig = Ncoa.GetSettings(); sparkDataConfig.NcoaSettings.PersonFullName = CurrentPerson != null ? CurrentPerson.FullName : null; sparkDataConfig.NcoaSettings.CurrentReportStatus = "Start"; Ncoa.SaveSettings(sparkDataConfig); using (RockContext rockContext = new RockContext()) { ServiceJob job = new ServiceJobService(rockContext).Get(Rock.SystemGuid.ServiceJob.GET_NCOA.AsGuid()); if (job != null) { var transaction = new Rock.Transactions.RunJobNowTransaction(job.Id); // Process the transaction on another thread System.Threading.Tasks.Task.Run(() => transaction.Execute()); mdGridWarning.Show(string.Format("The '{0}' job has been started.", job.Name), ModalAlertType.Information); lbStartNcoa.Enabled = false; } } mdRunNcoa.Hide(); }
/// <summary> /// Current state is complete. Check if recurring is enabled and recurring interval have been reached, /// and if so set the state back to Start. /// </summary> /// <param name="sparkDataConfig">The spark data configuration.</param> private void StatusComplete(SparkDataConfig sparkDataConfig) { if (sparkDataConfig.NcoaSettings.IsEnabled && !sparkDataConfig.NcoaSettings.LastRunDate.HasValue || (sparkDataConfig.NcoaSettings.RecurringEnabled && sparkDataConfig.NcoaSettings.LastRunDate.Value.AddDays(sparkDataConfig.NcoaSettings.RecurrenceInterval) < RockDateTime.Now)) { sparkDataConfig.NcoaSettings.CurrentReportStatus = "Start"; sparkDataConfig.NcoaSettings.PersonFullName = null; Ncoa.SaveSettings(sparkDataConfig); StatusStart(sparkDataConfig); } }
/// <summary> /// Handles the SaveClick event of the mdRunNcoa control. This is the Start NCOA dialog. Save = Start /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void mdRunNcoa_SaveClick(object sender, EventArgs e) { Ncoa ncoa = new Ncoa(); var sparkDataConfig = Ncoa.GetSettings(); sparkDataConfig.NcoaSettings.PersonFullName = CurrentPerson != null ? CurrentPerson.FullName : null; sparkDataConfig.NcoaSettings.CurrentReportStatus = "Start"; Ncoa.SaveSettings(sparkDataConfig); using (RockContext rockContext = new RockContext()) { ServiceJob job = new ServiceJobService(rockContext).Get(Rock.SystemGuid.ServiceJob.GET_NCOA.AsGuid()); if (job != null) { new ProcessRunJobNow.Message { JobId = job.Id }.Send(); mdGridWarning.Show(string.Format("The '{0}' job has been started.", job.Name), ModalAlertType.Information); lbStartNcoa.Enabled = false; } } mdRunNcoa.Hide(); }
/// <summary> /// Job to get a National Change of Address (NCOA) report for all active people's addresses. /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { Exception exception = null; // Get the job setting(s) JobDataMap dataMap = context.JobDetail.JobDataMap; SparkDataConfig sparkDataConfig = Ncoa.GetSettings(); if (!sparkDataConfig.NcoaSettings.IsEnabled || !sparkDataConfig.NcoaSettings.IsValid()) { return; } try { Guid?sparkDataApiKeyGuid = sparkDataConfig.SparkDataApiKey.AsGuidOrNull(); if (sparkDataApiKeyGuid == null) { exception = new Exception($"Spark Data Api Key '{sparkDataConfig.SparkDataApiKey.ToStringSafe()}' is empty or invalid. The Spark Data Api Key can be configured in System Settings > Spark Data Settings."); return; } switch (sparkDataConfig.NcoaSettings.CurrentReportStatus) { case "": case null: if (sparkDataConfig.NcoaSettings.RecurringEnabled) { StatusStart(sparkDataConfig); } break; case "Start": StatusStart(sparkDataConfig); break; case "Failed": StatusFailed(sparkDataConfig); break; case "Pending: Report": StatusPendingReport(sparkDataConfig); break; case "Pending: Export": StatusPendingExport(sparkDataConfig); break; case "Complete": StatusComplete(sparkDataConfig); break; } } catch (Exception ex) { exception = ex; } finally { if (exception != null) { context.Result = $"NCOA Job failed: {exception.Message}"; sparkDataConfig.NcoaSettings.CurrentReportStatus = "Failed"; sparkDataConfig.Messages.Add($"NOCA job failed: {RockDateTime.Now.ToString()} - {exception.Message}"); Ncoa.SaveSettings(sparkDataConfig); try { var ncoa = new Ncoa(); ncoa.SentNotification(sparkDataConfig, "failed"); } catch { } if (sparkDataConfig.SparkDataApiKey.IsNotNullOrWhiteSpace() && sparkDataConfig.NcoaSettings.FileName.IsNotNullOrWhiteSpace()) { SparkDataApi sparkDataApi = new SparkDataApi(); } Exception ex = new AggregateException("NCOA job failed.", exception); HttpContext context2 = HttpContext.Current; ExceptionLogService.LogException(ex, context2); throw ex; } else { string msg; if (sparkDataConfig.NcoaSettings.CurrentReportStatus == "Complete") { using (RockContext rockContext = new RockContext()) { NcoaHistoryService ncoaHistoryService = new NcoaHistoryService(rockContext); msg = $"NCOA request processed, {ncoaHistoryService.Count()} {(ncoaHistoryService.Count() == 1 ? "address" : "addresses")} processed, {ncoaHistoryService.MovedCount()} {(ncoaHistoryService.MovedCount() > 1 ? "were" : "was")} marked as 'moved'"; } } else { msg = $"Job complete. NCOA status: {sparkDataConfig.NcoaSettings.CurrentReportStatus}"; } context.Result = msg; sparkDataConfig.Messages.Add($"{msg}: {RockDateTime.Now.ToString()}"); Ncoa.SaveSettings(sparkDataConfig); } } }