コード例 #1
0
 /// <summary>
 /// 删除一个文章
 /// </summary>
 /// <param name="article"></param>
 /// <returns></returns>
 public bool DelArticle(Article article)
 {
     try
     {
         using (ACSDbContext db = new ACSDbContext ())
         {
             db.Articles.Attach(article);
             db.Articles.Remove(article);
             db.SaveChanges();
         }
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
コード例 #2
0
        public NewCollectForm(ref Article article)
        {
            InitializeComponent();

            articleList.Add(article);

            btn_Collect.Enabled = false;
            btn_Save.Enabled = false;
            lv_ArticleTitleList.Enabled = false;

            txt_PublishDate.Text = article.Time.ToString();
            txt_Title.Text = article.Title;
            webBrowser1.DocumentText = article.Content;

            BindArticleList();
            lv_ArticleTitleList.Items[0].Checked = true;
            lv_ArticleTitleList.Items[0].Selected = true;
        }
コード例 #3
0
        public Entities.Article GetArticle(Model.Address address)
        {
            string html = this.GetHtmlString(GetWebResponse(address.address));
            StanSoft.Article article = new StanSoft.Article();

            article = Html2Article.GetArticle(html);

            Entities.Article myArticle = new Entities.Article();
            myArticle.ID = Guid.NewGuid();
            myArticle.Time = article.PublishDate;

            // 这里要去掉采集出来的标题的制表符回车等等
            //以免在绑定到listview会看不见标题
            string clearFilter = @"[\t\n\r]";
            myArticle.Title = Regex.Replace(article.Title,clearFilter,"");
            myArticle.Title = myArticle.Title.TrimStart();
            myArticle.Title = myArticle.Title.TrimEnd();

            myArticle.Site = address.site;
            myArticle.Type = address.type;
            myArticle.Content = StanSoft.UrlUtility.FixUrl(address.address, article.ContentWithTags);

            return myArticle;
        }
コード例 #4
0
        public bool UpdateArticle(Article article)
        {
            try
            {
                using (ACSDbContext db = new ACSDbContext())
                {
                    DbEntityEntry<Article> entry = db.Entry<Article>(article);

                    entry.State = EntityState.Unchanged;
                    entry.Property("Title").IsModified = true;
                    entry.Property("Content").IsModified = true;
                    entry.Property("Time").IsModified = true;

                    db.SaveChanges();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #5
0
        /// <summary>
        /// 图片处理
        /// 根据文章信息 获取img的数目和对应的address
        /// 返回一个List<ArticlePic>
        /// </summary>
        /// <param name="article"></param>
        /// <returns></returns>
        public bool Process(Article article)
        {
            //Regex regImg = new Regex(@"<img .*?>");// 匹配img标签的正则
            //MatchCollection mc = regImg.Matches(article.Content);

            Regex regSrc = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
            MatchCollection mcSrc = regSrc.Matches(article.Content);
            //匹配img里面src

            int count = 0;

            foreach (Match item in mcSrc)
            {
                string imgName = Guid.NewGuid().ToString()+"_"+ (count++) + ".jpg";
                regSrc.Replace(item.Value, remotePath + imgName);
                try
                {
                    //WNetAddConnection2A
                    int tag = NASHelper.NetWorkConnection.Connect(localPath, remotePath, userName, passWord);
                    if ( tag == 0)
                    {
                        if (GetImage(item.Groups["imgUrl"].Value, remotePath +"\\"+ imgName))
                        {
                            NASHelper.NetWorkConnection.Disconnect(localPath);
                        }
                        NASHelper.NetWorkConnection.Disconnect(localPath);
                    }
                    else {
                        return false;
                    }

                }
                catch (Exception)
                {
                    return false;
                }
            }
            return true;
        }