Example #1
0
        public void RetryWhenResultIsEmpty()
        {
            //TODO:
            var spider = SpiderFactory.Create <Spider>();

            spider.Id                     = Guid.NewGuid().ToString("N");
            spider.Name                   = "RetryWhenResultIsEmpty";
            spider.Speed                  = 1;
            spider.Depth                  = 3;
            spider.EmptySleepTime         = 2;
            spider.RetryDownloadTimes     = 5;
            spider.RetryWhenResultIsEmpty = false;
            spider.DownloaderOptions.Type = DownloaderType.HttpClient;
            spider.Scheduler              = new QueueDistinctBfsScheduler();
            spider.AddRequests("http://www.devfans.com/home/testempty");
            spider.RunAsync().Wait(); // 启动

            var statisticsStore = SpiderFactory.GetStatisticsStore();
            var s = statisticsStore.GetSpiderStatisticsAsync(spider.Id).Result;

            Assert.Equal(6, s.Total);
            Assert.Equal(6, s.Failed);
            Assert.Equal(0, s.Success);

            var ds = statisticsStore.GetDownloadStatisticsListAsync(1, 10).Result[0];

            Assert.Equal(6, ds.Failed);
            Assert.Equal(0, ds.Success);
        }
Example #2
0
        public void ParallelPubAndSub()
        {
            if (Directory.Exists("/home/vsts/work"))
            {
                return;
            }

            int count   = 0;
            var options = SpiderFactory.GetRequiredService <ISpiderOptions>();
            var logger  = SpiderFactory.GetRequiredService <ILogger <KafkaMessageQueue> >();
            var mq      = new KafkaMessageQueue(options, logger);

            mq.Subscribe("ParallelPubAndSub", msg => { Interlocked.Increment(ref count); });

            Parallel.For(0, 100, async(i) => { await mq.PublishAsync("ParallelPubAndSub", "a"); });
            int j = 0;

            while (count < 100 && j < 150)
            {
                Thread.Sleep(500);
                ++j;
            }

            Assert.Equal(100, count);
        }
Example #3
0
        public void ParseEntity()
        {
            var service     = SpiderFactory.CreateScopeServiceProvider();
            var dataContext = new DataFlowContext(new Response
            {
                Request = new Request("https://list.jd.com/list.html?cat=9987,653,655",
                                      new Dictionary <string, string>
                {
                    { "cat", "手机" },
                    { "cat3", "110" }
                }),
                RawText = File.ReadAllText("Jd.html")
            }, service);

            DataParser <Product> extractor = new DataParser <Product>();


            extractor.HandleAsync(dataContext).GetAwaiter().GetResult();

            var results = (ParseResult <Product>)dataContext.GetParseItem(typeof(Product).FullName);

            Assert.Equal(60, results.Count);
            Assert.Equal("手机", results[0].CategoryName);
            Assert.Equal(110, results[0].CategoryId);
            Assert.Equal("https://item.jd.com/3031737.html", results[0].Url);
            Assert.Equal("3031737", results[0].Sku);
            Assert.Equal("荣耀官方旗舰店", results[0].ShopName);
            Assert.Equal("荣耀 NOTE 8 4GB+32GB 全网通版 冰河银", results[0].Name);
            Assert.Equal("1000000904", results[0].VenderId);
            Assert.Equal("1000000904", results[0].JdzyShopId);
            Assert.Equal(DateTime.Now.ToString("yyyy-MM-dd"), results[0].RunId.ToString("yyyy-MM-dd"));
        }
        public async Task CreateTableNoSchema()
        {
            using (var conn = CreateConnection())
            {
                // 如果实体的 Schema 没有配置表名,则使用类名
                await conn.ExecuteAsync("drop table if exists createtableentity1;");

                var services = SpiderFactory.CreateScopeServiceProvider();
                var storage  = CreateStorage(StorageType.Insert);
                var dfc      = new DataFlowContext(null, services);
                var typeName = typeof(CreateTableEntity1).FullName;
                var entity   = new CreateTableEntity1();
                dfc.Add(typeName, entity.GetTableMetadata());
                var items = new ParseResult <CreateTableEntity1>
                {
                    entity
                };
                dfc.AddParseItem(typeName, items);
                await storage.HandleAsync(dfc);

                var list = (await conn.QueryAsync <CreateTableEntity1>("SELECT * FROM createtableentity1")).ToList();
                Assert.Single(list);
                entity = list.First();
                Assert.Equal("xxx", entity.Str1);
                Assert.Equal("yyy", entity.Str2);
                Assert.Equal(655, entity.Required);
                Assert.Equal(0, entity.Decimal);
                Assert.Equal(600, entity.Long);
                Assert.Equal(400, entity.Double);
                Assert.Equal(200.0F, entity.Float);
                await conn.ExecuteAsync("drop table if exists createtableentity1;");
            }
        }
