/// <summary> /// Returns the current variations object also sets the impressions for test results. /// </summary> /// <param name="testId">Contains the id for the current test on the site.</param> private static sp_GetandUpdateVariationsInformation_Result GetVariationId(int testId, ABTestingEntities dbContext) { //try //{ sp_GetandUpdateVariationsInformation_Result variationData = dbContext.sp_GetandUpdateVariationsInformation(testId).First(); return(variationData); //} //catch (Exception ex) { // return null; //} }
/// <summary> /// Creates an instance of class and runs all other methods to populate properties /// </summary> /// <param name="requestObject">Contains the current context response object </param> /// <param name="deviceTypeId"> </param> public TestManager(HttpRequest requestObject, Int32 deviceTypeId) { try { //-- step 1) Check the user is not already cookied. If they are then use that information -- //-- step 2) Check that this url is in a test. --- //this.Authority = requestObject.Url.Authority; //requestObject.Url.Host; // ConfigurationManager.AppSettings["SEORefinementSite"]; this.Authority = "localhost:57815"; //-- used for testing from home. using (ABTestingEntities dbContext = new ABTestingEntities()) { this.CheckTest(deviceTypeId, dbContext); //-- step 3) If in a test then set all test information. --- if (this.IsTest) { //-- Get current test information based off of url. *** Can be added to Checktest, no reason to make the same call twice. JL this._testdata = dbContext.sp_GetTestInformation(this.Authority, deviceTypeId).Single(); //-- Get variations for the test. this._variationsdata = GetVariationId(Convert.ToInt32(testData.Id), dbContext); //-- only set impression when setting test cookie //-- Get list of replacements for the current test. this._replacementlist = Replacements(requestObject.Url.Authority, variationsData.Base, dbContext); //-- Generate Test Cookie. this.GenerateCookie(this._testdata, requestObject, this._variationsdata, deviceTypeId); } } //HttpCookie cookie = TestManager.ReturnTestCookie(); //this.VariationId = (cookie != null) ? Convert.ToInt32(cookie["VariationId"]) : 0; //this.Media = media; } catch (Exception ex) { //--- what error handeling do I add here ? --- // } }
/// <summary> /// If instance is verified as a test, pulls test information from entity and populates a cookie /// as well as media parameters to be used for implementing the test. /// </summary> private void GenerateCookie(sp_GetTestInformation_Result testData, HttpRequest requestObject, sp_GetandUpdateVariationsInformation_Result variationsResult, Int32 deviceTypeId) { bool setCookie = true; if (this.IsTest) { try { String checkCookie = String.Format("{0}{1}", this.Authority, CookieName); if (requestObject.Cookies[checkCookie] != null) { setCookie = false; } //-- If the cookies is not set or the set cookies does not match the current test cookie then set test. --- //public decimal Id { get; set; } //public Nullable<decimal> TestId { get; set; } //public string Variation { get; set; } //public string Description { get; set; } //public string ViewName { get; set; } //public bool DefaultView { get; set; } //public bool Base { get; set; } //public string TemplateName { get; set; } //public decimal Impressions { get; set; } if ((setCookie)) { sp_GetandUpdateVariationsInformation_Result variationData = variationsResult; //GetVariationId(Convert.ToInt32(testData.Id)); //-- only set impression when setting test cookie this.VariationId = Convert.ToInt32(variationData.Id); this.Cookie = new HttpCookie(checkCookie); this.Cookie["TestId"] = testData.Id.ToString(CultureInfo.InvariantCulture); this.Cookie["VariationId"] = variationData.Id.ToString(CultureInfo.InvariantCulture); this.Cookie["SiteId"] = testData.SiteId.ToString(); this.Cookie["DescriptiveName"] = variationData.Variation; this.Cookie["StartDate"] = testData.StartDate.ToString(); this.Cookie["EndDate"] = testData.EndDate.ToString(); this.Cookie["Impression"] = variationData.Impressions.ToString(CultureInfo.InvariantCulture); this.Cookie["Host"] = this.Host; this.Cookie["TemplateName"] = variationData.ViewName; this.Cookie["LayoutPage"] = variationData.TemplateName; this.Cookie["viewType"] = (!variationData.Base) ? "replacement" : "base"; this.Cookie["DeviceType"] = deviceTypeId == 2 ? "mobile" : "desktop"; //-- View TestingRenderingEnguine line 141 for explination. this.Cookie.Expires = DateTime.Now.AddMonths(6); requestObject.Cookies.Add(this.Cookie); } } catch (Exception ex) { this.IsTest = false; } } else { //-- No test going on. If cookie is set then expire the cookie. ---- if (this.Cookie != null) { this.Cookie.Expires = DateTime.Now.AddDays(-1d); } return; } }