private void GridVariants_OnAction(string actionName, object actionArgument)
    {
        if (actionName.Equals("delete", StringComparison.OrdinalIgnoreCase))
        {
            int deletedIssueId = ValidationHelper.GetInteger(actionArgument, 0);
            EmailABTestService.DeleteVariant(deletedIssueId);

            var variants = IssueHelper.GetIssueVariants(ParentIssueId, additionalWhereCondition: null);
            int redirectToIssueId;

            // Handle the situation when deleted variant was the actually displayed variant or entire A/B test was deleted as well.
            if ((variants != null) && variants.Any())
            {
                if (Issue.IssueID != deletedIssueId)
                {
                    // Don't redirect, leave current location unchanged.
                    return;
                }

                // Switch to first available variant
                redirectToIssueId = variants.First().IssueID;
            }
            else
            {
                // Suppose the entire A/B test was removed so switch to the original issue
                redirectToIssueId = ParentIssueId;
            }

            string url = EmailBuilderHelper.GetNavigationUrl(Issue.IssueNewsletterID, redirectToIssueId, 2);
            URLHelper.Redirect(url);
        }
    }
    private void GridVariants_OnAction(string actionName, object actionArgument)
    {
        if (actionName.Equals("delete", StringComparison.OrdinalIgnoreCase))
        {
            int deletedIssueId = ValidationHelper.GetInteger(actionArgument, 0);
            EmailABTestService.DeleteVariant(deletedIssueId);

            var variants = IssueHelper.GetIssueVariants(ParentIssueId);

            // Handle the situation when deleted variant was the actually displayed variant or entire A/B test was deleted as well.
            if (variants != null && variants.Any())
            {
                if (Issue.IssueID != deletedIssueId)
                {
                    // Don't redirect, leave current location unchanged.
                    return;
                }

                // Switch to first available variant
                OnSave(new EmailBuilderEventArgs(Issue.IssueNewsletterID, variants.First().IssueID, 2));
            }
            else
            {
                // Suppose the entire A/B test was removed so switch to the original issue
                OnSave(new EmailBuilderEventArgs());
            }
        }
    }
    /// <summary>
    /// Initializes controls
    /// </summary>
    protected void InitControls(bool forceReload)
    {
        grdElem.GridOptions.ShowSelection = ShowSelectionColumn;
        pMOut.Visible = EnableMailoutTimeSetting;

        if (EnableMailoutTimeSetting)
        {
            if (forceReload || (drpAllSelected.Items.Count <= 0))
            {
                drpAllSelected.Items.Clear();
                if (ShowSelectionColumn)
                {
                    drpAllSelected.Items.Add(new ListItem(GetString("general.selectall"), DDLIST_SETALL));
                    drpAllSelected.Items.Add(new ListItem(GetString("newsletterissue_send.selected"), DDLIST_SETSELECTED));
                }

                var items = IssueHelper.GetIssueVariants(ParentIssueID, "IssueMailoutTime IS NULL");
                if (items != null && items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        drpAllSelected.Items.Add(new ListItem(item.IssueVariantName, item.IssueID.ToString()));
                    }
                }
            }

            // Hide entire panel if no variant available
            if (drpAllSelected.Items.Count <= 0)
            {
                pMOut.Visible = false;
            }
        }

        pnlMailoutHeading.ResourceString = UseGroupingText ? "newsletterissue_send.schedulemailout" : "newsletterissue_send.testresults";
    }
