Exemplo n.º 1
0
        public void Update()
        {
            var result = HttpSender.Request((new HttpRequest
            {
                Url = Env.EnterpiseServiceUrl
            }));

            if (result.StatusCode != HttpStatusCode.OK)
            {
                return;
            }

            Env.LoadConfiguration("app.service.config");

            ClearDb();

            using (MySqlConnection conn = new MySqlConnection(ConnectString))
            {
                ISpider spider = new DefaultSpider("test", new Site());

                HttpMySqlEntityPipeline insertPipeline = new HttpMySqlEntityPipeline();
                var metadata  = new EntityDefine <ProductInsert>();
                var tableName = Guid.NewGuid().ToString("N");
                metadata.TableInfo.Name = tableName;
                insertPipeline.AddEntity(metadata);
                insertPipeline.Init();

                var data1 = new ProductInsert {
                    Sku = "210", Category = "3C", Url = "http://jd.com/110", CDate = new DateTime(2016, 8, 13)
                };
                var data2 = new ProductInsert {
                    Sku = "211", Category = "3C", Url = "http://jd.com/111", CDate = new DateTime(2016, 8, 13)
                };

                insertPipeline.Process(metadata.Name, new List <dynamic> {
                    data1, data2
                }, spider);

                MySqlEntityPipeline updatePipeline = new MySqlEntityPipeline(ConnectString);
                var metadata2 = new EntityDefine <ProductUpdate>();
                metadata2.TableInfo.Name = tableName;
                updatePipeline.AddEntity(metadata2);
                updatePipeline.Init();
                var sql   = $" select * from `test`.`{tableName}_{DateTime.Now.ToString("yyyy_MM_dd")}` where Sku=210";
                var data3 = conn.Query <ProductUpdate>(sql).First();
                data3.Category = "4C";
                updatePipeline.Process(metadata2.Name, new List <dynamic> {
                    data3
                }, spider);

                var list = conn.Query <ProductInsert>($"select * from test.{tableName}_{DateTime.Now.ToString("yyyy_MM_dd")}").ToList();
                Assert.Equal(2, list.Count);
                Assert.Equal("210", list[0].Sku);
                Assert.Equal("4C", list[0].Category);

                conn.Execute($"DROP TABLE test.{tableName}_{DateTime.Now.ToString("yyyy_MM_dd")};");
            }
            Env.LoadConfiguration("app.config");
        }
Exemplo n.º 2
0
        public void Update()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            ClearDb();
            using (MySqlConnection conn = new MySqlConnection(ConnectString))
            {
                ISpider spider = new DefaultSpider("test", new Site());

                HttpMySqlEntityPipeline insertPipeline = new HttpMySqlEntityPipeline();
                var metadata  = new EntityDefine <ProductInsert>();
                var tableName = Guid.NewGuid().ToString("N");
                metadata.TableInfo.Name = tableName;
                insertPipeline.AddEntity(metadata);
                insertPipeline.Init();

                var data1 = new ProductInsert {
                    Sku = "210", Category = "3C", Url = "http://jd.com/110", CDate = new DateTime(2016, 8, 13)
                };
                var data2 = new ProductInsert {
                    Sku = "211", Category = "3C", Url = "http://jd.com/111", CDate = new DateTime(2016, 8, 13)
                };

                insertPipeline.Process(metadata.Name, new List <dynamic> {
                    data1, data2
                }, spider);

                MySqlEntityPipeline updatePipeline = new MySqlEntityPipeline(ConnectString);
                var metadata2 = new EntityDefine <ProductUpdate>();
                metadata2.TableInfo.Name = tableName;
                updatePipeline.AddEntity(metadata2);
                updatePipeline.Init();
                var sql   = $" select * from `test`.`{tableName}_{DateTime.Now.ToString("yyyy_MM_dd")}` where Sku=210";
                var data3 = conn.Query <ProductUpdate>(sql).First();
                data3.Category = "4C";
                updatePipeline.Process(metadata2.Name, new List <dynamic> {
                    data3
                }, spider);

                var list = conn.Query <ProductInsert>($"select * from test.{tableName}_{DateTime.Now.ToString("yyyy_MM_dd")}").ToList();
                Assert.Equal(2, list.Count);
                Assert.Equal("210", list[0].Sku);
                Assert.Equal("4C", list[0].Category);

                conn.Execute($"DROP TABLE test.{tableName}_{DateTime.Now.ToString("yyyy_MM_dd")};");
            }
        }
Exemplo n.º 3
0
        public void Insert()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
            Env.LoadConfiguration("app.service.config");
            ClearDb();

            using (MySqlConnection conn = new MySqlConnection(ConnectString))
            {
                ISpider spider = new DefaultSpider("test", new Site());

                HttpMySqlEntityPipeline insertPipeline = new HttpMySqlEntityPipeline();
                var metadata  = new EntityDefine <ProductInsert>();
                var tableName = Guid.NewGuid().ToString("N");
                metadata.TableInfo.Name = tableName;
                insertPipeline.AddEntity(metadata);
                insertPipeline.Init();

                var data1 = new ProductInsert {
                    Sku = "210", Category = "3C", Url = "http://jd.com/110", CDate = new DateTime(2016, 8, 13)
                };
                var data2 = new ProductInsert {
                    Sku = "211", Category = "3C", Url = "http://jd.com/111", CDate = new DateTime(2016, 8, 13)
                };
                var data3 = new ProductInsert {
                    Sku = "212", Category = null, Url = "http://jd.com/111", CDate = new DateTime(2016, 8, 13)
                };

                insertPipeline.Process(metadata.Name, new List <dynamic> {
                    data1, data2, data3
                }, spider);

                var list = conn.Query <ProductInsert>($"select * from test.`{tableName}_{DateTime.Now.ToString("yyyy_MM_dd")}`").ToList();
                Assert.Equal(3, list.Count);
                Assert.Equal("210", list[0].Sku);
                Assert.Equal("211", list[1].Sku);
                Assert.Null(list[2].Category);

                conn.Execute($"DROP TABLE test.{tableName}_{DateTime.Now.ToString("yyyy_MM_dd")};");
            }
            Env.LoadConfiguration("app.config");
        }