Exemple #1
0
        public async void HandLocalFiles(User user, IFormFile file, string saveBookPath)
        {
            var novelId = Guid.NewGuid().ToString();

            saveBookPath = Path.Combine(saveBookPath, novelId);

            var filename = file.FileName;

            if (!System.IO.Directory.Exists(saveBookPath))
            {
                System.IO.Directory.CreateDirectory(saveBookPath);
            }
            var filePath = Path.Combine(saveBookPath, filename);

            using (FileStream fs = System.IO.File.Create(filePath))
            {
                file.CopyTo(fs);
                fs.Flush();
            }

            Repository.Add(new Novel()
            {
                Id           = novelId,
                Name         = filename,
                PhysicalPath = @"books\" + novelId,
                OriginLink   = "",
            });
            _userNovelApp.AddRelationShip(user.Id, user.Name, novelId, filename);

            await Task.Run(() =>
            {
                try
                {
                    var _tmpChapterManager = AutofacExt.GetFromFac <ChapterManagerApp>();
                    var listChapter        = _tmpChapterManager.AutoMatchSubchapter(novelId);
                    if (listChapter.Count() == 0)
                    {
                        return;
                    }
                    _tmpChapterManager.AddRandChapter(novelId, listChapter);
                    var _tmpNovelManager = AutofacExt.GetFromFac <NovelManagerApp>();
                    _tmpNovelManager.UpdateState(novelId, 1);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            });
        }
Exemple #2
0
        public bool Search(User user, string url)
        {
            if (!string.IsNullOrEmpty(url))
            {
                var count = Repository.Find(x => x.OriginLink == url).Count();
                if (count > 0)
                {
                    return(false);
                }
                var objNVB = NVHelper.NVBaseObject(url);
                if (objNVB == null)
                {
                    return(false);
                }
                ThreadPool.QueueUserWorkItem(x =>
                {
                    var websiteNovelApp           = AutofacExt.GetFromFac <WebsiteNovelApp>();
                    var websiteApp                = AutofacExt.GetFromFac <WebsiteApp>();
                    var webSearchHelper           = new WebSearchHelper();
                    webSearchHelper.SpecRegStr    = objNVB.GetSpecRegex();
                    webSearchHelper.GetNovelInfo += objNVB.GetNovelInfo;
                    webSearchHelper.Search(url);

                    string guid = Guid.NewGuid().ToString();
                    websiteApp.Repository.Add(new Website {
                        Id = guid, Name = "新的搜索任务", OriginLink = url, CreatorId = user.Id
                    });
                    var websiteId = guid;

                    ThreadPool.QueueUserWorkItem(m =>
                    {
                        CheckWebsiteState(websiteId, websiteApp, ref webSearchHelper);
                    });

                    try
                    {
                        websiteApp.UpdateState(websiteId, 1);
                        while (true)
                        {
                            if (webSearchHelper.IsAllDone)
                            {
                                websiteApp.UpdateState(websiteId, 2);
                                break;
                            }
                            Thread.Sleep(100);

                            if (webSearchHelper.WebSiteBookInfoQueue.Count > 0)
                            {
                                NVNovel nVNovel = (NVNovel)webSearchHelper.WebSiteBookInfoQueue.Dequeue();
                                if (nVNovel != null)
                                {
                                    nVNovel.WebsiteId = websiteId;
                                    var websiteNovel  = Mapper.Map <WebsiteNovel>(nVNovel);
                                    websiteNovelApp.AddWebsitNovel(websiteId, websiteNovel);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        websiteApp.UpdateState(websiteId, -1);
                        //throw ex;
                    }
                }, objNVB);
                return(true);
            }
            return(false);
        }
Exemple #3
0
        public bool ReSearch(string websiteId)
        {
            var website = Repository.FindSingle(x => x.Id == websiteId);

            if (website != null)
            {
                var objNVB = NVHelper.NVBaseObject(website.OriginLink);
                if (objNVB == null)
                {
                    return(false);
                }

                ThreadPool.QueueUserWorkItem(x =>
                {
                    var websiteNovelApp           = AutofacExt.GetFromFac <WebsiteNovelApp>();
                    var websiteApp                = AutofacExt.GetFromFac <WebsiteApp>();
                    var webSearchHelper           = new WebSearchHelper();
                    webSearchHelper.SpecRegStr    = objNVB.GetSpecRegex();
                    webSearchHelper.GetNovelInfo += objNVB.GetNovelInfo;
                    webSearchHelper.Search(website.OriginLink);
                    var guid = website.Id;

                    ThreadPool.QueueUserWorkItem(m =>
                    {
                        CheckWebsiteState(websiteId, websiteApp, ref webSearchHelper);
                    });

                    try
                    {
                        websiteApp.UpdateState(guid, 1);
                        while (true)
                        {
                            if (webSearchHelper.IsAllDone)
                            {
                                websiteApp.UpdateState(guid, 2);
                                break;
                            }
                            Thread.Sleep(100);

                            if (webSearchHelper.WebSiteBookInfoQueue.Count > 0)
                            {
                                NVNovel nVNovel = (NVNovel)webSearchHelper.WebSiteBookInfoQueue.Dequeue();
                                if (nVNovel != null)
                                {
                                    nVNovel.WebsiteId = guid;
                                    var websiteNovel  = Mapper.Map <WebsiteNovel>(nVNovel);
                                    websiteNovelApp.AddWebsitNovel(guid, websiteNovel);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        websiteApp.UpdateState(guid, -1);
                        //throw ex;
                    }
                });
                return(true);
            }
            return(false);
        }