示例#1
0
    /// <summary>
    /// Validates and returns selected schedule interval.
    /// </summary>
    private ObjectParameters GetValidScheduleInterval()
    {
        if (!editForm.StopProcessing)
        {
            if (ucScheduleInterval.ScheduleInterval == String.Empty)
            {
                ShowError(GetString("ma.trigger.invalidinterval"));
                editForm.StopProcessing = true;
            }

            if (!DataTypeManager.IsValidDate(ucScheduleInterval.StartTime.SelectedDateTime))
            {
                ShowError($"{GetString("BasicForm.ErrorInvalidDateTime")} {DateTime.Now}.");
                editForm.StopProcessing = true;
            }

            if (!ucScheduleInterval.CheckOneDayMinimum())
            {
                ShowError(GetString("ma.trigger.nodayselected"));
                editForm.StopProcessing = true;
            }
        }

        var triggerParameters = new ObjectParameters();

        triggerParameters.SetValue(TriggerDataConstants.TRIGGER_DATA_INTERVAL, ucScheduleInterval.ScheduleInterval);

        return(triggerParameters);
    }
示例#2
0
    /// <summary>
    /// Schedules mail-out of the issue to the future.
    /// </summary>
    private bool SendScheduled()
    {
        if (DataTypeManager.IsValidDate(calendarControl.SelectedDateTime))
        {
            RemovePreviousTaskAndSendIssue(calendarControl.SelectedDateTime);
        }
        else
        {
            ErrorMessage = GetString("newsletter.incorrectdate");
        }

        return(String.IsNullOrEmpty(ErrorMessage));
    }
示例#3
0
    /// <summary>
    /// Saves configuration changes.
    /// </summary>
    protected void SaveData()
    {
        // Check "configure" permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.newsletter", "configure"))
        {
            RedirectToAccessDenied("cms.newsletter", "configure");
        }

        string scheduledInterval = null;

        if (isDynamic && chkSchedule.Checked)
        {
            // Get scheduled interval for dynamic newsletter
            scheduledInterval = schedulerInterval.ScheduleInterval;
        }

        string errorMessage = ValidateNewsletterValues();

        if (!string.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
            return;
        }

        NewsletterInfo newsletterObj = NewsletterInfoProvider.GetNewsletterInfo(txtNewsletterName.Text.Trim(), SiteContext.CurrentSiteID);

        // Newsletter's code name must be unique
        if (newsletterObj != null && newsletterObj.NewsletterID != EditedNewsletter.NewsletterID)
        {
            ShowError(GetString("Newsletter_Edit.NewsletterNameExists"));
            return;
        }

        if (newsletterObj == null)
        {
            newsletterObj = NewsletterInfoProvider.GetNewsletterInfo(EditedNewsletter.NewsletterID);
        }

        SetNewsletterValues(newsletterObj);

        // Check if subscription template was selected
        int subscriptionTemplateValue = ValidationHelper.GetInteger(subscriptionTemplate.Value, 0);

        if (EditedFeedIsNewsletter() && subscriptionTemplateValue == 0)
        {
            ShowError(GetString("Newsletter_Edit.NoSubscriptionTemplateSelected"));
            return;
        }
        newsletterObj.NewsletterSubscriptionTemplateID = subscriptionTemplateValue;

        // Check if double opt-in template was selected
        if (chkEnableOptIn.Checked)
        {
            int optInTemplateValue = ValidationHelper.GetInteger(optInSelector.Value, 0);
            if (optInTemplateValue == 0)
            {
                ShowError(GetString("Newsletter_Edit.NoOptInTemplateSelected"));
                return;
            }
            newsletterObj.NewsletterOptInTemplateID = optInTemplateValue;
        }
        else
        {
            newsletterObj.NewsletterOptInTemplateID = 0;
        }

        // Check if unsubscription template was selected
        int unsubscriptionTemplateValue = ValidationHelper.GetInteger(unsubscriptionTemplate.Value, 0);

        if (unsubscriptionTemplateValue == 0)
        {
            ShowError(GetString("Newsletter_Edit.NoUnsubscriptionTemplateSelected"));
            return;
        }
        newsletterObj.NewsletterUnsubscriptionTemplateID = unsubscriptionTemplateValue;

        // ID of scheduled task which should be deleted
        int deleteScheduledTaskId = 0;

        if (isDynamic)
        {
            newsletterObj.NewsletterSource         = NewsletterSource.Dynamic;
            newsletterObj.NewsletterDynamicURL     = txtNewsletterDynamicURL.Value.ToString();
            newsletterObj.NewsletterDynamicSubject = radFollowing.Checked ? txtSubject.Text : string.Empty;

            if ((String.IsNullOrEmpty(txtNewsletterDynamicURL.Value.ToString())))
            {
                // Dynamic URL cannot be empty
                ShowError(GetString("newsletter_edit.sourcepageurlempty"));
                return;
            }

            if (chkSchedule.Checked)
            {
                if (!schedulerInterval.CheckOneDayMinimum())
                {
                    // If problem occurred while setting schedule interval
                    ShowError(GetString("Newsletter_Edit.NoDaySelected"));
                    return;
                }

                TaskInterval taskInterval = SchedulingHelper.DecodeInterval(scheduledInterval);
                if (!DataTypeManager.IsValidDate(taskInterval.StartTime))
                {
                    ShowError(GetString("Newsletter.IncorrectDate"));
                    return;
                }

                UpdateDynamicNewsletterTask(newsletterObj, taskInterval);
            }
            else
            {
                if (newsletterObj.NewsletterDynamicScheduledTaskID > 0)
                {
                    // Store task ID for deletion
                    deleteScheduledTaskId = newsletterObj.NewsletterDynamicScheduledTaskID;
                }
                newsletterObj.NewsletterDynamicScheduledTaskID = 0;
                schedulerInterval.Visible = false;
            }
        }
        else
        {
            newsletterObj.NewsletterSource = NewsletterSource.TemplateBased;

            // Check if at least one template is selected
            if (string.IsNullOrEmpty(ValidationHelper.GetString(usTemplates.Value, null)))
            {
                ShowError(GetString("Newsletter_Edit.NoEmailTemplateSelected"));
                usTemplates.Value = mCurrentTemplates;
                return;
            }
            SaveTemplates();
        }

        // Save changes to DB
        NewsletterInfoProvider.SetNewsletterInfo(newsletterObj);
        if (deleteScheduledTaskId > 0)
        {
            // Delete scheduled task if schedule mail-outs were unchecked
            TaskInfoProvider.DeleteTaskInfo(deleteScheduledTaskId);
        }

        ShowChangesSaved();

        // Update breadcrumbs
        ScriptHelper.RefreshTabHeader(Page, newsletterObj.NewsletterDisplayName);
    }