Example #5
0
        public GameSession(TileSet tileSet, int maxPlayersAllowed,
                           GameMode gameType, int gameID, int teams)
        {
            //	SessionTeamsList = new TeamsList();

            for (int i = 1; i <= teams; i++)
            {
                _sessionTeamsList.Teams.Add(new Team(i));
            }

            IsStarted = false;
            GameLevel = new GameLevel(Constants.LEVEL_WIDTH, Constants.LEVEL_HEIGHT, tileSet);

            var playerNames = new List <string>();

            _gameObjects = new List <AGameObject>();
            _newObjects  = new List <AGameObject>();

            LocalGameDescription = new GameDescription(playerNames, maxPlayersAllowed, gameType, gameID, tileSet, teams);
            if (gameType == GameMode.Deathmatch)
            {
                _spiderFactory = new DeathmatchSpiderFactory(GameLevel);
            }
            else
            {
                _spiderFactory = new DefaultSpiderFactory(GameLevel);
            }
            _bonusFactory = new BonusFactory();
            _wallFactory  = new WallFactory(GameLevel);
        }
Example #6
0
        public void RetryDownloadTimes()
        {
            // 配置使用 TestDownloader, 一直抛错,检测到达指定尝试次数是否不再重试。
            var spider = SpiderFactory.Create <Spider>();

            spider.Id                     = Guid.NewGuid().ToString("N");
            spider.Name                   = "RetryDownloadTimes";
            spider.Speed                  = 1;
            spider.Depth                  = 3;
            spider.EmptySleepTime         = 30;
            spider.RetryDownloadTimes     = 5;
            spider.DownloaderOptions.Type = DownloaderType.Exception;
            spider.Scheduler              = new QueueDistinctBfsScheduler();
            spider.AddRequests("http://www.baidu.com");
            spider.RunAsync().Wait(); // 启动

            var statisticsStore = SpiderFactory.GetStatisticsStore();
            var s = statisticsStore.GetSpiderStatisticsAsync(spider.Id).Result;

            Assert.Equal(6, s.Total);
            Assert.Equal(6, s.Failed);
            Assert.Equal(0, s.Success);

            var ds = statisticsStore.GetDownloadStatisticsListAsync(1, 10).Result[0];

            Assert.Equal(6, ds.Failed);
            Assert.Equal(0, ds.Success);
        }
        public void RunThenPauseThenContinueThenExit()
        {
            var url    = "http://www.RunThenPauseThenContinueThenExit.com/";
            var spider = SpiderFactory.Create <Spider>();

            spider.NewGuidId();
            spider.Name                    = "RunAsyncAndStop";
            spider.EmptySleepTime          = 15;
            spider.DownloaderSettings.Type = DownloaderType.Empty;

            for (int i = 0; i < 10000; i++)
            {
                spider.AddRequests(new Request(url + i));
            }

            spider.RunAsync();
            Thread.Sleep(2000);
            spider.Pause();
            Thread.Sleep(2000);
            spider.Continue();
            Thread.Sleep(2000);
            spider.Exit().WaitForExit();

            Assert.Equal(Status.Exited, spider.Status);
        }
        public void RetryDownloadTimes()
        {
            var spider = SpiderFactory.Create <Spider>();

            spider.NewGuidId();
            spider.Name = "RetryDownloadTimes";
            spider.RetryDownloadTimes      = 5;
            spider.EmptySleepTime          = 15;
            spider.DownloaderSettings.Type = DownloaderType.Exception;
            var scheduler = new QueueDistinctBfsScheduler();

            spider.Scheduler = scheduler;
            spider.AddRequests("http://www.RetryDownloadTimes.com");
            spider.Run();

            var statisticsStore = SpiderFactory.GetRequiredService <IStatisticsStore>();
            var s = statisticsStore.GetSpiderStatisticsAsync(spider.Id).Result;

            Assert.Equal(1, s.Total);
            Assert.Equal(1, s.Failed);
            Assert.Equal(0, s.Success);

            var dss = statisticsStore.GetDownloadStatisticsListAsync(1, 10).Result;
            var ds  = dss[0];

            Assert.Equal(6, ds.Failed);
            Assert.Equal(0, ds.Success);
        }
        public MainWindow()
        {
            InitializeComponent();

            try
            {
                this.logger = Gnosis.Utilities.Log4NetLogger.GetDefaultLogger(typeof(MainWindow));
            }
            catch (Exception loggerEx)
            {
                throw new ApplicationException("Could not initialize logger", loggerEx);
            }

            try
            {
                logger.Info("Initializing Alexandria");

                mediaFactory    = new MediaFactory(logger);
                securityContext = new SecurityContext(mediaFactory);
                tagTypeFactory  = new TagTypeFactory();

                mediaRepository = new SQLiteMediaRepository(logger, mediaFactory);
                mediaRepository.Initialize();

                linkRepository = new SQLiteLinkRepository(logger);
                linkRepository.Initialize();

                tagRepository = new SQLiteTagRepository(logger, tagTypeFactory);
                tagRepository.Initialize();

                metadataRepository = new SQLiteMetadataRepository(logger, securityContext, mediaFactory);
                metadataRepository.Initialize();

                marqueeRepository = new SQLiteMarqueeRepository(logger);

                audioStreamFactory = new AudioStreamFactory();

                videoPlayer = new Gnosis.Video.Vlc.VideoPlayerControl();
                videoPlayer.Initialize(logger, () => GetVideoHost());

                catalogController = new CatalogController(logger, securityContext, mediaFactory, mediaRepository, linkRepository, tagRepository, metadataRepository, audioStreamFactory);
                spiderFactory     = new SpiderFactory(logger, securityContext, mediaFactory, linkRepository, tagRepository, mediaRepository, metadataRepository, audioStreamFactory);

                metadataController = new MediaItemController(logger, securityContext, mediaFactory, linkRepository, tagRepository, metadataRepository);
                taskController     = new TaskController(logger, mediaFactory, videoPlayer, spiderFactory, metadataController, marqueeRepository, metadataRepository);
                tagController      = new TagController(logger, tagRepository);
                commandController  = new CommandController(logger);

                taskResultView.Initialize(logger, securityContext, mediaFactory, metadataController, taskController, tagController, videoPlayer);
                //taskManagerView.Initialize(logger, taskController, taskResultView);
                searchView.Initialize(logger, taskController, taskResultView);
                commandView.Initialize(logger, commandController, taskController, taskResultView);

                ScreenSaver.Disable();
            }
            catch (Exception ex)
            {
                logger.Error("MainWindow.ctor", ex);
            }
        }
