public bool SaveHandListStatus(SendHandListStatus status)
 {
     using (var db = new efContext())
     {
         db.SendHandListStatuss.Add(status);
         return(db.SaveChanges() > 0);
     }
 }
Exemple #2
0
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    var     html    = @"http://www.czcfang.com/house/index?sug=cm:4062";
                    HtmlWeb web     = new HtmlWeb();
                    var     htmlDoc = web.Load(html);
                    var     node    = htmlDoc.DocumentNode.SelectSingleNode("/html/body/div[5]/div[1]/div/ul/li[3]/span");

                    if (node != null)
                    {
                        int totalCount = 0;
                        if (int.TryParse(node.InnerText, out totalCount))
                        {
                            //check db if exist same value record
                            SendHandListStatus status = dbStorage.GetHandListStatusLastest();
                            if (status == null)
                            {
                                sMSService.SendByPhone("13961570305", "总套数: " + totalCount);
                                dbStorage.SaveHandListStatus(new SendHandListStatus
                                {
                                    Total = totalCount
                                });
                            }
                            else
                            {
                                if (status.Total != totalCount)
                                {
                                    sMSService.SendByPhone("13961570305", "总套数: " + totalCount);
                                    dbStorage.SaveHandListStatus(new SendHandListStatus
                                    {
                                        Total = totalCount
                                    });
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                await Task.Delay(1000 * 60 * 30);
            }
        }