Ejemplo n.º 4
0
    private void InitTestGroupSlider(IssueInfo parentIssue, ABTestInfo abTest, bool forceReload)
    {
        var variants = IssueHelper.GetIssueVariants(parentIssue, null);
        ucGroupSlider.Variants = variants;

        ucGroupSlider.NumberOfSubscribers = GetNumberOfSubscribers(parentIssue, variants);

        if (forceReload || !ucGroupSlider.Enabled)
        {
            ucGroupSlider.CurrentSize = abTest?.TestSizePercentage ?? DEFAULT_TEST_GROUP_SIZE_PERCENTAGE;
        }
        ucGroupSlider.ReloadData(forceReload);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Initializes the variants drop-down list or hides it if the issue has no variants.
    /// </summary>
    private void InitVariantDropDownList()
    {
        if (!NewsletterHelper.IsABTestingAvailable())
        {
            return;
        }

        var variants = IssueHelper.GetIssueVariants(Issue)
                       .Select(v => new ListItem(v.IssueVariantName, v.IssueID.ToString())).ToList();

        if (variants.Any())
        {
            foreach (var variant in variants)
            {
                drpVariantsSelector.Items.Add(variant);
            }

            drpVariantsSelector.SelectedValue = Issue.IssueID.ToString();
            pnlTabs.AddCssClass("with-variants");
            plcVariantSelection.Visible = true;
        }
    }
    /// <summary>
    /// When dialog's OK button for new variant action is clicked.
    /// </summary>
    protected void btnSaveDialog_Click(object sender, EventArgs e)
    {
        if (String.IsNullOrWhiteSpace(txtVariantName.Text))
        {
            errorMessage.Text = GetString("newsletter.variantdisplaynamemissing");
            return;
        }

        try
        {
            var variantName = txtVariantName.Text.Truncate(VARIANT_NAME_SIZE);
            var newVariant  = EmailABTestService.CreateVariant(variantName, Issue.IssueID);

            // If this is the first variant created (2 variants in total), make full refresh of the email builder in order to update related menu tabs
            var builderEventArgs = IssueHelper.GetIssueVariants(Issue).Count == 2 ? new EmailBuilderEventArgs() : new EmailBuilderEventArgs(Issue.IssueNewsletterID, newVariant.IssueID, 2);
            OnSave(builderEventArgs);
        }
        catch (InvalidOperationException exception)
        {
            Service.Resolve <IEventLogService>().LogException("Newsletter", "ADDVARIANT", exception);
            errorMessage.Text = GetString("emailbuilder.generalerror");
        }
    }
    /// <summary>
    /// Initializes selector with variants of the main issue that is specified by its ID.
    /// </summary>
    /// <param name="issueId">Issue ID</param>
    protected void InitVariantSelector(int issueId)
    {
        if (drpVariants.Items.Count == 0)
        {
            if (AllowSelectAll)
            {
                // Add (all) option
                drpVariants.Items.Add(new ListItem(GetString("general.selectall"), "-1"));
            }

            // Get A/B test variants
            var variants = IssueHelper.GetIssueVariants(issueId);
            if (variants?.Count > 0)
            {
                // Initialize selector
                foreach (var variant in variants)
                {
                    if (variant.IsWinner)
                    {
                        WinnerIssueID = variant.IssueID;
                        drpVariants.Items.Add(new ListItem(variant.IssueVariantName + " " + GetString("newsletterabtest.winner"), mainIssueID.ToString()));
                    }
                    else
                    {
                        drpVariants.Items.Add(new ListItem(variant.IssueVariantName, variant.IssueID.ToString()));
                    }
                }
            }

            if (!RequestHelper.IsPostBack() && drpVariants.Items.FindByValue(issueId.ToString()) != null)
            {
                // Preselect main issue
                drpVariants.SelectedValue = issueId.ToString();
            }
        }
    }
    /// <summary>
    /// Deletes an issue specified by its ID (if authorized).
    /// </summary>
    /// <param name="issueId">Issue's ID</param>
    private static void DeleteIssue(int issueId)
    {
        // Delete issue from database (if authorized)
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "authorissues"))
        {
            RedirectToCMSDeskAccessDenied("cms.newsletter", "authorissues");
        }


        IssueInfo issue = IssueInfoProvider.GetIssueInfo(issueId);

        if (issue != null)
        {
            // Delete variant issues if any
            if (issue.IssueIsABTest && (issue.IssueVariantOfIssueID == 0))
            {
                // Get all variants (children) and delete their mailout tasks
                List <IssueABVariantItem> variants = IssueHelper.GetIssueVariants(issue, null);
                IssueInfo issueVar = null;
                if ((variants != null) && (variants.Count > 0))
                {
                    foreach (IssueABVariantItem variant in variants)
                    {
                        issueVar = IssueInfoProvider.GetIssueInfo(variant.IssueID);
                        if (issueVar != null)
                        {
                            IssueInfoProvider.DeleteMailoutTask(issueVar.IssueGUID, issueVar.IssueSiteID);
                        }
                    }
                }
            }
            // Delete issue
            IssueInfoProvider.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID);
            IssueInfoProvider.DeleteIssueInfo(issue);
        }
    }
