public JSONFileClient(string splitsFilePath,
                              string segmentsFilePath,
                              ISplitLogger log = null,
                              ISegmentCache segmentCacheInstance = null,
                              ISplitCache splitCacheInstance     = null,
                              IImpressionsLog impressionsLog     = null,
                              bool isLabelsEnabled = true,
                              IEventsLog eventsLog = null,
                              ITrafficTypeValidator trafficTypeValidator = null,
                              IImpressionsManager impressionsManager     = null) : base(GetLogger(log))
        {
            _segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());

            var segmentFetcher     = new JSONFileSegmentFetcher(segmentsFilePath, _segmentCache);
            var splitChangeFetcher = new JSONFileSplitChangeFetcher(splitsFilePath);
            var task = splitChangeFetcher.Fetch(-1);

            task.Wait();

            var splitChangesResult = task.Result;
            var parsedSplits       = new ConcurrentDictionary <string, ParsedSplit>();

            _splitParser = new InMemorySplitParser(segmentFetcher, _segmentCache);

            foreach (var split in splitChangesResult.splits)
            {
                parsedSplits.TryAdd(split.name, _splitParser.Parse(split));
            }

            _splitCache = splitCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>(parsedSplits));

            _impressionsLog = impressionsLog;

            LabelsEnabled = isLabelsEnabled;

            _eventsLog            = eventsLog;
            _trafficTypeValidator = trafficTypeValidator;

            _blockUntilReadyService = new NoopBlockUntilReadyService();
            _manager = new SplitManager(_splitCache, _blockUntilReadyService, log);

            ApiKey = "localhost";

            BuildEvaluator(log);
            _impressionsManager = impressionsManager ?? new ImpressionsManager(impressionsLog, null, null, false, ImpressionsMode.Debug);
        }
Beispiel #2
0
        public SplitClientForTesting(ISplitLogger log,
                                     ISplitCache splitCache,
                                     IEventsLog eventsLog,
                                     IImpressionsLog impressionsLog,
                                     IBlockUntilReadyService blockUntilReadyService,
                                     IEvaluator evaluator,
                                     IImpressionsManager impressionsManager)
            : base(log)
        {
            _splitCache             = splitCache;
            _eventsLog              = eventsLog;
            _impressionsLog         = impressionsLog;
            _blockUntilReadyService = blockUntilReadyService;
            _trafficTypeValidator   = new TrafficTypeValidator(_splitCache, log);
            _evaluator              = evaluator;
            _impressionsManager     = impressionsManager;

            ApiKey = "SplitClientForTesting";
        }