예제 #1
0
        public async Task <bool> RssFetcherManager()
        {
            //TODO Repeated URL Problem gel  all url add then inset to redis this incorrect maybe first add one by one url in redis then add to list to insert mongo LN 36
            if (!IsInProccess())
            {
                try
                {
                    SetScheduleInProccess(SchedulerStat.inProccess);

                    Repository.ContentManagerRepository ContentManagerRepository = new Repository.ContentManagerRepository();
                    Repository.BaseContentRepository    BaseContentRepository    = new Repository.BaseContentRepository();
                    var SuccessList     = new List <Models.ContentManager.Rss>();
                    var BaseContentList = new List <Models.BaseContent.BaseContent>();
                    var deque           = await ContentManagerRepository.DequeRss(50);

                    foreach (var item in deque)
                    {
                        if (!string.IsNullOrWhiteSpace(item.url))
                        {
                            var res = await RssFetcher(item.url);

                            if (res != null)
                            {
                                SuccessList.Add(item);
                                foreach (var rss in res)
                                {
                                    BaseContentList.Add(new Models.BaseContent.BaseContent()
                                    {
                                        dateticks       = rss.dateticks,
                                        description     = rss.description,
                                        insertdateticks = DateTime.Now.Ticks,
                                        rssid           = item._id,
                                        title           = rss.title,
                                        url             = rss.url,
                                        userid          = item.userid,
                                        bycrawled       = false
                                    });
                                }
                            }
                        }
                    }
                    //TODO: Resolve concarrency problem insert repeated if waite for preve task
                    var addRes = await BaseContentRepository.Add(BaseContentList);

                    var changeRes = await ContentManagerRepository.ChangeLastCarawlDateRss(SuccessList);

                    // Cache Url on Is Repeated Url If not repeated ...
                    //var AddToRedisRes = await BaseContentRepository.AddRssURlInRedis(BaseContentList);

                    SetScheduleInProccess(SchedulerStat.idle);
                    return(true);
                }
                catch (Exception ex)
                {
                    SetScheduleInProccess(SchedulerStat.idle);
                    return(false);
                }
            }

            return(false);
        }