Пример #1
0
        public static void ProcessRelationshipInternal(MappingSet set, Relationship relationship, EntityProcessor processor)
        {
            Reference reference = processor.CreateReference(relationship, set.EntitySet);

            if (reference == null)
                return;

            RelationshipReferenceMapping mapping = new RelationshipReferenceMappingImpl();
            mapping.FromRelationship = relationship;
            mapping.ToReference = reference;
            //set.EntitySet.AddReference(reference);
            set.AddMapping(mapping);
        }
Пример #2
0
        protected override void OnInit(params string[] arguments)
        {
            Dictionary <string, object> headers = new Dictionary <string, object>();

            headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36");
            headers.Add("Request Method", "POST");
            AddHeaders("jzsc.mohurd.gov.cn", headers);
            AddRequests("http://jzsc.mohurd.gov.cn/dataservice/query/comp/list?$pg=1");
            EntityProcessor <BaiduSearchEntry> tempmodel = AddEntityType <BaiduSearchEntry>();
            var pipeine = new ExcelEntityPipeline();

            AddPipeline(pipeine);
            AddEntityType <BaiduSearchEntry>().SetRequestExtractor(new AutoIncrementRequestExtractor(@"\$pg=1", 1)).SetLastPageChecker(new TestLastPageChecker());;
        }
Пример #3
0
        /// <summary>
        /// 添加爬虫实体类
        /// </summary>
        /// <typeparam name="T">爬虫实体类的类型, 必须继承自 ISpiderEntity</typeparam>
        /// <param name="dataHandler">对解析的结果进一步加工操作</param>
        public EntityProcessor <T> AddEntityType <T>(IDataHandler dataHandler) where T : IBaseEntity
        {
            CheckIfRunning();
            var typeName = typeof(T).FullName;

            if (_processors.ContainsKey(typeName))
            {
                return(_processors[typeName] as EntityProcessor <T>);
            }
            var processor = new EntityProcessor <T>(new ModelExtractor <T>(), dataHandler);

            _processors.Add(typeName, processor);
            AddPageProcessors(processor);
            return(_processors[typeName] as EntityProcessor <T>);
        }
Пример #4
0
        public void TargetUrlsSelector_2Region_2Pattern()
        {
            var entity1   = EntitySpider.ParseEntityMetaData(typeof(Entity18).GetTypeInfo());
            var processor = new EntityProcessor(new Site(), entity1);

            Assert.AreEqual(2, processor.GetTargetUrlPatterns("//*[@id=\"1111\"]").Count);
            Assert.AreEqual(@"&page=[0-9]+&", processor.GetTargetUrlPatterns("//*[@id=\"1111\"]")[0].ToString());
            Assert.AreEqual(@"&page=[0-1]+&", processor.GetTargetUrlPatterns("//*[@id=\"1111\"]")[1].ToString());

            Assert.AreEqual(2, processor.GetTargetUrlPatterns("//*[@id=\"2222\"]").Count);
            Assert.AreEqual(@"&page=[0-9]+&", processor.GetTargetUrlPatterns("//*[@id=\"2222\"]")[0].ToString());
            Assert.AreEqual(@"&page=[0-1]+&", processor.GetTargetUrlPatterns("//*[@id=\"2222\"]")[1].ToString());

            Assert.IsTrue(processor.GetTargetUrlPatterns("//*[@id=\"3333\"]") == null);
        }
Пример #5
0
        public void HandlerWhenExtractZeroResult()
        {
            var entityMetadata = EntityDefine.Parse <Product>();
            var identity       = Guid.NewGuid().ToString("N");

            entityMetadata.DataHandler = new MyDataHanlder(identity);
            EntityProcessor processor = new EntityProcessor(new Site(), entityMetadata);

            processor.Process(new Page(new Request("http://www.abcd.com"))
            {
                Content = "{'data':[{'name':'1'},{'name':'2'}]}"
            });
            Assert.True(File.Exists(identity));
            File.Delete(identity);
        }
        public void TargetUrlsSelector_2Region_2Pattern()
        {
            new EntityDefine <Entity18>();
            var processor = new EntityProcessor <Entity18>();

            Assert.Equal(2, processor.GetTargetUrlPatterns("//*[@id=\"1111\"]").Count);
            Assert.Equal(@"&page=[0-9]+&", processor.GetTargetUrlPatterns("//*[@id=\"1111\"]")[0].ToString());
            Assert.Equal(@"&page=[0-1]+&", processor.GetTargetUrlPatterns("//*[@id=\"1111\"]")[1].ToString());

            Assert.Equal(2, processor.GetTargetUrlPatterns("//*[@id=\"2222\"]").Count);
            Assert.Equal(@"&page=[0-9]+&", processor.GetTargetUrlPatterns("//*[@id=\"2222\"]")[0].ToString());
            Assert.Equal(@"&page=[0-1]+&", processor.GetTargetUrlPatterns("//*[@id=\"2222\"]")[1].ToString());

            Assert.True(processor.GetTargetUrlPatterns("//*[@id=\"3333\"]") == null);
        }
        public void Correct_Entities_Are_Created()
        {
            EntityProcessor proc = MockRepository.GenerateMock <EntityProcessor>();

            Entity entity1 = new EntityImpl();

            proc.Stub(p => p.CreateEntity(Table1)).Return(entity1);

            MappingProcessor mappingProc = new MappingProcessor(proc);

            mappingProc.CreateOneToOneMappingsFor(new[] { Table1 }, Set);

            proc.AssertWasCalled(p => p.CreateEntity(Table1));
            proc.AssertWasNotCalled(p => p.CreateEntity(Table2));
        }
