Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task Execute(IJobExecutionContext context)
        {
            // 是否生成缩略图
            bool   IsCompressed = ConfigurationManager.AppSettings["IsCompressed"] == "Yes";
            string rootPath     = HostingEnvironment.MapPath("~/");

            return(Task.Factory.StartNew(async() =>
            {
                if (IsCompressed)
                {
                    // 获取没有生成缩略图的记录
                    var list = await srcOp.GetDataByFuncAsync(_ => _.CurrentStatus != (int)RowStatusEnum.Ready);
                    Parallel.ForEach(list, _ =>
                    {
                        ImageHelper.MakeThumbnail(rootPath + _.SavePathDir + _.CoverImageName,
                                                  rootPath + _.SavePathDir + "thumbnail/" + _.CoverImageName.Substring(0, _.CoverImageName.LastIndexOf(".") + 1) + "jpg",
                                                  800, 0, ThumbnailMode.W, "jpg");
                        _.SourceFiles.Split(';').ToList().ForEach(s =>
                        {
                            ImageHelper.MakeThumbnail(rootPath + _.SavePathDir + s,
                                                      rootPath + _.SavePathDir + "thumbnail/" + s.Substring(0, s.LastIndexOf(".") + 1) + "jpg",
                                                      800, 0, ThumbnailMode.W, "jpg");
                        });
                        _.CurrentStatus = 2;
                        srcOp.Update(_);
                    });
                }
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task Execute(IJobExecutionContext context)
        {
            string rootPath = HostingEnvironment.MapPath("~/");

            return(Task.Factory.StartNew(async() =>
            {
#if Prod
                var list = await srcOp.GetDataByFuncAsync(_ => _.CreatedDate < DateTime.Now.AddDays(-1));
                list.ForEach(_ =>
                {
                    if (!string.IsNullOrEmpty(_.SourceFiles))
                    {
                        _.SourceFiles.Split(';').ToList().ForEach(f =>
                        {
                            File.Delete(rootPath + _.SavePathDir + f);
                        });
                    }
                });
#endif
            }));
        }