Пример #1
0
        internal static StorageBase GetDefaultStorage(SpiderOptions options)
        {
            var type = Type.GetType(options.Storage);

            if (type == null)
            {
                throw new SpiderException("存储器类型配置不正确,或者未添加对应的库");
            }

            if (!typeof(StorageBase).IsAssignableFrom(type))
            {
                throw new SpiderException("存储器类型配置不正确");
            }

            var method = type.GetMethod("CreateFromOptions");

            if (method == null)
            {
                throw new SpiderException("存储器未实现 CreateFromOptions 方法,无法自动创建");
            }

            var storage = method.Invoke(null, new object[] { options });

            if (storage == null)
            {
                throw new SpiderException("创建默认存储器失败");
            }

            return((StorageBase)storage);
        }
Пример #2
0
        internal static StorageBase GetDefaultStorage(SpiderOptions options)
        {
            var type = Type.GetType(options.Storage);

            if (type == null)
            {
                throw new SpiderException($"Storage type {options.Storage} not found");
            }

            if (!typeof(StorageBase).IsAssignableFrom(type))
            {
                throw new SpiderException($"{type} is not a storage dataFlow");
            }

            var method = type.GetMethod("CreateFromOptions");

            if (method == null)
            {
                throw new SpiderException($"Storage {type} didn't implement method CreateFromOptions");
            }

            var storage = method.Invoke(null, new object[] { options });

            if (storage == null)
            {
                throw new SpiderException("Create default storage failed");
            }

            return((StorageBase)storage);
        }
Пример #3
0
 public SpiderParameters(IEventBus eventBus,
                         IStatisticsService statisticsService,
                         SpiderOptions options,
                         IServiceProvider services)
 {
     EventBus          = eventBus;
     StatisticsService = statisticsService;
     SpiderOptions     = options;
     ServiceProvider   = services;
 }
Пример #4
0
 public SpiderParameters(IMq mq,
                         IStatisticsService statisticsService,
                         SpiderOptions options,
                         IServiceProvider services)
 {
     Mq = mq;
     StatisticsService = statisticsService;
     SpiderOptions     = options;
     ServiceProvider   = services;
 }
Пример #5
0
 protected Spider(IOptions <SpiderOptions> options,
                  SpiderServices services,
                  ILogger <Spider> logger
                  )
 {
     Logger            = logger;
     _services         = services;
     _options          = options.Value;
     _requestedQueue   = new RequestedQueue(_options);
     _requestSuppliers = new List <IRequestSupplier>();
     _dataFlows        = new List <IDataFlow>();
 }
Пример #6
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="eventBus"></param>
 /// <param name="options"></param>
 /// <param name="logger"></param>
 /// <param name="services">服务提供接口</param>
 /// <param name="statisticsService"></param>
 public Spider(
     IEventBus eventBus,
     IStatisticsService statisticsService,
     SpiderOptions options,
     ILogger <Spider> logger,
     IServiceProvider services)
 {
     _services               = services;
     _statisticsService      = statisticsService;
     _eventBus               = eventBus;
     _options                = options;
     _logger                 = logger;
     Console.CancelKeyPress += ConsoleCancelKeyPress;
 }
Пример #7
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="eventBus"></param>
        /// <param name="options"></param>
        /// <param name="logger"></param>
        /// <param name="services">服务提供接口</param>
        /// <param name="statisticsService"></param>
        public Spider(
            IEventBus eventBus,
            IStatisticsService statisticsService,
            SpiderOptions options,
            ILogger <Spider> logger,
            IServiceProvider services)
        {
            Framework.RegisterEncoding();

            Services                = services;
            _statisticsService      = statisticsService;
            _eventBus               = eventBus;
            Options                 = options;
            Logger                  = logger;
            Console.CancelKeyPress += ConsoleCancelKeyPress;
        }
Пример #8
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="options">下载器代理选项</param>
 /// <param name="spiderOptions"></param>
 /// <param name="eventBus">消息队列</param>
 /// <param name="networkCenter">网络中心</param>
 /// <param name="logger">日志接口</param>
 public DefaultDownloaderAgent(DownloaderAgentOptions options,
                               SpiderOptions spiderOptions, IEventBus eventBus, NetworkCenter networkCenter,
                               ILogger <DefaultDownloaderAgent> logger) : base(options, spiderOptions, eventBus, networkCenter, logger)
 {
 }
Пример #9
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="eventBus">消息队列</param>
 /// <param name="downloaderAgentStore">下载器代理存储</param>
 /// <param name="options">系统选项</param>
 /// <param name="logger">日志接口</param>
 public DefaultDownloadAgentRegisterCenter(IEventBus eventBus, IDownloaderAgentStore downloaderAgentStore, SpiderOptions options,
                                           ILogger <DefaultDownloadAgentRegisterCenter> logger) : base(eventBus, downloaderAgentStore, options, logger)
 {
 }