Example #10
0
        public async Task PubAndUnSub()
        {
            if (Directory.Exists("/home/vsts/work"))
            {
                return;
            }

            int count   = 0;
            var options = SpiderFactory.GetRequiredService <ISpiderOptions>();
            var logger  = SpiderFactory.GetRequiredService <ILogger <KafkaMessageQueue> >();
            var mq      = new KafkaMessageQueue(options, logger);

            mq.Subscribe("PubAndUnSub", msg => { Interlocked.Increment(ref count); });

            int i = 0;

            Task.Factory.StartNew(async() =>
            {
                for (; i < 50; ++i)
                {
                    await mq.PublishAsync("PubAndUnSub", "a");
                    await Task.Delay(100);
                }
            }).ConfigureAwait(false).GetAwaiter();
            await Task.Delay(1500);

            mq.Unsubscribe("PubAndUnSub");

            while (i < 50)
            {
                await Task.Delay(100);
            }

            Assert.True(count < 100);
        }
		public async Task UpdatePartColumns()
		{
			using (var conn = CreateConnection())
			{
				// 如果实体的 Schema 没有配置表名,则使用类名
				await conn.ExecuteAsync(
					$"drop table if exists {Escape}test{Escape}.{Escape}updatepartcolumns{Escape};");
				var services = SpiderFactory.CreateScopeServiceProvider();
				var storage = CreateStorage(StorageType.InsertIgnoreDuplicate);
				var dfc = new DataFlowContext(null, services);
				var typeName = typeof(CreateTableEntity6).FullName;
				var entity = new CreateTableEntity6();
				dfc.Add(typeName, entity.GetTableMetadata());
				var items = new ParseResult<CreateTableEntity6>
				{
					entity
				};
				dfc.AddParseItem(typeName, items);
				await storage.HandleAsync(dfc);

				var dfc2 = new DataFlowContext(null, services);
				dfc2.Add(typeName, entity.GetTableMetadata());
				var now = DateTime.Now;
				dfc2.AddParseItem(typeName, new ParseResult<CreateTableEntity6>
				{
					new CreateTableEntity6
					{
						Str1 = "TTT",
						DateTime = now,
						DateTimeOffset = now,
						Double = 888,
						Float = 999F,
						Required = 888
					}
				});
				var storage2 = CreateStorage(StorageType.Update);
				await storage2.HandleAsync(dfc2);

				var list = (await conn.QueryAsync<CreateTableEntity6>(
						$"SELECT * FROM {Escape}test{Escape}.{Escape}updatepartcolumns{Escape}"))
					.ToList();
				Assert.Single(list);
				entity = list.First();
				Assert.Equal("TTT", entity.Str1);
				Assert.Equal("yyy", entity.Str2);
				Assert.Equal(655, entity.Required);
				Assert.Equal(0, entity.Decimal);
				Assert.Equal(600, entity.Long);
				Assert.Equal(888, entity.Double);
				Assert.Equal(200.0F, entity.Float);

				await conn.ExecuteAsync(
					$"drop table if exists {Escape}test{Escape}.{Escape}updatepartcolumns{Escape};");
			}
		}
