예제 #1
0
        internal string TestImpl(string name, string[] options)
        {
            var results = Settings.Storage.GetResults(name);

            var userResult = results.LastOrDefault(r => r.User == User && !r.Converted);

            //if the user has a result try get the previous option for the test
            if (userResult != null)
            {
                //Check if the user has already seen this test
                var tempOutput = GetUserTestOption(name);

                if (!string.IsNullOrEmpty(tempOutput))
                {
                    return(tempOutput);
                }
            }

            //Randomly select which option to use
            //TODO - Maybe this could be overwritten with an interface or something?
            var output = options[_rand.Next(options.Length)];

            //Store the new test in the IStorage
            var result = new ABSeeResult
            {
                Converted = false,//not yet
                Option    = output,
                TesterId  = Id,
                TestName  = name,
                User      = User,
                Date      = DateTime.Now
            };

            Settings.Storage.SaveResults(result);

            _context.Response.AppendCookie(new HttpCookie("abseetest-" + name, output));

            //return the selected option
            return(output);
        }
예제 #2
0
파일: ABTester.cs 프로젝트: Tboda/abSee
        internal string TestImpl(string name, string[] options)
        {
            var results = Settings.Storage.GetResults(name);

            var userResult = results.LastOrDefault(r => r.User == User && !r.Converted);
            //if the user has a result try get the previous option for the test
            if (userResult != null)
            {
                //Check if the user has already seen this test
                var tempOutput = GetUserTestOption(name);

                if (!string.IsNullOrEmpty(tempOutput))
                {
                    return tempOutput;
                }
            }

            //Select the option based on the OptionSelector
            var output = Settings.OptionSelector.SelectOption(_context, User, options);

            //Store the new test in the IStorage
            var result = new ABSeeResult
            {
                Converted = false,//not yet
                Option = output,
                TesterId = Id,
                TestName = name,
                User = User,
                Date = DateTime.Now
            };

            Settings.Storage.SaveResults(result);

            _context.Response.AppendCookie(new HttpCookie("abseetest-" + name, output));

            //return the selected option
            return output;
        }