Esempio n. 1
0
        public IPHandler(ILogger <IPHandler> logger, RetrieveConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (config.MaxConcurrent < 1)
            {
                throw new ArgumentException("Max concurrency can not be less than 1", nameof(config.MaxConcurrent));
            }

            this.logger = logger;

            var ips = config.Ips?.Length >= 1 ? config.Ips.Select(IPAddress.Parse).ToArray() : new[] { IPAddress.Any };

            for (var i = 0; i < config.MaxConcurrent; i++)
            {
                foreach (var ip in ips)
                {
                    logger.LogInformation("Adding local IP: {0}", ip);
                    addressed.Enqueue(ip);
                }
            }

            semaphore = new SemaphoreSlim(addressed.Count);
        }
        public TrackedRetrieval(ILogger <TrackedRetrieval> logger, Func <Uri, IDataRetriever> retrieverFactory, RetrieveConfiguration config, IResilience resilience)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (config.LongRetryCodes == null)
            {
                throw new ArgumentNullException(nameof(config.LongRetryCodes));
            }

            this.retrieverFactory = retrieverFactory ?? throw new ArgumentNullException(nameof(retrieverFactory));
            this.resilience       = resilience ?? throw new ArgumentNullException(nameof(resilience));
            this.logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            ResetCookies();
        }