コード例 #1
0
        public List <FeedItem> InsertItemsSqlLucene(RssItemCollection items, Feed feed)
        {
            var              entiti           = new TazehaContext();
            List <FeedItem>  listReturnBack   = new List <FeedItem>();
            IRepositorySaver RepositorySql    = new SqlRepository();
            IRepositorySaver RepositoryLucene = new LuceneRepositoryAsService();
            int              erroroccur       = 0;

            foreach (RssItem item in items)
            {
                if (erroroccur > 2)
                {
                    return(listReturnBack);
                }
                if (!Utility.HasFaWord(item.Title))
                {
                    continue;
                }

                FeedItem dbitem = new FeedItem();
                dbitem.Title       = HtmlRemoval.StripTagsRegex(item.Title).Replace("\t", "").Replace("\n", "").Replace("\r", "");
                dbitem.Link        = item.Link.ToString();
                dbitem.Description = HtmlRemoval.StripTagsRegex(item.Description).Replace("\t", "").Replace("\n", "").Replace("\r", "");
                //-------------------------Baray DB koochiK!!-----------------
                dbitem.Description = dbitem.Description.SubstringX(0, _appConfigBiz.MaxDescriptionLength());
                dbitem.SiteId      = feed.SiteId;
                dbitem.FeedId      = feed.Id;
                if (item.PubDate.Year > 1350 && item.PubDate < DateTime.Now.AddDays(2))
                {
                    dbitem.PubDate = item.PubDate;
                }
                else
                {
                    break;
                }
                dbitem.CreateDate = DateTime.Now;
                //dbitem.Cats = feed.Categories.Select(x => x.Id).ToList();
                dbitem.SiteTitle   = feed.Site.SiteTitle;
                dbitem.SiteUrl     = feed.Site.SiteUrl;
                dbitem.SiteId      = feed.SiteId;
                dbitem.IndexedType = dbitem.IndexedType.HasValue ? dbitem.IndexedType + 1 : 1;
                var feedItem = new FeedItem {
                    Link = dbitem.Link, Title = dbitem.Title, PubDate = dbitem.PubDate, CreateDate = DateTime.Now, FeedId = feed.Id
                };

                if (RepositorySql.AddItem(feedItem))
                {
                    RepositoryLucene.AddItem(dbitem);
                    listReturnBack.Add(dbitem);
                    Indexer.Indexer.FirstIndexing(dbitem);
                }
            }
            return(listReturnBack);
        }