コード例 #1
0
        /// <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();
        }
コード例 #2
0
        /// <summary>
        /// Gets the settings.
        /// </summary>
        private void GetSettings()
        {
            // Get Spark Data settings
            _sparkDataConfig = Ncoa.GetSettings();
            if (_sparkDataConfig.SparkDataApiKey.IsNullOrWhiteSpace())
            {
                pnlSparkDataEdit.Visible    = false;
                pnlSignIn.Visible           = true;
                pnlAccountStatus.Visible    = false;
                pwNcoaConfiguration.Visible = false;
                bbtnNcoaSaveConfig.Visible  = false;

                txtSparkDataApiKeyLogin.Text      = _sparkDataConfig.SparkDataApiKey;
                grpNotificationGroupLogin.GroupId = _sparkDataConfig.GlobalNotificationApplicationGroupId;
            }
            else
            {
                pnlSparkDataEdit.Visible    = false;
                pnlSignIn.Visible           = false;
                pnlAccountStatus.Visible    = true;
                pwNcoaConfiguration.Visible = true;
                bbtnNcoaSaveConfig.Visible  = true;

                // Get NCOA configuration settings
                nbNcoaMinMoveDistance.Text             = Rock.Web.SystemSettings.GetValue(SystemSetting.NCOA_MINIMUM_MOVE_DISTANCE_TO_INACTIVATE);
                cbNcoa48MonAsPrevious.Checked          = Rock.Web.SystemSettings.GetValue(SystemSetting.NCOA_SET_48_MONTH_AS_PREVIOUS).AsBoolean();
                cbNcoaInvalidAddressAsPrevious.Checked = Rock.Web.SystemSettings.GetValue(SystemSetting.NCOA_SET_INVALID_AS_PREVIOUS).AsBoolean();

                txtSparkDataApiKeyEdit.Text      = _sparkDataConfig.SparkDataApiKey;
                grpNotificationGroupEdit.GroupId = _sparkDataConfig.GlobalNotificationApplicationGroupId;

                // Get NCOA settings
                if (_sparkDataConfig.NcoaSettings == null)
                {
                    _sparkDataConfig.NcoaSettings = new NcoaSettings();
                }

                dvpNcoaPersonDataView.SetValue(_sparkDataConfig.NcoaSettings.PersonDataViewId);
                cbNcoaRecurringEnabled.Checked   = _sparkDataConfig.NcoaSettings.RecurringEnabled;
                nbNcoaRecurrenceInterval.Enabled = _sparkDataConfig.NcoaSettings.RecurringEnabled;
                nbNcoaRecurrenceInterval.Text    = _sparkDataConfig.NcoaSettings.RecurrenceInterval.ToStringSafe();
                cbNcoaAcceptTerms.Checked        = _sparkDataConfig.NcoaSettings.IsAcceptedTerms;
                cbNcoaAckPrice.Checked           = _sparkDataConfig.NcoaSettings.IsAckPrice;
                if (_sparkDataConfig.NcoaSettings.InactiveRecordReasonId.HasValue)
                {
                    dvpNcoaInactiveRecordReason.SetValue(_sparkDataConfig.NcoaSettings.InactiveRecordReasonId.Value);
                }

                nbNcoaCreditCard.Visible = false;

                if (_sparkDataConfig.NcoaSettings.CurrentReportStatus == null)
                {
                    _sparkDataConfig.NcoaSettings.CurrentReportStatus = string.Empty;
                }

                if (_sparkDataConfig.SparkDataApiKey.IsNullOrWhiteSpace())
                {
                    pnlSignIn.Visible        = true;
                    pnlSparkDataEdit.Visible = false;
                }
                else
                {
                    pnlSignIn.Visible = false;
                    bool accountValid = false;

                    SparkDataApi sparkDataApi = new SparkDataApi();
                    try
                    {
                        var accountStatus = sparkDataApi.CheckAccount(_sparkDataConfig.SparkDataApiKey);
                        switch (accountStatus)
                        {
                        case SparkDataApi.AccountStatus.AccountNoName:
                            hlAccountStatus.LabelType = LabelType.Warning;
                            hlAccountStatus.Text      = "Account does not have a name";
                            break;

                        case SparkDataApi.AccountStatus.AccountNotFound:
                            hlAccountStatus.LabelType = LabelType.Warning;
                            hlAccountStatus.Text      = "Account not found";
                            break;

                        case SparkDataApi.AccountStatus.Disabled:
                            hlAccountStatus.LabelType = LabelType.Warning;
                            hlAccountStatus.Text      = "Disabled";
                            break;

                        case SparkDataApi.AccountStatus.EnabledCardExpired:
                            hlAccountStatus.LabelType = LabelType.Danger;
                            hlAccountStatus.Text      = "Enabled - Card expired";
                            break;

                        case SparkDataApi.AccountStatus.EnabledNoCard:
                            hlAccountStatus.LabelType = LabelType.Warning;
                            hlAccountStatus.Text      = "Enabled - No card on file";
                            nbNcoaCreditCard.Visible  = true;
                            break;

                        case SparkDataApi.AccountStatus.EnabledCard:
                            hlAccountStatus.LabelType = LabelType.Success;
                            hlAccountStatus.Text      = "Enabled - Card on file";
                            accountValid = true;
                            break;

                        case SparkDataApi.AccountStatus.InvalidSparkDataKey:
                            hlAccountStatus.LabelType = LabelType.Warning;
                            hlAccountStatus.Text      = "Invalid Spark Data Key";
                            break;

                        case SparkDataApi.AccountStatus.EnabledCardNoExpirationDate:
                            hlAccountStatus.LabelType = LabelType.Warning;
                            hlAccountStatus.Text      = "Enabled - Card expiration date not on file";
                            break;
                        }

                        string cost = sparkDataApi.GetPrice("CF20766E-80F9-E282-432F-6A9E19F0BFF1");
                        cbNcoaAckPrice.Text = cbNcoaAckPrice.Text.Replace("$xx", "$" + cost);
                    }
                    catch
                    {
                        hlAccountStatus.LabelType = LabelType.Danger;
                        hlAccountStatus.Text      = "Error connecting to Spark server";
                    }

                    cbNcoaConfiguration.Checked = _sparkDataConfig.NcoaSettings.IsEnabled && accountValid;
                    cbNcoaConfiguration.Enabled = accountValid;
                    SetStartNcoaEnabled();
                    SetPanels();
                }
            }
        }
