Пример #1
0
        public LightNuGetFeedControllerActivator(LightNuGetFeed[] feeds)
        {
            Ensure.Collection.HasItems(feeds, nameof(feeds));

            _defaultControllerActivator = new DefaultHttpControllerActivator();
            _feedsBySlug = new ReadOnlyDictionary <string, LightNuGetFeed>(feeds.ToDictionary(f => $"/{f.Name.Slugify()}/"));

            if (_feedsBySlug.Count == 1)
            {
                _singleFeed = _feedsBySlug.Values.Single();
            }
        }
Пример #2
0
        private LightNuGetFeed GetMatchingFeed(HttpRequestMessage request)
        {
            if (_singleFeed != null)
            {
                return(_singleFeed);
            }

            var path = $"/{request.RequestUri.LocalPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).First()}/";

            LightNuGetFeed feed = null;

            if (_feedsBySlug.TryGetValue(path, out feed))
            {
                return(feed);
            }

            return(_feedsBySlug.Values.FirstOrDefault(f => path.StartsWith(f.Slug)));
        }