Пример #8
0
        public void HandlerWhenExtractZeroResult()
        {
            var entityMetadata = EntitySpider.GenerateEntityMetaData(typeof(Product).GetTypeInfo());
            var identity       = Guid.NewGuid().ToString("N");

            entityMetadata.DataHandler = new MyDataHanlder(identity);
            EntityProcessor processor = new EntityProcessor(new Site(), entityMetadata);

            processor.Process(new Page(new Request("http://www.abcd.com"))
            {
                Content     = "{}",
                ContentType = ContentType.Json
            });
            Assert.IsTrue(File.Exists(identity));
            File.Delete(identity);
        }
Пример #9
0
        protected virtual Core.Spider GenerateSpider(IScheduler scheduler)
        {
            EntityProcessor processor = new EntityProcessor(SpiderContext);

            processor.TargetUrlExtractInfos = SpiderContext.TargetUrlExtractInfos?.Select(t => t.GetTargetUrlExtractInfo()).ToList();
            foreach (var entity in SpiderContext.Entities)
            {
                processor.AddEntity(entity);
            }

            EntityGeneralSpider spider = new EntityGeneralSpider(SpiderContext.Site, Name, SpiderContext.UserId, SpiderContext.TaskGroup, processor, scheduler);

            foreach (var entity in SpiderContext.Entities)
            {
                string entiyName = entity.Identity;

                var schema = entity.Schema;

                List <IEntityPipeline> pipelines = new List <IEntityPipeline>();
                foreach (var pipeline in SpiderContext.Pipelines)
                {
                    pipelines.Add(pipeline.GetPipeline(schema, entity));
                }
                spider.AddPipeline(new EntityPipeline(entiyName, pipelines));
            }
            spider.SetCachedSize(SpiderContext.CachedSize);
            spider.SetEmptySleepTime(SpiderContext.EmptySleepTime);
            spider.SetThreadNum(SpiderContext.ThreadNum);
            spider.Deep = SpiderContext.Deep;
            spider.SetDownloader(SpiderContext.Downloader.GetDownloader());
            spider.SkipWhenResultIsEmpty = SpiderContext.SkipWhenResultIsEmpty;
            if (SpiderContext.PageHandlers != null)
            {
                spider.PageHandlers = new List <Action <Page> >();
                foreach (var pageHandler in SpiderContext.PageHandlers)
                {
                    spider.PageHandlers.Add(pageHandler.Customize);
                }
            }

            if (SpiderContext.TargetUrlsHandler != null)
            {
                spider.SetCustomizeTargetUrls(SpiderContext.TargetUrlsHandler.Handle);
            }

            return(spider);
        }
Пример #10
0
        public void HandleModel()
        {
            var model = new ModelDefine <Product>();
            EntityProcessor <Product> processor = new EntityProcessor <Product>(null, null, new MyDataHandler());

            processor.Process(new Page(new Request("http://www.abcd.com")
            {
                Site = new Site()
            })
            {
                Content = "{'data':[{'name':'aaaa'},{'name':'bbbb'}]}"
            }, null);
            Assert.True(File.Exists("file.aaaa"));
            Assert.True(File.Exists("file.bbbb"));
            File.Delete("file.aaaa");
            File.Delete("file.bbbb");
        }
Пример #11
0
        public void HandlerWhenExtractZeroResult()
        {
            var entityMetadata = new ModelDefine <Product>();
            var identity       = Guid.NewGuid().ToString("N");

            EntityProcessor <Product> processor = new EntityProcessor <Product>(null, null, new MyDataHanlder(identity));

            processor.Process(new Page(new Request("http://www.abcd.com")
            {
                Site = new Site()
            })
            {
                Content = "{'data':[{'name':'1'},{'name':'2'}]}"
            }, new DefaultSpider());
            Assert.True(File.Exists(identity));
            File.Delete(identity);
        }