示例#4
0
    /// <summary>
    /// OnAfterSave event handler.
    /// </summary>
    protected void EditForm_OnAfterSave(object sender, EventArgs e)
    {
        // Get edited contact group
        ContactGroupInfo cgi = (ContactGroupInfo)EditForm.EditedObject;

        if (chkDynamic.Checked)
        {
            // Set info for scheduled task
            task = GetScheduledTask(cgi);

            // Update scheduled task
            if (chkSchedule.Checked)
            {
                if (!schedulerInterval.CheckOneDayMinimum())
                {
                    // If problem occurred while setting schedule interval
                    EditForm.ErrorLabel.Text    = GetString("Newsletter_Edit.NoDaySelected");
                    EditForm.ErrorLabel.Visible = true;
                    EditForm.StopProcessing     = true;
                    return;
                }

                if (!DataTypeManager.IsValidDate(SchedulingHelper.DecodeInterval(scheduleInterval).StartTime))
                {
                    // Start date is not in valid format
                    EditForm.ErrorLabel.Text    = GetString("Newsletter.IncorrectDate");
                    EditForm.ErrorLabel.Visible = true;
                    EditForm.StopProcessing     = true;
                    return;
                }

                task.TaskInterval    = scheduleInterval;
                task.TaskNextRunTime = SchedulingHelper.GetNextTime(task.TaskInterval, new DateTime(), new DateTime());
                task.TaskEnabled     = true;
            }
            else
            {
                task.TaskInterval    = scheduleInterval;
                task.TaskNextRunTime = TaskInfoProvider.NO_TIME;
                task.TaskEnabled     = false;
            }
            TaskInfoProvider.SetTaskInfo(task);

            cgi.ContactGroupScheduledTaskID = task.TaskID;
            pnlInfo.Visible = true;
            InitInfoPanel(cgi, true);
        }
        else
        {
            if (cgi.ContactGroupScheduledTaskID > 0)
            {
                // Store task ID for deletion
                deleteScheduledTaskId = cgi.ContactGroupScheduledTaskID;
            }
            cgi.ContactGroupScheduledTaskID = 0;
            cgi.ContactGroupStatus          = ContactGroupStatusEnum.Unspecified;
            schedulerInterval.Visible       = false;
            pnlInfo.Visible = false;
        }

        // Update contact group
        ContactGroupInfoProvider.SetContactGroupInfo(cgi);

        if (deleteScheduledTaskId > 0)
        {
            // Delete scheduled task if schedule evaluation was unchecked
            TaskInfoProvider.DeleteTaskInfo(deleteScheduledTaskId);
        }

        InitHeaderActions(false);
        ((CMSPage)Page).CurrentMaster.HeaderActions.ReloadData();

        // Refresh breadcrumbs
        var append = cgi.IsGlobal ? " " + GetString("general.global") : "";

        ScriptHelper.RefreshTabHeader(Page, cgi.ContactGroupDisplayName + append);
    }