Example #12
0
            public void DifficultyRange(SpiderTypes type, int difficulty)
            {
                const int MaxDeviation_ATT = 2;
                const int MaxDeviation_DEF = 2;

                int    targetvalue_att = difficulty * 2;
                int    targetvalue_def = difficulty * 4;
                Entity ent             = SpiderFactory.createSpider(type, difficulty);
                int    deviation_att   = Math.Abs(targetvalue_att - ent.Attack);
                int    deviation_def   = Math.Abs(targetvalue_def - ent.Defence);

                Assert.IsTrue(deviation_att <= MaxDeviation_ATT);
                Assert.IsTrue(deviation_def <= MaxDeviation_DEF);
            }
Example #13
0
            public void ClassValidity(SpiderTypes type, Type expected)
            {
                const int DIFF = 1;
                Entity    ent  = SpiderFactory.createSpider(type, DIFF);

                try
                {
                    Convert.ChangeType(ent, expected);
                }
                catch
                {
                    Assert.Fail();
                }
            }
        public void XpathFollow()
        {
            var services    = SpiderFactory.CreateScopeServiceProvider();
            var dataContext = new DataFlowContext(new Response
            {
                Request = new Request("http://cnblogs.com"),
                RawText = File.ReadAllText("cnblogs.html")
            }, services);
            var xpathFollow = DataParserHelper.QueryFollowRequestsByXPath(".//div[@class='pager']");

            var requests = xpathFollow.Invoke(dataContext);

            Assert.Equal(12, requests.Count);
            Assert.Contains(requests, r => r == "http://cnblogs.com/sitehome/p/2");
        }