Пример #12
0
        public void ModelProcess()
        {
            EntityProcessor <N> processor = new EntityProcessor <N>();
            var page = CreatePage();

            processor.Process(page);

            var results = page.ResultItems[typeof(N).FullName] as IEnumerable <dynamic>;
            var model   = results.First() as N;

            Assert.Equal(100, model.Int);
            Assert.True(model.Bool);
            Assert.Equal(200, model.BigInt);
            Assert.Equal("abcd", model.String);
            Assert.Equal(new DateTime(2018, 6, 3), model.DateTime);
            Assert.Equal(1.1F, model.Float);
            Assert.Equal(2.2D, model.Double);
            Assert.Equal((Decimal)0.8, model.Decimal);
        }
        public void ModelProcess()
        {
            EntityProcessor <N> processor = new EntityProcessor <N>();
            var page = CreatePage();

            processor.Process(page, null);

            var results = page.ResultItems.GetResultItem(processor.Model.Identity) as Tuple <IModel, IList <dynamic> >;
            var model   = results.Item2.First() as N;

            Assert.Equal(100, model.Int);
            Assert.True(model.Bool);
            Assert.Equal(200, model.BigInt);
            Assert.Equal("abcd", model.String);
            Assert.Equal(new DateTime(2018, 6, 3), model.DateTime);
            Assert.Equal(1.1F, model.Float);
            Assert.Equal(2.2D, model.Double);
            Assert.Equal((Decimal)0.8, model.Decimal);
        }
Пример #14
0
        public async Task FunctionHandler(string folderName, ILambdaContext context)
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                         .Build();

            var accessKey = config["accessKey"];
            var secretKet = config["secretKey"];

            var s3RegionName       = Environment.GetEnvironmentVariable("S3_region");
            var dynamoDbRegionName = Environment.GetEnvironmentVariable("DynamoDB_region");
            var bucketName         = Environment.GetEnvironmentVariable("S3_bucket_name");
            var tableName          = Environment.GetEnvironmentVariable("DynamoDB_table_name");

            var s3Repository       = new S3Repository(accessKey, secretKet, s3RegionName, bucketName);
            var dynamoDbRepository = new DynamoDbRepository(accessKey, secretKet, dynamoDbRegionName, tableName);
            var entityProcessor    = new EntityProcessor(s3Repository, dynamoDbRepository);

            await entityProcessor.ProcessFolder(folderName);
        }
        public void Insert()
        {
            var processor = new EntityProcessor <N>(new ModelExtractor());
            var spider    = new DefaultSpider();
            var page      = CreatePage();

            processor.Process(page, spider);
            var guid = Guid.NewGuid().ToString("N");
            RedisEntityPipeline pipeline = new RedisEntityPipeline(guid, connectString);

            pipeline.Process(new[] { page.ResultItems }, spider);

            var connection = ConnectionMultiplexer.Connect(connectString);
            var db         = connection.GetDatabase(0);
            var json       = db.ListRightPop(guid);
            var item       = LZ4MessagePackSerializer.Typeless.Deserialize(json) as Dictionary <string, object>;

            Assert.Equal("100", item["Int"]);
            Assert.Equal("2018-06-03", item["DateTime"]);
        }
        public void Correct_References_Are_Created()
        {
            EntityProcessor proc = MockRepository.GenerateMock <EntityProcessor>();

            Entity    entity1   = new EntityImpl();
            Entity    entity2   = new EntityImpl();
            Reference reference = new ReferenceImpl(entity1, entity2);

            proc.Stub(p => p.CreateEntity(Table1)).Return(entity1);
            proc.Stub(p => p.CreateEntity(Table2)).Return(entity2);
            proc.Stub(p => p.CreateReference(Relationship12, Set.EntitySet)).Return(reference);

            MappingProcessor mappingProc = new MappingProcessor(proc);

            mappingProc.CreateOneToOneMappingsFor(new[] { Table1, Table2 }, Set);

            proc.AssertWasCalled(p => p.CreateEntity(Table1));
            proc.AssertWasCalled(p => p.CreateEntity(Table2));
            proc.AssertWasCalled(p => p.CreateReference(Relationship12, Set.EntitySet));
            proc.AssertWasNotCalled(p => p.CreateReference(Relationship13, Set.EntitySet));
        }
