Ejemplo n.º 1
0
        private static Type GetSchedulerType()
        {
            var  schedulerName = NScrapyContext.GetInstance().CurrentConfig["AppSettings:Scheduler:SchedulerType"];
            Type schedulerType = null;

            if (string.IsNullOrEmpty(schedulerName))
            {
                return(typeof(Scheduler.InMemoryScheduler));
            }
            else
            {
                Assembly schedulerAssembly = null;
                var      assemblyName      = NScrapyContext.GetInstance().CurrentConfig["AppSettings:Scheduler:SchedulerTypeAssembly"];
                if (string.IsNullOrEmpty(assemblyName))
                {
                    schedulerAssembly = Assembly.LoadFrom(Path.Combine(Directory.GetCurrentDirectory(), "NScrapy.Scheduler.dll"));
                }
                else
                {
                    schedulerAssembly = Assembly.LoadFrom(Path.Combine(Directory.GetCurrentDirectory(), assemblyName));
                }
                schedulerType = schedulerAssembly.GetType(schedulerName);
                if (!schedulerType.GetInterfaces().Contains(typeof(IScheduler)))
                {
                    throw new TypeLoadException($"{schedulerName} must implement NScrapy.Infra.IScheduler interface");
                }
            }
            return(schedulerType);
        }
Ejemplo n.º 2
0
 private NScrapy()
 {
     ConfigSerivces();
     this._context = NScrapyContext.GetInstance();
     this._context.ConfigRefreshed += _context_ConfigRefreshed;
     SetServices();
 }
Ejemplo n.º 3
0
        private static Type GetEngineType()
        {
            var  engineName = NScrapyContext.GetInstance().CurrentConfig["AppSettings:SpiderEngine:SpiderEngineName"];
            Type engineType = null;

            if (string.IsNullOrEmpty(engineName))
            {
                return(typeof(NScrapyEngine));
            }
            else
            {
                Assembly engineAssembly     = null;
                var      engineAssemblyName = NScrapyContext.GetInstance().CurrentConfig["AppSettings:SpiderEngine:SpiderEngineAssembly"];
                if (engineAssemblyName != null)
                {
                    engineAssembly = Assembly.LoadFrom(engineAssemblyName);
                }
                else
                {
                    engineAssembly = Assembly.GetEntryAssembly();
                }
                engineType = engineAssembly.GetType(engineName);
                if (!engineType.GetInterfaces().Contains(typeof(IEngine)))
                {
                    throw new TypeLoadException($"{engineName} must implement NScrapy.Infra.IEngin interface");
                }
            }

            return(engineType);
        }
Ejemplo n.º 4
0
        public void NScrapyContextConfigProviderTest()
        {
            var context = NScrapyContext.GetInstance();

            context.ConfigProvider = new MockConfigProvider();
            Assert.AreEqual("192.168.0.103:2181", context.CurrentConfig["AppSettings:ZookeeperEndpoint"]);
        }
Ejemplo n.º 5
0
 private NScrapy()
 {
     ConfigSerivces();
     this._context = NScrapyContext.GetInstance();
     this._context.CurrentEngine = this._provider.GetService <IEngine>();
     //This is a temp solution, later on we will implement IOC in this place so we can chose other approach to filter the url
     this._context.UrlFilter = new InMemoryUrlFilter();
     Scheduler.RequestReceiver.StartReceiver();
     Scheduler.ResponseDistributer.StartDistribuiter();
 }