コード例 #3
0
        /// <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);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Current state is pending export report. Try to resume a pending export report.
        /// </summary>
        /// <param name="sparkDataConfig">The spark data configuration.</param>
        private void StatusPendingExport(SparkDataConfig sparkDataConfig)
        {
            var ncoa = new Ncoa();

            ncoa.PendingExport(sparkDataConfig);
        }
コード例 #5
0
        /// <summary>
        /// Current State is Failed. If recurring is enabled, retry.
        /// </summary>
        /// <param name="sparkDataConfig">The spark data configuration.</param>
        private void StatusFailed(SparkDataConfig sparkDataConfig)
        {
            var ncoa = new Ncoa();

            ncoa.Start(sparkDataConfig);
        }
コード例 #6
0
        /// <summary>
        /// Handles the ItemCommand event of the rptNcoaResults control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterCommandEventArgs"/> instance containing the event data.</param>
        protected void rptNcoaResults_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            var ncoaHistoryId = e.CommandArgument.ToStringSafe().AsIntegerOrNull();

            if (!ncoaHistoryId.HasValue)
            {
                return;
            }

            if (e.CommandName == "MarkAddressAsPrevious")
            {
                using (var rockContext = new RockContext())
                {
                    var ncoaHistory = new NcoaHistoryService(rockContext).Get(ncoaHistoryId.Value);
                    if (ncoaHistory != null)
                    {
                        var groupService         = new GroupService(rockContext);
                        var groupLocationService = new GroupLocationService(rockContext);

                        var changes = new History.HistoryChangeList();

                        Ncoa ncoa                  = new Ncoa();
                        var  previousValue         = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_PREVIOUS.AsGuid());
                        int? previousValueId       = previousValue == null ? ( int? )null : previousValue.Id;
                        var  previousGroupLocation = ncoa.MarkAsPreviousLocation(ncoaHistory, groupLocationService, previousValueId, changes);
                        if (previousGroupLocation != null)
                        {
                            ncoaHistory.Processed = Processed.Complete;

                            // If there were any changes, write to history
                            if (changes.Any())
                            {
                                var family = groupService.Get(ncoaHistory.FamilyId);
                                if (family != null)
                                {
                                    foreach (var fm in family.Members)
                                    {
                                        HistoryService.SaveChanges(
                                            rockContext,
                                            typeof(Person),
                                            Rock.SystemGuid.Category.HISTORY_PERSON_FAMILY_CHANGES.AsGuid(),
                                            fm.PersonId,
                                            changes,
                                            family.Name,
                                            typeof(Group),
                                            family.Id,
                                            false);
                                    }
                                }
                            }
                        }
                    }

                    rockContext.SaveChanges();
                }
            }
            else if (e.CommandName == "MarkProcessed")
            {
                using (RockContext rockContext = new RockContext())
                {
                    var ncoa = (new NcoaHistoryService(rockContext)).Get(ncoaHistoryId.Value);
                    ncoa.Processed = Processed.Complete;
                    rockContext.SaveChanges();
                }
            }

            NcoaResults_BlockUpdated(null, null);
        }