protected void FinishABTest() { if (ABTest == null) { ShowWarning(GetString("abtesting.invalidtest")); return; } if (!CurrentUser.IsAuthorizedPerResource("CMS.ABTest", "Manage", ABTestSiteName)) { RedirectToAccessDenied("cms.abtest", "Manage"); } DateTime finish = (radNow.Checked) ? DateTime.Now : calendarControl.SelectedDateTime; // Validate input if (radLater.Checked && !ABTestValidator.IsValidFinish(ABTest.ABTestOpenFrom, finish)) { ShowError(GetString("abtesting.scheduled.invaliddate")); return; } // Save the test with the new finish date ABTest.ABTestOpenTo = finish; ABTestInfoProvider.SetABTestInfo(ABTest); ScriptHelper.RegisterWOpenerScript(this); // Refresh the window opener with parameter indicating that the refresh was caused by this modal window ScriptHelper.RegisterStartupScript(this, typeof(string), "RefreshPage", ScriptHelper.GetScript("wopener.__doPostBack('', 'modalClosed'); CloseDialog();")); }
protected void StartABTest() { if (ABTest == null) { ShowWarning(GetString("abtesting.invalidtest")); return; } if (!CurrentUser.IsAuthorizedPerResource("CMS.ABTest", "Manage", ABTestSiteName)) { RedirectToAccessDenied("cms.abtest", "Manage"); } DateTime start = (radNow.Checked) ? DateTime.Now : calendarControl.SelectedDateTime; // Validate input if (radLater.Checked && !ABTestValidator.IsValidStart(start)) { ShowError(GetString("abtesting.scheduled.invaliddate")); return; } // Create clone of the test to circumvent caching issues ABTestInfo testClone = ABTest.Clone(); testClone.ABTestOpenFrom = start; // Check for collisions string collidingTestName = ABTestValidator.GetCollidingTestName(testClone); if (!String.IsNullOrEmpty(collidingTestName)) { ShowError(String.Format(GetString("om.twotestsonepageerror"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(collidingTestName)), ABTest.ABTestOriginalPage)); return; } // Save the test with the new start date ABTest.ABTestOpenFrom = start; ABTestInfoProvider.SetABTestInfo(ABTest); ScriptHelper.RegisterWOpenerScript(this); // Refresh the window opener with parameter indicating that the refresh was caused by this modal window ScriptHelper.RegisterStartupScript(this, typeof(string), "RefreshPage", ScriptHelper.GetScript("wopener.RefreshPage(false); CloseDialog();")); }
/// <summary> /// Checks whether the form is valid. /// </summary> private bool IsValid() { // If the test is finished, no validation is needed if (TestStatus == ABTestStatusEnum.Finished) { return(true); } // Get page of the test so we can check for collisions string page = QueryHelper.GetString("AliasPath", null); if (String.IsNullOrEmpty(page)) { page = form.GetFieldValue("ABTestOriginalPage").ToString(); } // Validate original page of the test if (!PageExists(page)) { ShowError(GetString("abtesting.testpath.pagenotfound")); return(false); } // Create temporary test used for validation of the new values ABTestInfo updatedTest = new ABTestInfo { ABTestID = ABTest.ABTestID, ABTestOriginalPage = page, ABTestCulture = form.GetFieldValue("ABTestCulture").ToString(), ABTestSiteID = SiteContext.CurrentSiteID, }; updatedTest.ABTestOpenFrom = ValidationHelper.GetDateTime(form.GetFieldValue("ABTestOpenFrom"), DateTimeHelper.ZERO_TIME); // Validate start time if the test is not already running if (TestStatus != ABTestStatusEnum.Running) { if (!ABTestValidator.IsValidStart(updatedTest.ABTestOpenFrom)) { ShowError(GetString("om.wrongtimeinterval")); return(false); } } updatedTest.ABTestOpenTo = ValidationHelper.GetDateTime(form.GetFieldValue("ABTestOpenTo"), DateTimeHelper.ZERO_TIME); // Validate finish time of the test if (!ABTestValidator.IsValidFinish(updatedTest.ABTestOpenFrom, updatedTest.ABTestOpenTo)) { ShowError(GetString("om.wrongtimeinterval")); return(false); } // Find out possible collision - another test running on the same page, culture and at the same time string collidingTestName = ABTestValidator.GetCollidingTestName(updatedTest); if (!String.IsNullOrEmpty(collidingTestName)) { ShowError(String.Format(GetString("om.twotestsonepageerror"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(collidingTestName)), updatedTest.ABTestOriginalPage)); return(false); } // If we get here, all fields are valid return(true); }