Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public LocalhostClient(string filePath,
                               ISplitLogger log = null) : base(GetLogger(log))
        {
            _fullPath = LookupFilePath(filePath);

            if (_fullPath.ToLower().EndsWith(SplitFileYaml) || _fullPath.ToLower().EndsWith(SplitFileYml))
            {
                _localhostFileService = new YamlLocalhostFileService();
            }
            else
            {
                _log.Warn("Localhost mode: .split/.splits mocks will be deprecated soon in favor of YAML files, which provide more targeting power. Take a look in our documentation.");

                _localhostFileService = new LocalhostFileService();
            }

            var directoryPath = Path.GetDirectoryName(_fullPath);

            _watcher = new FileSystemWatcher(directoryPath != string.Empty ? directoryPath : Directory.GetCurrentDirectory(), Path.GetFileName(_fullPath))
            {
                NotifyFilter = NotifyFilters.LastWrite
            };

            _watcher.Changed            += new FileSystemEventHandler(OnFileChanged);
            _watcher.EnableRaisingEvents = true;

            var splits = ParseSplitFile(_fullPath);

            _splitCache = new InMemorySplitCache(splits);

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

            ApiKey    = "localhost";
            Destroyed = false;

            _trafficTypeValidator = new TrafficTypeValidator(_splitCache);

            BuildEvaluator();

            _impressionsManager = new ImpressionsManager(null, null, null, false, ImpressionsMode.Debug);
        }
Ejemplo n.º 3
0
        public JSONFileClient(string splitsFilePath,
                              string segmentsFilePath,
                              ILog log,
                              ISegmentCache segmentCacheInstance             = null,
                              ISplitCache splitCacheInstance                 = null,
                              IListener <KeyImpression> treatmentLogInstance = null,
                              bool isLabelsEnabled = true,
                              IListener <WrappedEvent> _eventListener    = null,
                              ITrafficTypeValidator trafficTypeValidator = null)  : base(log)
        {
            segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());

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

            task.Wait();

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

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

            splitCache         = splitCacheInstance ?? new InMemorySplitCache(new ConcurrentDictionary <string, ParsedSplit>(parsedSplits));
            impressionListener = treatmentLogInstance;
            splitter           = new Splitter();
            LabelsEnabled      = isLabelsEnabled;

            eventListener         = _eventListener;
            _trafficTypeValidator = trafficTypeValidator;

            _blockUntilReadyService = new NoopBlockUntilReadyService();
            manager = new SplitManager(splitCache, _blockUntilReadyService, log);

            ApiKey = "localhost";
        }
Ejemplo n.º 4
0
 private void BuildBlockUntilReadyService()
 {
     _blockUntilReadyService = new NoopBlockUntilReadyService();
 }