Ejemplo n.º 1
0
        public void TestCreateRule()
        {
            //RuleLiteDB.Remove(1);

            var rule = new RuleModel();

            rule.Url        = "http://www.ruijihg.com/2018/05/24/json-net-%e5%8f%8d%e5%ba%8f%e5%88%97%e5%8c%96%e6%8e%a5%e5%8f%a3%e9%9b%86%e5%90%88/";
            rule.Domain     = new Uri(rule.Url).GetDomain();
            rule.Expression = "http://www.ruijihg.com/????/??/??/*";

            var block = new ExtractBlock()
            {
                Selectors = new List <ISelector>
                {
                    new CssSelector("#main", CssTypeEnum.InnerHtml)
                },
                Metas = new ExtractMetaCollection()
            };

            block.Metas.AddMeta("time", new List <ISelector> {
                new CssSelector("time", CssTypeEnum.Text)
            });

            block.Metas.AddMeta("author", new List <ISelector> {
                new CssSelector(".author", CssTypeEnum.Text)
            });

            block.Metas.AddMeta("content", new List <ISelector> {
                new CssSelector(".entry-content", CssTypeEnum.InnerHtml)
            });

            rule.BlockExpression = JsonConvert.SerializeObject(block);

            //rule.Id = 1;
            RuleLiteDB.AddOrUpdate(rule);

            Assert.IsTrue(rule.Id > 0);
        }
Ejemplo n.º 2
0
 public void UpdateRule(RuleModel rule)
 {
     RuleLiteDB.AddOrUpdate(rule);
 }