Esempio n. 1
0
 public int insert(edata d)
 {
     using (IDbConnection conn = OpenConnection())
     {
         const string query2 = @"insert into edata values(null, @type, @name, @url, @value1, @value2, @value3, @value4, @value5, @create_at)";
         return(conn.Execute(query2, d));
     }
 }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var db = new DbMapper();

            this.progressBar1.Value = 0;

            string config = File.ReadAllText(@".\config.json");
            var    json   = JsonConvert.DeserializeObject <List <Config> >(config);
            var    len    = json.Count();

            log("开始获取数据!");

            for (Int32 i = 0; i < len; i++)
            {
                var it = json[i];
                var d  = new edata();
                d.name = it.name;
                d.url  = it.url;

                AsynTask.Task(() => {
                    AsynTask.UpdateUI(() =>
                    {
                        log(d.name);
                        log(d.url);
                    });

                    var dom = new JumonyParser().LoadDocument(it.url);
                    if (!string.IsNullOrWhiteSpace(it.selector1))
                    {
                        d.value1 = dom.FindSingle(it.selector1).InnerText();
                    }
                    if (!string.IsNullOrWhiteSpace(it.selector2))
                    {
                        d.value2 = dom.FindSingle(it.selector2).InnerText();
                    }
                    if (!string.IsNullOrWhiteSpace(it.selector3))
                    {
                        d.value3 = dom.FindSingle(it.selector3).InnerText();
                    }
                    if (!string.IsNullOrWhiteSpace(it.selector4))
                    {
                        d.value4 = dom.FindSingle(it.selector4).InnerText();
                    }
                    if (!string.IsNullOrWhiteSpace(it.selector5))
                    {
                        d.value5 = dom.FindSingle(it.selector5).InnerHtml();
                    }

                    //DB
                    db.insert(d);

                    AsynTask.UpdateUI(() =>
                    {
                        this.progressBar1.Value = i / len * 100;
                    });
                })
                .OnSuccess(() =>
                {
                    log("处理完毕!");
                })
                .OnError(ex =>
                {
                    log("处理失败了!" + ex.Message);
                })
                .Start();
            }
        }