protected void btnSend_Click(object sender, EventArgs e) { // Validate date/time if (dtpMailout.SelectedDateTime == DateTimeHelper.ZERO_TIME) { ShowError(GetString("newsletterissue_send.invaliddatetime")); return; } IssueInfo winner = (IssueInfo)EditedObject; int parentIssueId = winner.IssueVariantOfIssueID; // Get A/B test info ABTestInfo abi = ABTestInfoProvider.GetABTestInfoForIssue(parentIssueId); if (abi != null) { IssueInfo issue = IssueInfoProvider.GetIssueInfo(parentIssueId); // Check if winner was selected and sent if (abi.TestWinnerIssueID != 0) { if ((issue.IssueStatus == IssueStatusEnum.Finished) || (issue.IssueStatus == IssueStatusEnum.Sending)) { // Winner was already sent CloseDialogAndRefreshParent(); return; } } // Update A/B test info and winner selection task (if exist) abi.TestWinnerOption = ABTestWinnerSelectionEnum.Manual; NewsletterTasksManager.EnsureWinnerSelectionTask(abi, issue, false, DateTime.Now); abi.TestSelectWinnerAfter = 0; abi.TestWinnerSelected = DateTime.Now; abi.TestWinnerIssueID = winner.IssueID; ABTestInfoProvider.SetABTestInfo(abi); if ((issue != null) && (winner != null)) { // Copy data from winner to parent IssueHelper.CopyIssueProperties(winner, issue, "issuesubject;issuetext;issuetemplateid;issueshowinnewsletterarchive;issuesendername;issuesenderemail"); IssueInfoProvider.SetIssueInfo(issue); // Remove previous scheduled task of this issue NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID); DateTime mailoutTime = dtpMailout.SelectedDateTime; Service <IIssueSender> .Entry().Send(IssueInfoProvider.GetIssueInfo(parentIssueId), mailoutTime); } } // Close dialog and refresh parent page CloseDialogAndRefreshParent(); }
private void SetABTestWinnerManually(ABTestInfo abTest, IssueInfo parentIssue, IssueInfo winnerVariant) { // Update A/B test info and winner selection task (if exist) abTest.TestWinnerOption = ABTestWinnerSelectionEnum.Manual; NewsletterTasksManager.EnsureWinnerSelectionTask(abTest, parentIssue, false, DateTime.Now); abTest.TestSelectWinnerAfter = 0; abTest.TestWinnerSelected = DateTime.Now; abTest.TestWinnerIssueID = winnerVariant.IssueID; ABTestInfo.Provider.Set(abTest); }
/// <summary> /// Removes all scheduled tasks for the given issue. /// </summary> /// <param name="when">DateTime when to send</param> private void RemovePreviousTaskAndSendIssue(DateTime when) { IssueInfo issue = IssueInfoProvider.GetIssueInfo(IssueID); if (issue != null) { // Remove all previously scheduled tasks (if any) NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID); // Schedule new task for new mailout time Service <IIssueSender> .Entry().Send(issue, when); } }
/// <summary> /// Creates new scheduled task for the given issue and newsletter. /// </summary> /// <param name="issue">Issue</param> private int CreateScheduledTask(IssueInfo issue) { if (issue == null) { throw new ArgumentNullException("issue"); } // Create new scheduled task TaskInfo task = NewsletterTasksManager.CreateMailoutTask(issue, DateTime.Now, false); TaskInfoProvider.SetTaskInfo(task); return(task.TaskID); }
/// <summary> /// Deletes an issue specified by its ID (if authorized). /// </summary> /// <param name="issueId">Issue's ID</param> private static void DeleteIssue(int issueId) { var issue = GetIssueOrRedirect(issueId); // User has to have both destroy and issue privileges to be able to delete the issue. if (!issue.CheckPermissions(PermissionsEnum.Delete, SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser)) { RedirectToAccessDenied(issue.TypeInfo.ModuleName, "AuthorIssues"); } if (issue.IssueIsABTest) { var abTest = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID); NewsletterTasksManager.DeleteWinnerSelectionTask(abTest); } IssueInfo.Provider.Delete(issue); }
/// <summary> /// Create schedule task. /// </summary> private void CreateTask() { try { var newsletter = TypedEditedObject; var task = NewsletterTasksManager.CreateOrUpdateDynamicNewsletterTask(newsletter, ScheduleInterval.TaskInterval); TaskInfo.Provider.Set(task); newsletter.NewsletterDynamicScheduledTaskID = task.TaskID; NewsletterInfo.Provider.Set(newsletter); Redirect(); } catch (Exception ex) { ShowError(GetString(ex.Message)); } }
private void UpdateDynamicNewsletterTask(NewsletterInfo newsletterObj, TaskInterval taskInterval) { var currentTask = TaskInfoProvider.GetTaskInfo(newsletterObj.NewsletterDynamicScheduledTaskID); var taskIntervalStr = SchedulingHelper.EncodeInterval(taskInterval); if ((currentTask != null) && (currentTask.TaskInterval == taskIntervalStr)) { // No need to update anything, nothing has changed return; } // Update or create new task based on current taskInterval var task = NewsletterTasksManager.CreateOrUpdateDynamicNewsletterTask(newsletterObj, taskInterval, currentTask); TaskInfoProvider.SetTaskInfo(task); // Update taskID newsletterObj.NewsletterDynamicScheduledTaskID = task.TaskID; }
protected void btnOk_Click(object sender, EventArgs e) { // Validate date/time (blank date/time textbox is allowed) if ((dtpMailout.SelectedDateTime == DateTimeHelper.ZERO_TIME) && !string.IsNullOrEmpty(dtpMailout.DateTimeTextBox.Text.Trim())) { ShowErrorInternal(GetString("newsletterissue_send.invaliddatetime")); return; } // Get variants (IDs) to set var selItems = new List <string>(); if (drpAllSelected.SelectedValue == DDLIST_SETALL) { selItems = IssueInfoProvider.GetIssues() .Where(GetWhereCondition(ParentIssueID, true)) .Column("IssueID") .TypedResult .Select(s => s.IssueID.ToString()) .ToList(); } else if (drpAllSelected.SelectedValue == DDLIST_SETSELECTED) { selItems = grdElem.SelectedItems; } else { selItems.Add(drpAllSelected.SelectedValue); } // Check selected variants if (!selItems.Any()) { if (drpAllSelected.SelectedValue != DDLIST_SETALL) { ShowErrorInternal(GetString("newsletterissue_send.novariantsselected")); } else { pMOut.Visible = false; } return; } var when = (dtpMailout.SelectedDateTime == DateTimeHelper.ZERO_TIME) ? DateTime.Now : dtpMailout.SelectedDateTime; foreach (var itemId in selItems) { var issue = IssueInfoProvider.GetIssueInfo(ValidationHelper.GetInteger(itemId, 0)); if (issue == null) { continue; } var task = NewsletterTasksManager.EnsureMailoutTask(issue, DateTime.Now, false); task.TaskNextRunTime = when; TaskInfoProvider.SetTaskInfo(task); if (issue.IssueScheduledTaskID != task.TaskID) { issue.IssueScheduledTaskID = task.TaskID; IssueInfoProvider.SetIssueInfo(issue); } } mHighestMailoutTime = DateTime.MinValue; grdElem.ResetSelection(); grdElem.ReloadData(); OnChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Saves current newsletter settings. /// </summary> public bool SaveIssue() { try { switch (CurrentState) { case VariantStatusEnum.WaitingToSend: case VariantStatusEnum.ReadyForSending: case VariantStatusEnum.ReadyForTesting: case VariantStatusEnum.WaitingToSelectWinner: if (mABTest == null) { mABTest = ABTestInfoProvider.GetABTestInfoForIssue(mParentIssue.IssueID); } // Get A/B test settings from controls var abTestChanged = SaveABTestInfo(mABTest); if (mABTest == null) { return(false); } if (mABTest.TestWinnerOption != ABTestWinnerSelectionEnum.Manual) { // Check minimal time interval if (mABTest.TestSelectWinnerAfter < 5) { ErrorMessage = GetString("newsletterissue_send.saveissuewrongwinnerselectioninterval"); return(false); } } // Check if test options has changed if (abTestChanged && mABTest.TestWinnerIssueID > 0) { // Options has been changed => reset previously selected winner NewsletterTasksManager.DeleteMailoutTask(mParentIssue.IssueGUID, mParentIssue.IssueSiteID); mABTest.TestWinnerIssueID = 0; mABTest.TestWinnerSelected = DateTimeHelper.ZERO_TIME; // Hide/reload winner selection in issue mail-out grid ucMailout.ReloadData(false); } ABTestInfo.Provider.Set(mABTest); if (CurrentState == VariantStatusEnum.WaitingToSelectWinner) { NewsletterTasksManager.EnsureWinnerSelectionTask(mABTest, mParentIssue, true, ucMailout.HighestMailoutTime); } // Update info message for parent control var currentState = GetCurrentState(mParentIssue); InfoMessage = GetInfoMessage(currentState, mParentIssue, mABTest.TestWinnerOption); return(true); case VariantStatusEnum.Finished: ErrorMessage = GetString("newsletterissue_send.saveissuehasbeensent"); break; } } catch (Exception e) { ErrorMessage = e.Message; return(false); } return(true); }
/// <summary> /// Saves current newsletter settings. /// </summary> public bool SaveIssue() { try { switch (CurrentState) { case STATE_WAITING_TO_SEND_PAGE: case STATE_WAITING_TO_SEND_WIZARD: case STATE_TEST_READY_FOR_SENDING: case STATE_TEST_WAITING_TO_SEL_WINNER: if (mABTest == null) { mABTest = ABTestInfoProvider.GetABTestInfoForIssue(mParentIssue.IssueID); } // Get A/B test settings from controls bool abTestChanged = SaveABTestInfo(mABTest); if (mABTest == null) { return(false); } if (mABTest.TestWinnerOption != ABTestWinnerSelectionEnum.Manual) { // Check minimal time interval if (mABTest.TestSelectWinnerAfter < 5) { ErrorMessage = GetString("newsletterissue_send.saveissuewrongwinnerselectioninterval"); return(false); } } // Check if test options has changed if (abTestChanged) { if (mABTest.TestWinnerIssueID > 0) { // Options has been changed => reset previously selected winner NewsletterTasksManager.DeleteMailoutTask(mParentIssue.IssueGUID, mParentIssue.IssueSiteID); mABTest.TestWinnerIssueID = 0; mABTest.TestWinnerSelected = DateTimeHelper.ZERO_TIME; // Hide/reload winner selection in issue mail-out grid ucMailout.ReloadData(false); } IssueInfoProvider.SetIssueInfo(mParentIssue); } ABTestInfoProvider.SetABTestInfo(mABTest); if (CurrentState == STATE_TEST_WAITING_TO_SEL_WINNER) { NewsletterTasksManager.EnsureWinnerSelectionTask(mABTest, mParentIssue, true, ucMailout.HighestMailoutTime); } // Update info message for parent control int currentState = GetCurrentState(mParentIssue); InfoMessage = GetInfoMessage(currentState, mParentIssue, mABTest.TestWinnerOption, GetPlannedMailoutTime(ucMailout.HighestMailoutTime)); return(true); case STATE_TEST_FINISHED: ErrorMessage = GetString("newsletterissue_send.saveissuehasbeensent"); break; } } catch (Exception e) { ErrorMessage = e.Message; return(false); } return(true); }