Ejemplo n.º 9
0
    private static bool AreAllVariantsSent(IssueInfo parentIssue)
    {
        var variants = IssueHelper.GetIssueVariants(parentIssue);

        return(AreAllVariantsSent(variants));
    }
    /// <summary>
    /// Reloads control data.
    /// </summary>
    /// <param name="forceReload">Indicates if force reload should be used</param>
    public override void ReloadData(bool forceReload)
    {
        if (StopProcessing && !forceReload)
        {
            return;
        }

        if (ForceReloadNeeded)
        {
            forceReload       = true;
            ForceReloadNeeded = false;
        }

        int parentIssueId = 0;

        parentIssue = IssueInfoProvider.GetOriginalIssue(IssueID);
        if (parentIssue != null)
        {
            parentIssueId = parentIssue.IssueID;
        }

        // Get A/B test configuration
        abTest = ABTestInfoProvider.GetABTestInfoForIssue(parentIssueId);
        if (abTest == null)
        {
            // Ensure A/B test object with default settings
            abTest = new ABTestInfo()
            {
                TestIssueID = parentIssueId, TestSizePercentage = 50, TestWinnerOption = ABTestWinnerSelectionEnum.OpenRate, TestSelectWinnerAfter = 60
            };
            ABTestInfoProvider.SetABTestInfo(abTest);
        }

        CurrentState = GetCurrentState(parentIssue);
        InitControls(CurrentState, forceReload);

        ucMailout.ParentIssueID = parentIssueId;
        ucMailout.ReloadData(forceReload);

        InfoMessage = GetInfoMessage(CurrentState, parentIssue, (abTest != null ? abTest.TestWinnerOption : ABTestWinnerSelectionEnum.OpenRate), GetPlannedMailoutTime(ucMailout.HighestMailoutTime));

        // Init test group slider
        List <IssueABVariantItem> variants = IssueHelper.GetIssueVariants(parentIssue, null);

        ucGroupSlider.Variants = variants;
        bool allVariantsSent = true;

        if (variants != null)
        {
            allVariantsSent = variants.TrueForAll(delegate(IssueABVariantItem item) { return(item.IssueStatus == IssueStatusEnum.Finished); });
        }
        if ((parentIssue.IssueStatus == IssueStatusEnum.Finished) || allVariantsSent)
        {
            // Issue was sent long time ago => get number of subscribers from issue properties instead of current number of subscribers
            int perVariantEmails = 1;
            if (abTest != null)
            {
                perVariantEmails = abTest.TestNumberPerVariantEmails;
            }
            ucGroupSlider.NumberOfTestSubscribers = ucGroupSlider.Variants.Count * perVariantEmails;

            if (parentIssue.IssueStatus == IssueStatusEnum.Finished)
            {
                // Issue was sent => get number of subscribers from number of sent issues
                ucGroupSlider.NumberOfSubscribers = parentIssue.IssueSentEmails;
            }
            else
            {
                // Only variants was sent => get current number of subscribers
                ucGroupSlider.NumberOfSubscribers = GetEmailAddressCount(parentIssue.IssueNewsletterID, parentIssue.IssueSiteID);
            }
        }
        else
        {
            ucGroupSlider.NumberOfSubscribers = GetEmailAddressCount(parentIssue.IssueNewsletterID, parentIssue.IssueSiteID);
        }

        if (forceReload || !ucGroupSlider.Enabled)
        {
            ucGroupSlider.CurrentSize = (abTest != null ? abTest.TestSizePercentage : 10);
        }
        ucGroupSlider.ReloadData(forceReload);
        ucWO_OnChange(this, EventArgs.Empty);
    }