/// <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> /// Gets a collection of base views. Based on the last winner /// </summary> /// <param name="hostname">Contains the host name of the site.</param> /// <returns></returns> //public static List<sp_GetBaseReplacements_Result> BaseReplacements(String hostname) //{ // try // { // using (ABTestingEntities dbContext = new ABTestingEntities()) // { // //List<Replacements> replacementViews = (from replacementInfo in dbContext.Replacements // // join variationInfo in dbContext.Variations on replacementInfo.VariationId equals variationInfo.Id // // join testInfo in dbContext.ABTests on variationInfo.TestId equals testInfo.Id // // join siteInfo in dbContext.Sites on testInfo.SiteId equals siteInfo.Id // // where siteInfo.SiteName == hostname && variationInfo.Base == true // // select replacementInfo).ToList(); // List<sp_GetBaseReplacements_Result> replacementBaseViews = dbContext.sp_GetBaseReplacements(hostname).ToList(); // return replacementBaseViews; // } // } // catch (Exception ex) // { // return null; // } //} /// <summary> /// Gets a collection of views to replace by the variation id /// </summary> /// <param name="url">Contains the url of the current site</param> /// <param name="isbase">Contains a boolen representing if its a base replacement or not.</param> /// <returns></returns> public static List <sp_GetReplacements_Result> Replacements(String url, Boolean isbase, ABTestingEntities dbContext) { List <sp_GetReplacements_Result> replacementViews = dbContext.sp_GetReplacements(url, isbase).ToList(); return(replacementViews); }
/// <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; //} }
// Methods /// <summary> /// Checks to see if the current site is in a test through the site host name and active bool, shoudl default to false. /// </summary> private void CheckTest(Int32 deviceTypeId, ABTestingEntities dbContext) { //this.IsTest = false; this.IsTest = dbContext.sp_CheckIfInATest(this.Authority, deviceTypeId).Any(); }