예제 #1
0
        private static ImageUrl DownloadBlogImgToLocal(string blogImgUrl)
        {
            ImageUrl imageUrl = new ImageUrl();
            string   fileName = CrawlerUtility.GetFileContent(blogImgUrl, Const.BlogFileDirectory, "http://www.zimuzu.tv/");

            if (fileName == "")
            {
                return(null);
            }
            string localFilePath = Const.BlogFileDirectory + fileName;

            using (Image downloadImage = Image.FromFile(localFilePath))
            {
                if (downloadImage.Size.Width > 500)
                {
                    var image = Domain.Helper.ImgHandler.ZoomPictureProportionately(downloadImage, 500, 500 * downloadImage.Size.Height / downloadImage.Size.Width);
                    image.Save(localFilePath);
                }
            }

            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Console.WriteLine("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            imageUrl.Url         = fileName;
            imageUrl.ImageStatus = ImageStatus.Local;
            imageUrl.TimeStamp   = DateTime.Now;
            if (!string.IsNullOrEmpty(yunUrl))
            {
                imageUrl.YunUrl      = yunUrl;
                imageUrl.ImageStatus = ImageStatus.Yun;
            }
            return(imageUrl);
        }
예제 #2
0
        private static bool SaveRecomment(Blog blog, string coverImgUrl)
        {
            if (coverImgUrl == "")
            {
                return(true);
            }
            string fileName = CrawlerUtility.GetFileContent(coverImgUrl, Const.CoverFileDirectory, "http://www.zimuzu.tv/");

            if (string.IsNullOrEmpty(fileName))
            {
                return(true);
            }
            string localFilePath = Const.CoverFileDirectory + fileName;
            var    image         = Domain.Helper.ImgHandler.ZoomPicture(Image.FromFile(localFilePath), 200, 110);

            image.Save(localFilePath);
            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Console.WriteLine("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            var recomment = new Recomment()
            {
                BlogId    = blog.Id,
                CoverName = fileName,
                Title     = blog.Title,
                TimeStamp = DateTime.Now,
                Category  = SetCategoryByTitle(blog.Title)
            };

            if (!string.IsNullOrEmpty(yunUrl))
            {
                recomment.YunUrl      = yunUrl;
                recomment.ImageStatus = ImageStatus.Yun;
            }
            return(SyncUtility.SyncRecomment(recomment));
        }
예제 #3
0
        public OperationResult <ImageUrl> UploadImage(HttpPostedFileBase file, int blogId)
        {
            if (file.ContentLength > 0)
            {
                string fileName = DateTime.Now.ToString("yy/MM/dd/") + Guid.NewGuid().ToString("N") +
                                  Path.GetExtension(file.FileName);
                string diskPath = HttpContext.Current.Server.MapPath("~" + ConstValues.BlogImageDirectory + fileName);
                string diskDir  = diskPath.Substring(0, diskPath.LastIndexOf("\\", StringComparison.Ordinal));
                if (!Directory.Exists(diskDir))
                {
                    Directory.CreateDirectory(diskDir);
                }
                file.SaveAs(diskPath);
                string yunUrl   = UploadUtility.UploadLocalFile(diskPath);
                var    imageUrl = new ImageUrl()
                {
                    BlogId      = blogId,
                    Url         = fileName.Replace('/', '\\'),
                    TimeStamp   = DateTime.Now,
                    YunUrl      = yunUrl,
                    ImageStatus = string.IsNullOrEmpty(yunUrl) ? ImageStatus.Local : ImageStatus.Yun
                };

                _context.ImageUrls.Add(imageUrl);
                _context.SaveChanges();
                if (string.IsNullOrEmpty(yunUrl))
                {
                    imageUrl.Url = "http://www.withyun.com" + ConstValues.BlogImageDirectory + fileName;
                }

                return(new OperationResult <ImageUrl>(true, imageUrl));
            }
            return(new OperationResult <ImageUrl>(false, null));
        }
예제 #4
0
        private static bool SaveRecomment(Blog blog, string imageUrl, string category)
        {
            if (imageUrl == "")
            {
                return(true);
            }
            string fileName = CrawlerUtility.GetFileContent(imageUrl, Const.CoverFileDirectory, "http://www.mp4ba.com/");

            if (fileName == "")
            {
                return(true);
            }

            var recomment = new Recomment()
            {
                BlogId    = blog.Id,
                Title     = blog.Title,
                CoverName = fileName,
                TimeStamp = DateTime.Now
            };

            if (category.Contains("电影"))
            {
                recomment.Category = RecommentCategory.电影;
            }
            if (category.Contains("电视剧"))
            {
                recomment.Category = RecommentCategory.剧集;
            }
            if (category == "欧美电视剧")
            {
                recomment.Category = RecommentCategory.美剧;
            }
            if (category == "日韩电视剧")
            {
                recomment.Category = RecommentCategory.韩剧;
            }
            if (category == "综艺娱乐")
            {
                recomment.Category = RecommentCategory.综艺;
            }
            string localFilePath = Const.CoverFileDirectory + fileName;
            var    image         = Domain.Helper.ImgHandler.ZoomPicture(Image.FromFile(localFilePath), 200, 110);

            image.Save(localFilePath);
            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Console.WriteLine("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            if (!string.IsNullOrEmpty(yunUrl))
            {
                recomment.YunUrl      = yunUrl;
                recomment.ImageStatus = ImageStatus.Yun;
            }
            return(SyncUtility.SyncRecomment(recomment));
        }
예제 #5
0
        private static bool SaveRecomment(Blog blog, string imageUrl, string category)
        {
            if (imageUrl == "http://verycd.gdajie.com/img/default_cover.jpg" || imageUrl == "")
            {
                return(true);
            }
            string fileName = CrawlerUtility.GetFileContent(imageUrl, Const.CoverFileDirectory, "http://www.gdajie.com/");

            if (string.IsNullOrEmpty(fileName))
            {
                return(true);
            }
            string localFilePath = Const.CoverFileDirectory + fileName;

            try
            {
                using (var localImage = Image.FromFile(localFilePath))
                {
                    var image = ImgHandler.ZoomPicture(localImage, 200, 110);
                    image.Save(localFilePath);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "localFilePath:{0}", localFilePath);
                return(true);
            }

            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Info("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            var recomment = new Recomment()
            {
                BlogId    = blog.Id,
                CoverName = fileName,
                Title     = blog.Title,
                TimeStamp = DateTime.Now,
                Category  = SetCategory(category)
            };

            if (!string.IsNullOrEmpty(yunUrl))
            {
                recomment.YunUrl      = yunUrl;
                recomment.ImageStatus = ImageStatus.Yun;
            }
            return(SyncUtility.SyncRecomment(recomment));
        }
예제 #6
0
        public void SaveRecomment(HttpPostedFileBase file, string title, int blogId, int[] selectedCategory)
        {
            string fileName = "";
            string yunUrl   = "";

            if (file.ContentLength > 0)
            {
                fileName = DateTime.Now.ToString("yy/MM/dd/") + Guid.NewGuid().ToString("N") +
                           Path.GetExtension(file.FileName);
                string diskPath = HttpContext.Current.Server.MapPath("~" + ConstValues.CoverImageDirectory + fileName);
                var    image    = ImgHandler.ZoomPicture(Image.FromStream(file.InputStream), 200, 110);
                string diskDir  = diskPath.Substring(0, diskPath.LastIndexOf("\\", StringComparison.Ordinal));
                if (!Directory.Exists(diskDir))
                {
                    Directory.CreateDirectory(diskDir);
                }
                image.Save(diskPath);
                image.Dispose();
                yunUrl = UploadUtility.UploadLocalFile(diskPath);
            }
            foreach (int category in selectedCategory)
            {
                var recomment = new Recomment()
                {
                    BlogId      = blogId,
                    CoverName   = fileName.Replace('/', '\\'),
                    Title       = title,
                    TimeStamp   = DateTime.Now,
                    Category    = (RecommentCategory)category,
                    YunUrl      = yunUrl,
                    ImageStatus = string.IsNullOrEmpty(yunUrl) ? ImageStatus.Local : ImageStatus.Yun
                };

                _context.Recomments.Add(recomment);
            }
            _context.SaveChanges();
        }
예제 #7
0
        private static bool SaveRecomment(Blog blog, string imageUrl, string category)
        {
            if (imageUrl == "http://verycd.gdajie.com/img/default_cover.jpg" || imageUrl == "")
            {
                return(true);
            }
            string fileName = CrawlerUtility.GetFileContent(imageUrl, Const.CoverFileDirectory, "http://www.gdajie.com/");

            if (string.IsNullOrEmpty(fileName))
            {
                return(true);
            }
            string localFilePath = Const.CoverFileDirectory + fileName;
            var    image         = Domain.Helper.ImgHandler.ZoomPicture(Image.FromFile(localFilePath), 200, 110);

            image.Save(localFilePath);
            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Console.WriteLine("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            var recomment = new Recomment()
            {
                BlogId    = blog.Id,
                CoverName = fileName,
                Title     = blog.Title,
                TimeStamp = DateTime.Now,
                Category  = SetCategory(category)
            };

            if (!string.IsNullOrEmpty(yunUrl))
            {
                recomment.YunUrl      = yunUrl;
                recomment.ImageStatus = ImageStatus.Yun;
            }
            return(SyncUtility.SyncRecomment(recomment));
            //Context.Set<Recomment>().Add(recomment);
            //Context.SaveChanges();
        }
예제 #8
0
        private void UpdateServiceProcess()
        {
            while (true)
            {
                try
                {
                    var blogImageList  = ImageUrlDao.GetToUploadList();
                    int blogImageCount = blogImageList.Count;
                    MessageLog("updating blogImageCount:" + blogImageCount);
                    int successCount = 0;
                    foreach (ImageUrl image in blogImageList)
                    {
                        string localPath = Const.BlogFileDirectory + image.Url;
                        string yunUrl    = UploadUtility.UploadLocalFile(localPath);
                        if (yunUrl == "")
                        {
                            Thread.Sleep(5 * 60 * 1000);
                            continue;
                        }
                        image.YunUrl      = yunUrl;
                        image.ImageStatus = ImageStatus.Yun;
                        if (SyncUtility.SyncImageUrl(image))
                        {
                            MessageLog("sync success,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                            ImageUrlDao.DeleteRecord(image.Id);
                            successCount++;
                        }
                        else
                        {
                            MessageLog("sync fail,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                        }
                        Thread.Sleep(15 * 1000);
                    }
                    MessageLog("updated blogImageCount:" + successCount);

                    var coverImageList  = RecommentDao.GetToUploadList();
                    int coverImageCount = coverImageList.Count;
                    MessageLog("updating coverImageCount:" + coverImageCount);
                    successCount = 0;
                    foreach (Recomment image in coverImageList)
                    {
                        if (image.CoverName.Trim().StartsWith("http"))
                        {
                            image.CoverName = CrawlerUtility.GetFileContent(image.CoverName.Trim(),
                                                                            Const.CoverFileDirectory, "");
                            if (string.IsNullOrEmpty(image.CoverName))
                            {
                                continue;
                            }
                        }
                        string localPath = Const.CoverFileDirectory + image.CoverName;
                        string yunUrl    = UploadUtility.UploadLocalFile(localPath);
                        if (yunUrl == "")
                        {
                            //Thread.Sleep(5 * 60 * 1000);
                            continue;
                        }
                        image.YunUrl      = yunUrl;
                        image.ImageStatus = ImageStatus.Yun;
                        if (SyncUtility.SyncRecomment(image))
                        {
                            MessageLog("sync success,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                            RecommentDao.DeleteRecord(image.Id);
                            successCount++;
                        }
                        else
                        {
                            MessageLog("sync fail,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                        }
                        Thread.Sleep(15 * 1000);
                    }
                    MessageLog("updated blogImageCount:" + successCount);
                    if (blogImageCount == 0 && coverImageCount == 0)
                    {
                        MessageLog("record empty,sleeping 10 minutes");
                        Thread.Sleep(10 * 60 * 1000);
                    }
                }
                catch (ThreadAbortException threadAbortException)
                {
                    Logger.Error(threadAbortException);
                    break;
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    Thread.Sleep(10 * 60 * 1000);
                }
            }
        }
예제 #9
0
 private void UpdateServiceProcess()
 {
     while (true)
     {
         try
         {
             ImageUrlService imageService   = new ImageUrlService();
             var             blogImageList  = imageService.GetLocalList();
             int             blogImageCount = blogImageList.Count;
             MessageLog("updating blogImageCount:" + blogImageCount);
             int successCount = 0;
             foreach (ImageUrl image in blogImageList)
             {
                 string localPath = BlogFileDirectory + image.Url;
                 string yunUrl    = UploadUtility.UploadLocalFile(localPath);
                 if (yunUrl == "")
                 {
                     Thread.Sleep(5 * 60 * 1000);
                     continue;
                 }
                 image.YunUrl      = yunUrl;
                 image.ImageStatus = ImageStatus.Yun;
                 if (imageService.Update(image))
                 {
                     MessageLog("update success,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                     successCount++;
                 }
                 else
                 {
                     MessageLog("update fail,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                 }
                 Thread.Sleep(15 * 1000);
             }
             MessageLog("updated blogImageCount:" + successCount);
             imageService.Dispose();
             RecommentService recommentService = new RecommentService();
             var coverImageList  = recommentService.GetLocalList();
             int coverImageCount = coverImageList.Count;
             MessageLog("updating coverImageCount:" + coverImageCount);
             successCount = 0;
             foreach (Recomment image in coverImageList)
             {
                 string localPath = CoverFileDirectory + image.CoverName;
                 string yunUrl    = UploadUtility.UploadLocalFile(localPath);
                 if (yunUrl == "")
                 {
                     Thread.Sleep(5 * 60 * 1000);
                     continue;
                 }
                 image.YunUrl      = yunUrl;
                 image.ImageStatus = ImageStatus.Yun;
                 if (recommentService.Update(image))
                 {
                     MessageLog("update success,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                     successCount++;
                 }
                 else
                 {
                     MessageLog("update fail,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                 }
                 Thread.Sleep(15 * 1000);
             }
             MessageLog("updated blogImageCount:" + successCount);
             recommentService.Dispose();
             if (blogImageCount == 0 && coverImageCount == 0)
             {
                 MessageLog("record empty,sleeping 10 minutes");
                 Thread.Sleep(10 * 60 * 1000);
             }
         }
         catch (ThreadAbortException threadAbortException)
         {
             Logger.Error(threadAbortException);
             break;
         }
         catch (Exception ex)
         {
             Logger.Error(ex);
             Thread.Sleep(10 * 60 * 1000);
         }
     }
 }