Пример #17
0
        public EntityDefine AddEntityType(Type type, DataHandler dataHandler, string tableName)
        {
            CheckIfRunning();

            if (typeof(SpiderEntity).IsAssignableFrom(type))
            {
                var entity = EntityDefine.Parse(type.GetTypeInfoCrossPlatform());
                if (entity.TableInfo != null && !string.IsNullOrEmpty(tableName))
                {
                    entity.TableInfo.Name = tableName;
                }
                entity.DataHandler = dataHandler;

                Entities.Add(entity);
                EntityProcessor processor = new EntityProcessor(Site, entity);
                AddPageProcessor(processor);
                return(entity);
            }
            else
            {
                throw new SpiderException($"Type: {type.FullName} is not a SpiderEntity.");
            }
        }
        public virtual void DataTypes()
        {
            using (MySqlConnection conn = new MySqlConnection("Database='mysql';Data Source=localhost;User ID=root;Password=;Port=3306;SslMode=None;"))
            {
                try
                {
                    conn.Execute("use test;  drop table table15;");
                }
                catch
                {
                }

                var spider = new DefaultSpider();

                EntityProcessor <Entity15> processor = new EntityProcessor <Entity15>();

                var pipeline    = new MySqlEntityPipeline("Database='mysql';Data Source=localhost;User ID=root;Password=;Port=3306;SslMode=None;");
                var resultItems = new ResultItems();
                resultItems.Request = new Request();
                resultItems.AddOrUpdateResultItem(processor.Model.Identity,
                                                  new Tuple <IModel, IList <dynamic> >(processor.Model, new[] {
                    new Dictionary <string, dynamic>
                    {
                        { "int", "1" },
                        { "bool", "1" },
                        { "bigint", "11" },
                        { "string", "aaa" },
                        { "time", "2018-06-12" },
                        { "float", "1" },
                        { "double", "1" },
                        { "string1", "abc" },
                        { "string2", "abcdd" },
                        { "decimal", "1" }
                    }
                }));
                pipeline.Process(new ResultItems[] { resultItems }, spider.Logger, spider);

                var columns = conn.Query <ColumnInfo>("SELECT COLUMN_NAME as `Name`, COLUMN_TYPE as `Type` FROM information_schema.columns WHERE table_name='table15' AND table_schema = 'test';").ToList();;
                Assert.Equal(12, columns.Count);

                Assert.Equal("int".ToLower(), columns[0].Name);
                Assert.Equal("bool".ToLower(), columns[1].Name);
                Assert.Equal("bigint".ToLower(), columns[2].Name);
                Assert.Equal("string".ToLower(), columns[3].Name);
                Assert.Equal("time".ToLower(), columns[4].Name);
                Assert.Equal("float".ToLower(), columns[5].Name);
                Assert.Equal("double".ToLower(), columns[6].Name);
                Assert.Equal("string1".ToLower(), columns[7].Name);
                Assert.Equal("string2".ToLower(), columns[8].Name);
                Assert.Equal("decimal".ToLower(), columns[9].Name);
                Assert.Equal("creation_time".ToLower(), columns[10].Name);
                Assert.Equal("creation_date".ToLower(), columns[11].Name);


                Assert.Equal("int(11)", columns[0].Type);
                Assert.Equal("tinyint(1)", columns[1].Type);
                Assert.Equal("bigint(20)", columns[2].Type);
                Assert.Equal("varchar(255)", columns[3].Type);
                Assert.Equal("timestamp", columns[4].Type);
                Assert.Equal("float", columns[5].Type);
                Assert.Equal("double", columns[6].Type);
                Assert.Equal("varchar(100)", columns[7].Type);
                Assert.Equal("longtext", columns[8].Type);
                Assert.Equal("decimal(18,2)", columns[9].Type);
                Assert.Equal("timestamp", columns[10].Type);
                Assert.Equal("date", columns[11].Type);


                try
                {
                    conn.Execute("use test;  drop table table15;");
                }
                catch
                {
                }
            }
        }
