示例#1
0
        public long Add(ArticleDetailInfo info)
        {
            var sql = @"insert into article 
                                (ThirdId,Title,Summary,Cover,CategoryId,ThirdCategoryId,CreateDate) 
                                values 
                                (@ThirdId,@Title,@Summary,@Cover,@CategoryId,@ThirdCategoryId,@CreateDate);
                                select last_insert_id(); ";

            long aid;

            using (DbCommand cmd = DbInstance.GetSqlStringCommand(sql))
            {
                SetCommandParameter(cmd, "ThirdId", DbType.Int64, info.ThirdId);
                SetCommandParameter(cmd, "Title", DbType.String, info.Title);
                SetCommandParameter(cmd, "Summary", DbType.String, info.Summary);
                SetCommandParameter(cmd, "Cover", DbType.String, info.Cover);
                SetCommandParameter(cmd, "CategoryId", DbType.Int64, info.CategoryId);
                SetCommandParameter(cmd, "ThirdCategoryId", DbType.Int64, info.ThirdCategoryId);
                SetCommandParameter(cmd, "CreateDate", DbType.DateTime, info.CreateDate);

                aid = GetLong(cmd);
            }

            AddContent(aid, info.Content);

            return(aid);
        }
示例#2
0
        public void Edit(ArticleDetailInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (string.IsNullOrWhiteSpace(info.Title))
            {
                throw new Exception("标题不能为空");
            }

            if (string.IsNullOrWhiteSpace(info.Content))
            {
                throw new Exception("内容不能为空");
            }

            var sqlTxt = @"update article 
                            set Title=@Title,
                                CategoryId=@CategoryId,
                                ThirdCategoryId=@ThirdCategoryId,
                                Cover=@Cover
                            where Id=@Id;
                          update article_content set Content=@Content where ArticleId=@Id;";

            using (DbCommand cmd = DbInstance.GetSqlStringCommand(sqlTxt))
            {
                SetCommandParameter(cmd, "Title", DbType.String, info.Title);
                SetCommandParameter(cmd, "Content", DbType.String, info.Content);
                SetCommandParameter(cmd, "Cover", DbType.String, info.Cover);
                SetCommandParameter(cmd, "CategoryId", DbType.Int64, info.CategoryId);
                SetCommandParameter(cmd, "ThirdCategoryId", DbType.Int64, info.ThirdCategoryId);
                SetCommandParameter(cmd, "Id", DbType.Int64, info.Id);

                ExecSql(cmd);
            }
        }
示例#3
0
        public static List <ArticleDetailInfo> CaptureList(AutoCaptureInfo cfg, Dictionary <long, long> existRefIds, int index)
        {
            List <ArticleDetailInfo> dataList = null;
            var existHasVal = existRefIds != null && existRefIds.GetEnumerator().MoveNext();

            if (cfg != null &&
                !string.IsNullOrWhiteSpace(cfg.ListUrl) &&
                !string.IsNullOrWhiteSpace(cfg.ListXPath) &&
                !string.IsNullOrWhiteSpace(cfg.DetailUrl) &&
                !string.IsNullOrWhiteSpace(cfg.DetailXpath))
            {
                var listUrl = cfg.ListUrl.ToLower();
                if (listUrl.Contains("{pageindex}"))
                {
                    listUrl = listUrl.Replace("{pageindex}", index.ToString());
                }

                if (listUrl.Contains("{categoryid}"))
                {
                    listUrl = listUrl.Replace("{categoryid}", cfg.ThridCategoryId.ToString());
                }

                using (WebClient client = new WebClient())
                {
                    var res = string.Empty;
                    client.Encoding = Encoding.Default;
                    try
                    {
                        res = client.DownloadString(listUrl);
                    }
                    catch (Exception ex)
                    {
                        Point.Common.Core.SystemLoger.Current.Write(string.Format("获取[{0}]数据失败:{1}", listUrl, ex.Message));
                    }

                    if (!string.IsNullOrWhiteSpace(res))
                    {
                        var doc = new HtmlDocument();
                        doc.LoadHtml(res);


                        var rootNode = doc.DocumentNode;
                        if (rootNode != null)
                        {
                            var list = rootNode.SelectNodes(cfg.ListXPath);
                            if (list != null && list.Count() > 0)
                            {
                                dataList = new List <ArticleDetailInfo>();
                                foreach (var node in list)
                                {
                                    var title = node.Attributes["title"].Value;
                                    var href  = node.Attributes["href"].Value;
                                    var refId = GetUrlParmsValue(href, "infoid");

                                    long _refId;
                                    if (Int64.TryParse(refId, out _refId))
                                    {
                                        var model = new ArticleDetailInfo()
                                        {
                                            Title           = title,
                                            ThirdId         = _refId,
                                            ThirdCategoryId = cfg.ThridCategoryId,
                                            CategoryId      = cfg.CategoryId,
                                            CreateDate      = DateTime.Now
                                        };

                                        if (existHasVal && existRefIds.Values.Contains(_refId))
                                        {
                                            model.Id = existRefIds.First(i => i.Value == _refId).Key;
                                        }

                                        //获取详情
                                        var details_url = cfg.DetailUrl.ToLower();
                                        var content     = string.Empty;
                                        var cover       = string.Empty;

                                        if (details_url.Contains("{articleid}"))
                                        {
                                            details_url = details_url.Replace("{articleid}", _refId.ToString());
                                        }

                                        model.Content = CaptureDetails(details_url, cfg.DetailXpath, cfg.LinkBaseUrl, cfg.ThridCategoryId, out cover);
                                        model.Cover   = cover;
                                        dataList.Add(model);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(dataList);
        }