Example #1
0
        /// <summary>
        /// Records a request by a segmented user
        /// </summary>
        /// <param name="context">The request that the user made</param>
        /// <param name="test">The segmentation test that is running</param>
        /// <param name="segmentKey">The key that identifies the user's segment</param>
        /// <param name="scenario">The test scenario that is being presented to this user</param>
        void ISegmentTestRecorder.Record(IOwinContext context, ISegmentTestingTest test, string segmentKey, ISegmentTestingScenario scenario)
        {
            var identification = context.GetFeature <IIdentification>();
            var identity       = identification == null ? "unknown" : (identification.IsAnonymous ? "anonymous" : identification.Identity);

            Trace.WriteLine("SEGMENT: " + identity + " user in '" + segmentKey + "' segment requested " + context.Request.Uri);
        }
Example #2
0
        private void RunSchedule()
        {
            if (_activeTest == null)
            {
                var now = DateTime.UtcNow;
                foreach (var testData in _segmentTestingData.GetAllTests())
                {
                    if (testData.StartUtc > now || testData.EndUtc <= now)
                    {
                        continue;
                    }

                    var scenarios = _segmentTestingData.GetAllScenarios();

                    var test = new Test
                    {
                        Name            = testData.Name,
                        EnvironmentName = testData.EnvironmentName,
                        StartUtc        = testData.StartUtc,
                        EndUtc          = testData.EndUtc,
                        PageNames       = testData.PageNames,
                        ScenarioMap     = _userSegments
                                          .Select(segment =>
                        {
                            var map = testData.ScenarioMap.FirstOrDefault(m => string.Equals(m.Item1, segment.Key, StringComparison.OrdinalIgnoreCase));
                            ISegmentTestingScenario scenario = null;
                            if (map != null)
                            {
                                scenario = scenarios.FirstOrDefault(s => string.Equals(s.Name, map.Item2, StringComparison.OrdinalIgnoreCase));
                            }
                            return(new Tuple <string, ISegmentTestingScenario>(segment.Key, scenario));
                        })
                                          .ToArray()
                    };

                    // TODO: Get routes to pages included in the test and register new routes with +1 priority and capture IDisposables

                    _activeTest        = test;
                    _activeSegmentTest = testData;
                    break;
                }
            }
            else
            {
                if (DateTime.UtcNow >= _activeTest.EndUtc)
                {
                    if (_activeTest.Routes != null)
                    {
                        foreach (var route in _activeTest.Routes)
                        {
                            route.Dispose();
                        }
                    }

                    _activeTest = null;
                }
            }
        }
 string ISegmentTestingData.CreateTest(ISegmentTestingTest test)
 {
     lock (_lock)
     {
         var list = _allTests.ToList();
         list.Add(test);
         _allTests = list.ToArray();
         return("t" + _allTests.Length);
     }
 }
 void ISegmentTestingData.UpdateTest(ISegmentTestingTest test)
 {
     lock (_lock)
     {
         for (var i = 0; i < _allTests.Length; i++)
         {
             if (_allTests[i].Name == test.Name)
             {
                 _allTests[i] = test;
             }
         }
     }
 }
Example #5
0
 void ISegmentTestingFramework.UpdateTest(ISegmentTestingTest test)
 {
     _segmentTestingData.UpdateTest(test);
 }
Example #6
0
 string ISegmentTestingFramework.CreateTest(ISegmentTestingTest test)
 {
     return(_segmentTestingData.CreateTest(test));
 }