Пример #19
0
        public void Run(MessageInterest messageInterest, CultureInfo culture)
        {
            Console.WriteLine(string.Empty);
            _log.Info("Running the OddsFeed SDK Complete example");

            var configuration = Feed.GetConfigurationBuilder().SetAccessTokenFromConfigFile().SelectIntegration().LoadFromConfigFile().Build();
            var oddsFeed      = new Feed(configuration);

            AttachToFeedEvents(oddsFeed);

            _log.Info("Creating IOddsFeedSessions");

            var session = oddsFeed.CreateBuilder()
                          .SetMessageInterest(messageInterest)
                          .Build();

            _culture = culture;

            var marketWriter      = new MarketWriter(_log, _taskProcessor, _culture);
            var sportEntityWriter = new SportEntityWriter(_taskProcessor, _culture);

            _log.Info("Creating entity specific dispatchers");
            var matchDispatcher           = session.CreateSportSpecificMessageDispatcher <IMatch>();
            var stageDispatcher           = session.CreateSportSpecificMessageDispatcher <IStage>();
            var tournamentDispatcher      = session.CreateSportSpecificMessageDispatcher <ITournament>();
            var basicTournamentDispatcher = session.CreateSportSpecificMessageDispatcher <IBasicTournament>();
            var seasonDispatcher          = session.CreateSportSpecificMessageDispatcher <ISeason>();

            _log.Info("Creating event processors");
            var defaultEventsProcessor         = new EntityProcessor <ISportEvent>(session, sportEntityWriter, marketWriter);
            var matchEventsProcessor           = new SpecificEntityProcessor <IMatch>(_log, matchDispatcher, sportEntityWriter, marketWriter);
            var stageEventsProcessor           = new SpecificEntityProcessor <IStage>(_log, stageDispatcher, sportEntityWriter, marketWriter);
            var tournamentEventsProcessor      = new SpecificEntityProcessor <ITournament>(_log, tournamentDispatcher, sportEntityWriter, marketWriter);
            var basicTournamentEventsProcessor = new SpecificEntityProcessor <IBasicTournament>(_log, basicTournamentDispatcher, sportEntityWriter, marketWriter);
            var seasonEventsProcessor          = new SpecificEntityProcessor <ISeason>(_log, seasonDispatcher, sportEntityWriter, marketWriter);

            _log.Info("Opening event processors");
            defaultEventsProcessor.Open();
            matchEventsProcessor.Open();
            stageEventsProcessor.Open();
            tournamentEventsProcessor.Open();
            basicTournamentEventsProcessor.Open();
            seasonEventsProcessor.Open();

            _log.Info("Opening the feed instance");

            oddsFeed.Open();

            _log.Info("Example successfully started. Hit <enter> to quit");
            Console.WriteLine(string.Empty);
            Console.ReadLine();

            _log.Info("Closing / disposing the feed");
            oddsFeed.Close();

            DetachFromFeedEvents(oddsFeed);

            _log.Info("Closing event processors");
            defaultEventsProcessor.Close();
            matchEventsProcessor.Close();
            stageEventsProcessor.Close();
            tournamentEventsProcessor.Close();
            basicTournamentEventsProcessor.Close();
            seasonEventsProcessor.Close();

            _log.Info("Waiting for asynchronous operations to complete");
            var waitResult = _taskProcessor.WaitForTasks();

            _log.Info($"Waiting for tasks completed. Result:{waitResult}");

            _log.Info("Stopped");
        }
Пример #20
0
        public override void Run(params string[] arguments)
        {
            InitEnvorimentAndVerify();

            try
            {
#if !NET_CORE
                if (CookieInterceptor != null)
                {
                    this.Log("尝试获取 Cookie...", LogLevel.Info);
                    var cookie = CookieInterceptor.GetCookie();
                    if (cookie == null)
                    {
                        this.Log("获取 Cookie 失败, 爬虫无法继续.", LogLevel.Warn);
                        return;
                    }
                    else
                    {
                        Site.CookiesStringPart = cookie.CookiesStringPart;
                        Site.Cookies           = cookie.CookiesDictionary;
                    }
                }
#endif

                this.Log("创建爬虫...", LogLevel.Info);
                EntityProcessor processor = new EntityProcessor(this);

                foreach (var entity in Entities)
                {
                    processor.AddEntity(entity);
                }
                PageProcessor = processor;
                foreach (var entity in Entities)
                {
                    string entiyName = entity.Entity.Name;
                    var    pipelines = new List <BaseEntityPipeline>();
                    foreach (var pipeline in EntityPipelines)
                    {
                        var newPipeline = pipeline.Clone();
                        newPipeline.InitiEntity(entity);
                        if (newPipeline.IsEnabled)
                        {
                            pipelines.Add(newPipeline);
                        }
                    }
                    if (pipelines.Count > 0)
                    {
                        Pipelines.Add(new EntityPipeline(entiyName, pipelines));
                    }
                }

                CheckIfSettingsCorrect();

                bool   needInitStartRequest = true;
                string key = "locker-" + Identity;
                if (Db != null)
                {
                    while (!Db.LockTake(key, "0", TimeSpan.FromMinutes(10)))
                    {
                        Thread.Sleep(1000);
                    }
                    var lockerValue = Db.HashGet(InitStatusSetName, Identity);
                    needInitStartRequest = lockerValue != "init finished";
                }

                if (arguments.Contains("rerun"))
                {
                    Scheduler.Init(this);
                    Scheduler.Clear();
                    //DELETE verify record.
                    Db?.HashDelete(ValidateStatusName, Identity);
                    needInitStartRequest = true;
                }

                this.Log("构建内部模块、准备爬虫数据...", LogLevel.Info);
                InitComponent();

                if (needInitStartRequest)
                {
                    if (PrepareStartUrls != null)
                    {
                        for (int i = 0; i < PrepareStartUrls.Length; ++i)
                        {
                            var prepareStartUrl = PrepareStartUrls[i];
                            this.Log($"[步骤 {i + 2}] 添加链接到调度中心.", LogLevel.Info);
                            prepareStartUrl.Build(this, null);
                        }
                    }
                }

                MonitorCenter.Register(this);

                Db?.LockRelease(key, 0);

                RegisterControl(this);

                if (!arguments.Contains("running-test"))
                {
                    base.Run();
                }
                else
                {
                    IsExited = true;
                }

                TaskFinished();

                HandleVerifyCollectData();
            }
            finally
            {
                Dispose();
                MonitorCenter.Dispose();
            }
        }