Example #15
0
        static void Main(string[] args)
        {
            try
            {
                var spiderFactory = new SpiderFactory();
                var userHandler   = new UserHandler(spiderFactory);
                userHandler.RunWorkFlow(OnSpiderDeployed);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }
Example #16
0
        public void XpathFollow()
        {
            var service     = SpiderFactory.CreateScope();
            var dataContext = new DataFlowContext(service);

            dataContext.AddResponse(new Response
            {
                Request = new Request("http://cnblogs.com"),
                RawText = File.ReadAllText("cnblogs.html")
            });
            var xpathFollow = DataParser.XpathFollow(".//div[@class='pager']");

            var requests = xpathFollow.Invoke(dataContext);

            Assert.Equal(12, requests.Length);
            Assert.Contains(requests, r => r == "http://cnblogs.com/sitehome/p/2");
        }
		public async Task AutoIncPrimary()
		{
			using (var conn = CreateConnection())
			{
				// 如果实体的 Schema 没有配置表名,则使用类名
				await conn.ExecuteAsync(
					$"drop table if exists {Escape}test{Escape}.{Escape}createtableautoincprimay{Escape};");
				var services = SpiderFactory.CreateScopeServiceProvider();
				var storage = CreateStorage(StorageType.Insert);
				var dfc = new DataFlowContext(null, services);
				var typeName = typeof(CreateTableEntity5).FullName;
				var entity = new CreateTableEntity5();
				dfc.Add(typeName, entity.GetTableMetadata());
				var items = new ParseResult<CreateTableEntity5>
				{
					entity,
					entity
				};
				dfc.AddParseItem(typeName, items);
				await storage.HandleAsync(dfc);
				var list =
					(await conn.QueryAsync<CreateTableEntity5>(
						$"SELECT * FROM {Escape}test{Escape}.{Escape}createtableautoincprimay{Escape}"))
					.ToList();
				Assert.Equal(2, list.Count);
				entity = list.First();
				Assert.Equal("xxx", entity.Str1);
				Assert.Equal("yyy", entity.Str2);
				Assert.Equal(655, entity.Required);
				Assert.Equal(0, entity.Decimal);
				Assert.Equal(600, entity.Long);
				Assert.Equal(400, entity.Double);
				Assert.Equal(200.0F, entity.Float);
				Assert.Equal(1, entity.Id);
				Assert.Equal(2, list[1].Id);

				var primaries = (await conn.QueryAsync<PrimaryInfo>(
						$"SELECT t.CONSTRAINT_TYPE, c.COLUMN_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t, INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c WHERE t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = 'test' AND t.CONSTRAINT_TYPE = 'PRIMARY KEY' AND t.TABLE_NAME='createtableautoincprimay';")
					).ToList();
				Assert.Single(primaries);
				Assert.Equal("id", primaries[0].COLUMN_NAME);
				await conn.ExecuteAsync(
					$"drop table if exists {Escape}test{Escape}.{Escape}createtableautoincprimay{Escape};");
			}
		}
        public async Task CreateTableAutoIncPrimary()
        {
            using (var conn = CreateConnection())
            {
                // 如果实体的 Schema 没有配置表名,则使用类名
                await conn.ExecuteAsync("drop table if exists test.dbo.createtableautoincprimay;");

                var services = SpiderFactory.CreateScopeServiceProvider();
                var storage  = CreateStorage(StorageType.Insert);
                var dfc      = new DataFlowContext(null, services);
                var typeName = typeof(CreateTableEntity5).FullName;
                var entity   = new CreateTableEntity5();
                dfc.Add(typeName, entity.GetTableMetadata());
                var items = new ParseResult <CreateTableEntity5>
                {
                    entity,
                    entity
                };
                dfc.AddParseItem(typeName, items);
                await storage.HandleAsync(dfc);

                var list =
                    (await conn.QueryAsync <CreateTableEntity5>("SELECT * FROM test.dbo.createtableautoincprimay"))
                    .ToList();
                Assert.Equal(2, list.Count);
                entity = list.First();
                Assert.Equal("xxx", entity.Str1);
                Assert.Equal("yyy", entity.Str2);
                Assert.Equal(655, entity.Required);
                Assert.Equal(0, entity.Decimal);
                Assert.Equal(600, entity.Long);
                Assert.Equal(400, entity.Double);
                Assert.Equal(200.0F, entity.Float);
                Assert.Equal(1, entity.Id);
                Assert.Equal(2, list[1].Id);

                var primaries = (await conn.QueryAsync <IndexInfo>
                                     (@"USE test; EXEC sp_pkeys @table_name='createtableautoincprimay'")
                                 ).ToList();
                Assert.Single(primaries);
                Assert.Equal("id", primaries[0].COLUMN_NAME);
                Assert.Equal(1, primaries[0].KEY_SEQ);
                await conn.ExecuteAsync("drop table if exists test.dbo.createtableautoincprimay;");
            }
        }
Example #19
0
        public void MultiEntitySelector()
        {
            var service     = SpiderFactory.CreateScopeServiceProvider();
            var dataContext = new DataFlowContext(new Response
            {
                Request = new Request("http://abcd.com"),
                RawText = Html
            }, service);

            var parser = new DataParser <E>();

            parser.HandleAsync(dataContext).GetAwaiter().GetResult();

            var results = (ParseResult <E>)dataContext.GetParseItem(typeof(E).FullName);

            Assert.Equal("a", results[0].title);
            Assert.Equal("b", results[1].title);
        }
Example #20
0
        public void RunThenPauseThenContinueThenExit()
        {
            var url = Environment.GetEnvironmentVariable("TRAVIS") == "1"
                ? "https://www.google.com/"
                : "http://www.baidu.com/";

            var spider = SpiderFactory.Create <Spider>();

            spider.Id    = Guid.NewGuid().ToString("N");               // 设置任务标识
            spider.Name  = "RunAsyncAndStop";                          // 设置任务名称
            spider.Speed = 1;                                          // 设置采集速度, 表示每秒下载多少个请求, 大于 1 时越大速度越快, 小于 1 时越小越慢, 不能为0.
            spider.Depth = 3;                                          // 设置采集深度
            spider.DownloaderOptions.Type = DownloaderType.HttpClient; // 使用普通下载器, 无关 Cookie, 干净的 HttpClient

            for (int i = 0; i < 10000; i++)
            {
                spider.AddRequests(new Request(url + i)
                {
                    Encoding = "UTF-8"
                });
            }

            spider.RunAsync();
            Thread.Sleep(4000);
            spider.Pause();
            Thread.Sleep(4000);
            spider.Continue();
            Thread.Sleep(4000);
            spider.Exit();

            for (int i = 0; i < 50; ++i)
            {
                if (spider.Status == Status.Exited)
                {
                    break;
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }

            Assert.Equal(Status.Exited, spider.Status);
        }
Example #21
0
        public void MultiEntitySelector()
        {
            var service     = SpiderFactory.CreateScope();
            var dataContext = new DataFlowContext(service);

            dataContext.AddResponse(new Response
            {
                Request = new Request("http://abcd.com"),
                RawText = Html
            });

            var parser = new DataParser <E>();

            parser.HandleAsync(dataContext).GetAwaiter().GetResult();

            var results = ((List <object>)dataContext.GetItem(typeof(E).FullName)).Select(x => (E)x).ToList();

            Assert.Equal("a", results[0].title);
            Assert.Equal("b", results[1].title);
        }
Example #22
0
    void Start()
    {
        Debug.Log("start");
        SSDirector director = SSDirector.GetInstance();

        director.CurrentScenceController = this;
        spider_factory = Singleton <SpiderFactory> .Instance;
        action_manager = gameObject.AddComponent <SpiderActionManager>() as SpiderActionManager;
        Instantiate(Resources.Load <GameObject>("Prefabs/Maze"));
        player  = Instantiate(Resources.Load("Prefabs/Player"), new Vector3(0, 9, 0), Quaternion.identity) as GameObject;
        spiders = spider_factory.GetSpiders();
        for (int i = 0; i < spiders.Count; i++)
        {
            action_manager.GoSpider(spiders[i]);
        }
        main_camera.GetComponent <CameraFlow>().follow  = player;
        main_camera.GetComponent <CameraFlow>().enabled = true;
        Debug.Log("camera");
        recorder = Singleton <ScoreRecorder> .Instance;
    }
		public async Task Indexes()
		{
			using (var conn = CreateConnection())
			{
				await conn.ExecuteAsync(
					$"drop table if exists {Escape}test{Escape}.{Escape}createtableindexes{Escape};");
				var services = SpiderFactory.CreateScopeServiceProvider();
				var storage = CreateStorage(StorageType.Insert);

				var dfc = new DataFlowContext(null, services);
				var typeName = typeof(CreateTableEntity5).FullName;
				var entity = new CreateTableEntity9();
				dfc.Add(typeName, entity.GetTableMetadata());
				var items = new ParseResult<CreateTableEntity9>
				{
					entity
				};
				dfc.AddParseItem(typeName, items);
				await storage.HandleAsync(dfc);
				var indexes = (await conn.QueryAsync<IndexInfo>
						($"show index from test.createtableindexes")
					).ToList();
				Assert.Equal(6, indexes.Count);
				Assert.Contains(indexes,
					x => x.Key_name == "INDEX_STR1" && x.Non_unique == 1 && x.Column_name == "str1");
				Assert.Contains(indexes, x =>
					x.Key_name == "INDEX_STR1_STR2" && x.Non_unique == 1 && x.Column_name == "str1");
				Assert.Contains(indexes, x =>
					x.Key_name == "INDEX_STR1_STR2" && x.Non_unique == 1 && x.Column_name == "str2");
				Assert.Contains(indexes,
					x => x.Key_name == "UNIQUE_STR3" && x.Non_unique == 0 && x.Column_name == "str3");
				Assert.Contains(indexes, x =>
					x.Key_name == "UNIQUE_STR3_STR4" && x.Non_unique == 0 && x.Column_name == "str3");
				Assert.Contains(indexes, x =>
					x.Key_name == "UNIQUE_STR3_STR4" && x.Non_unique == 0 && x.Column_name == "str4");

				await conn.ExecuteAsync(
					$"drop table if exists {Escape}test{Escape}.{Escape}createtableindexes{Escape};");
			}
		}
		public async Task UseTransaction()
		{
			using (var conn = CreateConnection())
			{
				// 如果实体的 Schema 没有配置表名,则使用类名
				await conn.ExecuteAsync(
					$"drop table if exists {Escape}test{Escape}.{Escape}createtableprimay{Escape};");
				var services = SpiderFactory.CreateScopeServiceProvider();
				var storage = (RelationalDatabaseEntityStorageBase) CreateStorage(StorageType.InsertIgnoreDuplicate);
				storage.UseTransaction = true;
				var dfc = new DataFlowContext(null, services);
				var typeName = typeof(CreateTableEntity4).FullName;
				var entity = new CreateTableEntity4();
				dfc.Add(typeName, entity.GetTableMetadata());
				var items = new ParseResult<CreateTableEntity4>
				{
					entity,
					entity,
					entity
				};
				dfc.AddParseItem(typeName, items);
				await storage.HandleAsync(dfc);
				var list = (await conn.QueryAsync<CreateTableEntity4>(
						$"SELECT * FROM {Escape}test{Escape}.{Escape}createtableprimay{Escape}"))
					.ToList();
				Assert.Single(list);
				entity = list.First();
				Assert.Equal("xxx", entity.Str1);
				Assert.Equal("yyy", entity.Str2);
				Assert.Equal(655, entity.Required);
				Assert.Equal(0, entity.Decimal);
				Assert.Equal(600, entity.Long);
				Assert.Equal(400, entity.Double);
				Assert.Equal(200.0F, entity.Float);

				await conn.ExecuteAsync(
					$"drop table if exists {Escape}test{Escape}.{Escape}createtableprimay{Escape};");
			}
		}
Example #25
0
        public void MmfCloseSignal()
        {
            var url = "http://www.MmfCloseSignal.com/";

            var spider = SpiderFactory.Create <Spider>();

            spider.MmfSignal = true;
            spider.NewGuidId();
            spider.Name = "MmfCloseSignal";
            spider.DownloaderSettings.Type = DownloaderType.Empty;

            for (int i = 0; i < 10000; i++)
            {
                spider.AddRequests(new Request(url + i));
            }

            spider.RunAsync();
            Thread.Sleep(2000);
            spider.ExitBySignal().WaitForExit(15000);

            Assert.Equal(Status.Exited, spider.Status);
        }
 public HostService(SpiderFactory spiderFactory)
 {
     _spiderFactory = spiderFactory;
 }