Beispiel #1
0
        /// <summary>
        /// 生成最新50
        /// </summary>
        public void RunTo50()
        {
            //每一个分类取最新的一条记录
            var docs = Tygdb.ExecuteStoreQuery <NewDocItem>(@"
select d.ID,d.本记录GUID,d.GUID,d.书名 into #doc  from (
  select top 100 [GUID] from 书名表 where 包含有效章节 > 0 and 书名表.完本='false'  order by 最后更新时间 desc 
 ) as
 doctype
 left join 
 (
    SELECT *  from  文章表 
 )
 d
 on d.[GUID]=doctype.[GUID] 
select * from (select *,row=row_number()over(partition by [GUID] order by ID desc) from #doc)t where row=1 and t.id>0
drop table #doc ");

            //decimal[] ids = docs.Select(p => p.ID).ToArray();
            ////使用了in
            //var topDocs = Tygdb.文章表.Where(p => ids.Contains(p.ID)).OrderByDescending(p => p.ID).ToList().Where(
            //    //确保章节是有效的
            //    p => string.Join("", System.Text.RegularExpressions.Regex.Matches(p.内容, @"[\u4e00-\u9fa5\d\w123456789~!!·#¥%……—*()——+/”》“‘’,;。、?,:…《]+[\u4e00-\u9fa5123456789~!!·#¥%……—*(!)——+/”》“‘,’\r\n;。、?,:…《]", System.Text.RegularExpressions.RegexOptions.Multiline)
            //                .Cast<System.Text.RegularExpressions.Match>().Select(x => x.Value).ToArray()
            //                ).Length > 200
            //    );


            ////更新其它数据
            //foreach (var item in topDocs)
            //{
            //    CreateBookHTMLFTP createbook = new CreateBookHTMLFTP(item.书名表);
            //    createbook.Run();
            //}


            var topbook = books.Where(p => p.包含有效章节 > 0 && !p.完本).OrderByDescending(p => p.最后更新时间).Take(50);

            //生成明细项
            foreach (var book in topbook)
            {
                //开始生成最新
                using (TygModel.Entities tygdb = new TygModel.Entities())
                {
                    var itembook = tygdb.书名表.Where(b => b.GUID == book.GUID).FirstOrDefault();
                    CreateBookHTMLFTP createbook = new CreateBookHTMLFTP(itembook);
                    createbook.Run();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 开始运行数据
        /// </summary>
        public void Run(Action callBack, TygModel.书名表 book)
        {
            //数据无效直接返回
            if (book == null)
            {
                return;
            }


            //记时器
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();

            System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Factory.StartNew(new Action(delegate
            {
                using (TygModel.Entities entity = new TygModel.Entities())
                {
                    var itembook = entity.书名表.Where(b => b.GUID == book.GUID).FirstOrDefault();
                    CreateBookHTMLFTP createbook = new CreateBookHTMLFTP(itembook);
                    createbook.Run();
                }
                //线程写文件时不锁会冲突 另一个文件正在使用的异常
                lock (lockobj)
                {
                    //采集完成一个记录一个
                    System.IO.File.AppendAllLines(ProgressFileName, new string[] { book.GUID.ToString() + ((char)2) + book.书名 });
                }
            }));
            try
            {
                task.Wait();
                task.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //进度加1
            System.Threading.Interlocked.Increment(ref CurrentIndex);
            //输出当前进度
            System.Console.WriteLine(string.Format("生成完成{0},用时:{1},进度:{2}/{3}", book.书名, Math.Round(watch.ElapsedMilliseconds / 1000.0 / 60, 2), CurrentIndex, books.Count));
            watch.Stop();

            //运行下一个数据
            callBack();
        }