Пример #21
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            IsMouseVisible = true;

            var worldSpriteBatch = new SpriteBatchProxy(new SpriteBatch(GraphicsDevice));
            var hudSpriteBatch = new SpriteBatchProxy(new SpriteBatch(GraphicsDevice));
            _world = new World(Vector2.Zero);
            var physicsUpdater = new WorldUpdateableAdapter(_world);
            var controllersProcessor = new EntityProcessor<IController>();
            var controllersUpdater = new EntityUpdater<IController>(controllersProcessor);
            var modelsProcessor = new EntityProcessor<IModel>();
            var modelsUpdater = new EntityUpdater<IModel>(modelsProcessor);
            var viewsProcessor = new EntityProcessor<IView>();
            var viewsUpdater = new EntityUpdater<IView>(viewsProcessor);

            var worldMapViewProcessor = new EntityProcessor<IView>();
            var worldCharacterViewProcessor = new EntityProcessor<IView>();

            var worldViewCamera = new Camera(worldSpriteBatch) { ViewProcessors = new[] { worldMapViewProcessor, worldCharacterViewProcessor } };
            var hudViewCamera = new Camera(hudSpriteBatch);
            var updateStepMultiplexer = new UpdationMultiplexer { Updateables = { controllersUpdater, modelsUpdater, physicsUpdater, } };
            var drawMultiplexer = new DrawingMultiplexer { Drawables = { worldViewCamera, hudViewCamera } };
            _screen = new GameStateAdapter { UpdateStepUpdateable = updateStepMultiplexer, DrawStepUpdateable = viewsUpdater, Drawable = drawMultiplexer };

            var map = Content.Load<Map>("01");
            //добавить мапу как вьюху
            var mapView = new MapView(map);
            worldMapViewProcessor.Collect(mapView);

            //добавить стены в мир
            var wallBody = new Body(_world, Vector2.Zero);
            var verticesArrays = map.ObjectLayers["walls"].MapObjects
                .Select(mapObject => new Vertices(mapObject.Polyline.Points.Select(p => new Vector2(p.X/10f, p.Y/10f))));
            foreach (var vertices in verticesArrays)
                FixtureFactory.AttachChainShape(vertices, wallBody);

            //добавить танки как полноценные тройки MVC
            var bodyTexture = Content.Load<Texture2D>("body");
            var towerTexture = Content.Load<Texture2D>("tower");
            var bulletTexture = Content.Load<Texture2D>("bullet");

            IBulletModelFactory bulletModelFactory = new BulletModelFactory(_world);
            IBulletViewFactory bulletViewFactory = new BulletViewFactory(bulletTexture);
            IBulletSpawner bulletSpawner = new BulletSpawner(modelsProcessor, viewsProcessor, worldCharacterViewProcessor, bulletModelFactory, bulletViewFactory);

            ITankTowerFactory tankTowerFactory = new TankTowerFactory(bulletSpawner);
            ITankModelFactory tankModelFactory = new TankModelFactory(_world, tankTowerFactory);
            ITankViewFactory tankViewFactory = new TankViewFactory(bodyTexture, towerTexture);
            ITankControllerFactory tankUserControllerFactory = new TankUserControllerFactory();
            ITankControllerFactory tankEnemyControllerFactory = new TankEnemyControllerFactory();

            ITankSpawner userTankSpawner = new TankSpawner(modelsProcessor, controllersProcessor, viewsProcessor, worldCharacterViewProcessor, tankModelFactory, tankViewFactory, tankUserControllerFactory);
            ITankSpawner enemyTankSpawner = new TankSpawner(modelsProcessor, controllersProcessor, viewsProcessor, worldCharacterViewProcessor, tankModelFactory, tankViewFactory, tankEnemyControllerFactory);

            foreach (var mapObject in map.ObjectLayers["entities"].MapObjects)
            {
                var position = new Vector2(mapObject.Bounds.X/10f, mapObject.Bounds.Y/10f);
                var rotation = 0;
                switch (mapObject.Type)
                {
                    case "Player":
                        userTankSpawner.Spawn(position, rotation);
                        break;
                    case "Enemy":
                        enemyTankSpawner.Spawn(position, rotation);
                        break;
                }
            }

            foreach (var mapObject in map.ObjectLayers["triggers"].MapObjects)
            {
                if (mapObject.Type == "VictoryPoint")
                {
                    var body = new Body(_world, Vector2.Zero) { IsSensor = true };
                    FixtureFactory.AttachPolygon(new Vertices(mapObject.Polygon.Points.Select(p => new Vector2(p.X/10f, p.Y/10f))), 1, body);
                    body.OnCollision += (a, b, contact) => { Exit(); return false; };
                }
            }
        }
