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)) { var parentIssue = IssueInfoProvider.GetIssueInfo(parentIssueId); NewsletterSendingStatusModifier.ResetAllEmailsInQueueForIssue(parentIssue.IssueID); // Copy data from winner to parent IssueHelper.CopyWinningVariantIssueProperties(winner, issue); IssueInfoProvider.SetIssueInfo(issue); // Remove previous scheduled task of this issue NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID); DateTime mailoutTime = dtpMailout.SelectedDateTime; Service.Resolve <IIssueScheduler>().ScheduleIssue(parentIssue, mailoutTime); } } // Close dialog and refresh parent page CloseDialogAndRefreshParent(); }
private void ScheduleSendingOfIssue(IssueInfo issue) { // Remove previous scheduled task of this issue NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID); DateTime mailoutTime = dtpMailout.SelectedDateTime; Service.Resolve <IIssueScheduler>().ScheduleIssue(issue, mailoutTime); }
/// <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> /// 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); }