Пример #22
0
 public static void Run()
 {
     var entityProcessor = new EntityProcessor <BaiduSearchEntry>();
     var spider          = Spider.Create();
 }
Пример #23
0
 public EntityIndexer(
     EntityProcessor processor,
     EntityIndexerOptionManager optionManager,
     FastAdapter adapter) : base(processor, optionManager, adapter)
 {
 }
Пример #24
0
        private Core.Spider GenerateSpider(IScheduler scheduler)
        {
            Site            site      = _spiderContext.Site;
            EntityProcessor processor = new EntityProcessor(site);

            foreach (var entity in _spiderContext.Entities)
            {
                processor.AddEntity(entity);
            }

            EntityGeneralSpider spider = new EntityGeneralSpider(_spiderContext.SpiderName, processor, scheduler);

            foreach (var entity in _spiderContext.Entities)
            {
                string entiyName    = entity.SelectToken("$.Identity")?.ToString();
                var    pipelineType = _spiderContext.Pipeline.SelectToken("$.Type").ToObject <Configuration.Pipeline.Types>();
                var    schema       = entity.SelectToken("$.Schema")?.ToObject <Schema>();

                switch (pipelineType)
                {
                case Configuration.Pipeline.Types.MongoDb:
                {
                    var mongoDbPipelineConfig = _spiderContext.Pipeline.ToObject <MongoDbPipeline>();
                    spider.AddPipeline(new EntityPipeline(entiyName, mongoDbPipelineConfig.GetPipeline(schema, entity)));

                    break;
                }

                case Configuration.Pipeline.Types.MySql:
                {
                    var mysqlPipelineConfig = _spiderContext.Pipeline.ToObject <MysqlPipeline>();
                    spider.AddPipeline(new EntityPipeline(entiyName, mysqlPipelineConfig.GetPipeline(schema, entity)));
                    break;
                }

                case Configuration.Pipeline.Types.MySqlFile:
                {
                    var mysqlFilePipelineConfig = _spiderContext.Pipeline.ToObject <MysqlFilePipeline>();

                    spider.AddPipeline(new EntityPipeline(entiyName, mysqlFilePipelineConfig.GetPipeline(schema, entity)));
                    break;
                }
                }
            }
            spider.SetCachedSize(_spiderContext.CachedSize);
            spider.SetEmptySleepTime(_spiderContext.EmptySleepTime);
            spider.SetThreadNum(_spiderContext.ThreadNum);
            spider.Deep = _spiderContext.Deep;
            spider.SetDownloader(GenerateDownloader());

            if (_spiderContext.CustomizePage != null)
            {
                var customizePageType = _spiderContext.CustomizePage.SelectToken("$.Type").ToObject <CustomizePage.Types>();
                switch (customizePageType)
                {
                case CustomizePage.Types.Sub:
                {
                    var customizePage = _spiderContext.CustomizePage.ToObject <SubCustomizePage>();
                    spider.CustomizePage = customizePage.Customize;
                    break;
                }
                }
            }

            if (_spiderContext.CustomizeTargetUrls != null)
            {
                var customizeTargetUrlsType = _spiderContext.CustomizeTargetUrls.SelectToken("$.Type").ToObject <CustomizeTargetUrls.Types>();
                switch (customizeTargetUrlsType)
                {
                case CustomizeTargetUrls.Types.IncreasePageNumber:
                {
                    var customizeTargetUrls = _spiderContext.CustomizeTargetUrls.ToObject <IncreasePageNumberCustomizeTargetUrls>();
                    spider.SetCustomizeTargetUrls(customizeTargetUrls.Customize);
                    break;
                }
                }
            }

            return(spider);
        }
Пример #25
0
 public EntityPusher(
     EntityPusherOptionManager optionManager,
     EntityProcessor processor,
     FastAdapter adapter) : base(optionManager, processor, adapter)
 {
 }
Пример #26
0
        public static void ProcessRelationshipInternal(MappingSet set, Relationship relationship, EntityProcessor processor)
        {
            Reference reference = processor.CreateReference(relationship, set.EntitySet);

            if (reference == null)
            {
                return;
            }

            RelationshipReferenceMapping mapping = new RelationshipReferenceMappingImpl();

            mapping.FromRelationship = relationship;
            mapping.ToReference      = reference;
            //set.EntitySet.AddReference(reference);
            set.AddMapping(mapping);
        }
Пример #27
0
 public void AddEntityProcessor(EntityProcessor processor)
 {
     processor.Game  = _game;
     processor.Scene = this;
     _entityProcessors.add(processor);
 }
Пример #28
0
        public override void DataTypes()
        {
            if (!Env.IsWindows)
            {
                return;
            }
            using (var conn = new SqlConnection("Server=.\\SQLEXPRESS;Database=master;Trusted_Connection=True;MultipleActiveResultSets=true"))
            {
                try
                {
                    conn.Execute("create database test;");
                }
                catch
                {
                }
                try
                {
                    conn.Execute("USE [test]; drop table [test].dbo.[table15]");
                }
                catch
                {
                }


                var spider = new DefaultSpider();

                EntityProcessor <Entity15> processor = new EntityProcessor <Entity15>();

                var pipeline    = new SqlServerEntityPipeline("Server=.\\SQLEXPRESS;Database=master;Trusted_Connection=True;MultipleActiveResultSets=true");
                var resultItems = new ResultItems();
                resultItems.Request = new Request();
                resultItems.AddOrUpdateResultItem(processor.Model.Identity, new Tuple <IModel, IEnumerable <dynamic> >(processor.Model, new dynamic[] {
                    new Dictionary <string, dynamic>
                    {
                        { "int", "1" },
                        { "bool", "1" },
                        { "bigint", "11" },
                        { "string", "aaa" },
                        { "time", "2018-06-12" },
                        { "float", "1" },
                        { "double", "1" },
                        { "string1", "abc" },
                        { "string2", "abcdd" },
                        { "decimal", "1" }
                    }
                }));
                pipeline.Process(new ResultItems[] { resultItems }, spider);

                var columns = conn.Query <ColumnInfo>("USE [test];select  b.name Name,c.name+'(' + cast(c.length as varchar)+')' [Type] from sysobjects a,syscolumns b,systypes c where a.id=b.id and a.name='table15' and a.xtype='U'and b.xtype=c.xtype").ToList();
                Assert.Equal(15, columns.Count);

                Assert.Equal("creation_date".ToLower(), columns[0].Name);
                Assert.Equal("int".ToLower(), columns[1].Name);
                Assert.Equal("time".ToLower(), columns[2].Name);
                Assert.Equal("creation_time".ToLower(), columns[3].Name);
                Assert.Equal("float".ToLower(), columns[4].Name);
                Assert.Equal("double".ToLower(), columns[5].Name);
                Assert.Equal("bool".ToLower(), columns[6].Name);
                Assert.Equal("decimal".ToLower(), columns[7].Name);
                Assert.Equal("bigint".ToLower(), columns[8].Name);
                Assert.Equal("string".ToLower(), columns[9].Name);
                Assert.Equal("string1".ToLower(), columns[10].Name);
                Assert.Equal("string2".ToLower(), columns[11].Name);


                Assert.Equal("date(3)", columns[0].Type);
                Assert.Equal("int(4)", columns[1].Type);
                Assert.Equal("datetime(8)", columns[2].Type);
                Assert.Equal("datetime(8)", columns[3].Type);
                Assert.Equal("float(8)", columns[4].Type);
                Assert.Equal("float(8)", columns[5].Type);
                Assert.Equal("bit(1)", columns[6].Type);
                Assert.Equal("decimal(17)", columns[7].Type);
                Assert.Equal("bigint(8)", columns[8].Type);
                Assert.Equal("nvarchar(8000)", columns[9].Type);
                Assert.Equal("nvarchar(8000)", columns[10].Type);
                Assert.Equal("nvarchar(8000)", columns[11].Type);

                conn.Execute("USE [test]; drop table [test].dbo.[table15]");
            }
        }
Пример #29
0
 public EntityPuller(EntityPullerOptionManager optionManager,
                     EntityProcessor processor,
                     FastAdapter adapter) : base(optionManager, processor, adapter)
 {
     this.adapter = adapter;
 }
Пример #30
0
 public MappingProcessor(EntityProcessor processor)
 {
     if (processor == null) throw new ArgumentNullException("processor");
     this.processor = processor;
 }